Files
YaeMikoBot/database/psql/fraction.go
2026-02-12 15:09:06 +03:00

39 lines
933 B
Go

package psql
import (
"git.nix13.pw/scuroneko/laniakea"
"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 *laniakea.DatabaseContext) FractionRepository {
return newFractionRepository(db.PostgresSQL)
}
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
}