changes to model

This commit is contained in:
samantha42
2026-03-26 08:39:42 +01:00
parent ff7b41e2a8
commit 3f878c1dc0
15 changed files with 119 additions and 195 deletions

View File

@@ -20,14 +20,22 @@ func GetCurrencyByID(db *sql.DB, ID int) (model.Currency, error) {
return c, nil
}
/*
CREATE TABLE IF NOT EXISTS currencies (
id INTEGER PRIMARY KEY AUTOINCREMENT,
code TEXT NOT NULL UNIQUE,
name TEXT NOT NULL
);
*/
func GetCurrencyByCode(db *sql.DB, Code string) (model.Currency, error) {
var c model.Currency
err := db.QueryRow(
`SELECT id, code, name, FROM currencies WHERE code = ?`,
`SELECT id, code, name FROM currencies WHERE code = ?`,
Code,
).Scan(&c.ID, &c.Code, &c.Name)
if err == sql.ErrNoRows {
return c, fmt.Errorf("company %d not found", Code)
return c, fmt.Errorf("company %s not found", Code)
}
return c, nil
}