Files
Portfolio-Engine/internal/database/currency.go
2026-03-25 17:44:04 +01:00

34 lines
738 B
Go

package database
import (
"Portifolio/internal/model"
"database/sql"
"fmt"
_ "github.com/mattn/go-sqlite3"
)
func GetCurrencyByID(db *sql.DB, ID int) (model.Currency, error) {
var c model.Currency
err := db.QueryRow(
`SELECT id, code, name, FROM currencies WHERE id = ?`,
ID,
).Scan(&c.ID, &c.Code, &c.Name)
if err == sql.ErrNoRows {
return c, fmt.Errorf("company %d not found", ID)
}
return c, nil
}
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 = ?`,
Code,
).Scan(&c.ID, &c.Code, &c.Name)
if err == sql.ErrNoRows {
return c, fmt.Errorf("company %d not found", Code)
}
return c, nil
}