40 lines
940 B
Go
40 lines
940 B
Go
package psql
|
|
|
|
import (
|
|
"git.nix13.pw/scuroneko/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 *sqlx.DB) WorkRepository {
|
|
return WorkRepository{db}
|
|
}
|
|
func NewWorkRepository(db *laniakea.DatabaseContext) WorkRepository {
|
|
return newWorkRepository(db.PostgresSQL)
|
|
}
|
|
|
|
func (rep WorkRepository) GetById(id int) (Work, error) {
|
|
work := Work{}
|
|
err := rep.db.Get(&work, "SELECT * FROM works WHERE id = $1;", id)
|
|
return work, err
|
|
}
|
|
|
|
func (rep WorkRepository) GetAll() ([]Work, error) {
|
|
works := make([]Work, 0)
|
|
err := rep.db.Select(&works, "SELECT * FROM works;")
|
|
return works, err
|
|
}
|