35 lines
860 B
Go
35 lines
860 B
Go
package psql
|
|
|
|
import (
|
|
"github.com/shopspring/decimal"
|
|
"github.com/vinovest/sqlx"
|
|
)
|
|
|
|
type Group struct {
|
|
ID int
|
|
Name string
|
|
IsAdmin bool `db:"is_admin"`
|
|
IsVip bool `db:"is_vip"`
|
|
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: db}
|
|
}
|
|
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
|
|
}
|