Files
YaeMikoBot/database/psql/groups.go

42 lines
1009 B
Go

package psql
import (
"ymgb/database"
"github.com/shopspring/decimal"
"github.com/vinovest/sqlx"
)
type Group struct {
ID int
Name string
IsVip bool `db:"is_vip"`
IsPremium bool `db:"is_premium"`
IsAdmin bool `db:"is_admin"`
IsTester bool `db:"is_tester"`
Multiplier decimal.Decimal
Sale decimal.Decimal
MaxMultigen int `db:"max_multigen"`
MaxWaifus int `db:"max_waifus"`
}
type GroupRepository struct {
db *sqlx.DB
}
func newGroupRepository(db *sqlx.DB) GroupRepository {
return GroupRepository{db}
}
func NewGroupRepository(db *database.Context) GroupRepository {
return newGroupRepository(db.Postgres)
}
func (rep GroupRepository) GetAll() ([]Group, error) {
groups := make([]Group, 0)
err := rep.db.Select(&groups, "SELECT * FROM groups ORDER BY id DESC;")
return groups, err
}
func (rep GroupRepository) GetById(id int) (Group, error) {
group, err := sqlx.One[Group](rep.db, "SELECT * FROM groups WHERE id = $1", id)
return group, err
}