all database switched to repository model. some other fixes and features
This commit is contained in:
@@ -2,8 +2,10 @@ package psql
|
||||
|
||||
import (
|
||||
"kurumibot/database"
|
||||
"kurumibot/laniakea"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/vinovest/sqlx"
|
||||
)
|
||||
|
||||
type Work struct {
|
||||
@@ -15,13 +17,21 @@ type Work struct {
|
||||
MaxExp int `db:"max_exp"`
|
||||
}
|
||||
|
||||
func GetWorkById(id int) (Work, error) {
|
||||
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 GetAllWorks() ([]Work, error) {
|
||||
func (rep *WorkRepository) GetAll() ([]Work, error) {
|
||||
works := make([]Work, 0)
|
||||
err := database.PostgresDatabase.Select(&works, "SELECT * FROM works;")
|
||||
return works, err
|
||||
|
||||
Reference in New Issue
Block a user