Files
YaeMikoBot/database/psql/fraction.go
2026-01-14 14:29:03 +03:00

35 lines
798 B
Go

package psql
import (
"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: db}
}
func (rep *FractionRepository) GetAllFractions() ([]*Fraction, error) {
fractions := make([]*Fraction, 0)
err := rep.db.Select(&fractions, "SELECT * FROM fractions ORDER BY id DESC;")
return fractions, err
}
func (rep *FractionRepository) GetFraction(id int32) (*Fraction, error) {
fraction := new(Fraction)
err := rep.db.Get(fraction, "SELECT * FROM fractions WHERE id = $1", id)
return fraction, err
}