Files
YaeMikoBot/database/psql/fraction.go

40 lines
905 B
Go

package psql
import (
"ymgb/database"
"github.com/shopspring/decimal"
"github.com/vinovest/sqlx"
)
type Fraction struct {
ID int32
Name string
OwnerID int `db:"owner_id"`
Owner *User
Money decimal.Decimal
Exp int
Level int
}
type FractionRepository struct {
db *sqlx.DB
}
func newFractionRepository(db *sqlx.DB) FractionRepository {
return FractionRepository{db}
}
func NewFractionRepository(db *database.Context) FractionRepository {
return newFractionRepository(db.Postgres)
}
func (rep FractionRepository) GetAll() ([]Fraction, error) {
fractions := make([]Fraction, 0)
err := rep.db.Select(&fractions, "SELECT * FROM fractions ORDER BY id DESC;")
return fractions, err
}
func (rep FractionRepository) GetById(id int32) (Fraction, error) {
fraction := Fraction{}
err := rep.db.Get(&fraction, "SELECT * FROM fractions WHERE id = $1", id)
return fraction, err
}