all database switched to repository model. some other fixes and features

This commit is contained in:
2026-01-22 20:58:46 +03:00
parent 804d683f9e
commit 331f6854b6
14 changed files with 283 additions and 187 deletions

View File

@@ -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