ai work
This commit is contained in:
@@ -1,24 +1,34 @@
|
||||
package psql
|
||||
|
||||
import (
|
||||
"kurumibot/database"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/vinovest/sqlx"
|
||||
)
|
||||
|
||||
type Group struct {
|
||||
ID int
|
||||
Name string
|
||||
IsAdmin bool
|
||||
IsVip bool
|
||||
IsTester bool
|
||||
Multiplier decimal.Decimal
|
||||
Sale decimal.Decimal
|
||||
MaxWaifus int
|
||||
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 GetGroupById(id int) (*Group, error) {
|
||||
group := new(Group)
|
||||
tx := database.PostgresDatabase.First(group, "id = ?", id)
|
||||
return group, tx.Error
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user