Files
YaeMikoBot/database/psql/works.go

39 lines
911 B
Go

package psql
import (
"kurumibot/database"
"kurumibot/laniakea"
"github.com/shopspring/decimal"
"github.com/vinovest/sqlx"
)
type Work struct {
ID int
Name string
RequiredLevel int `db:"required_level"`
MoneyIncome decimal.Decimal `db:"money_income"`
MinExp int `db:"min_exp"`
MaxExp int `db:"max_exp"`
}
type WorkRepository struct {
db *sqlx.DB
}
func NewWorkRepository(db *laniakea.DatabaseContext) *WorkRepository {
return &WorkRepository{db: db.PostgresSQL}
}
func (rep *WorkRepository) GetById(id int) (Work, error) {
work := Work{}
err := database.PostgresDatabase.Get(&work, "SELECT * FROM works WHERE id = $1;", id)
return work, err
}
func (rep *WorkRepository) GetAll() ([]Work, error) {
works := make([]Work, 0)
err := database.PostgresDatabase.Select(&works, "SELECT * FROM works;")
return works, err
}