database changes

This commit is contained in:
2026-02-12 15:09:06 +03:00
parent c5448b14f6
commit 022cf4ba06
18 changed files with 202 additions and 223 deletions

View File

@@ -1,8 +1,6 @@
package psql
import (
"kurumibot/database"
"git.nix13.pw/scuroneko/laniakea"
"github.com/shopspring/decimal"
"github.com/vinovest/sqlx"
@@ -21,18 +19,21 @@ type WorkRepository struct {
db *sqlx.DB
}
func NewWorkRepository(db *laniakea.DatabaseContext) *WorkRepository {
return &WorkRepository{db: db.PostgresSQL}
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) {
func (rep WorkRepository) GetById(id int) (Work, error) {
work := Work{}
err := database.PostgresDatabase.Get(&work, "SELECT * FROM works WHERE id = $1;", id)
err := rep.db.Get(&work, "SELECT * FROM works WHERE id = $1;", id)
return work, err
}
func (rep *WorkRepository) GetAll() ([]Work, error) {
func (rep WorkRepository) GetAll() ([]Work, error) {
works := make([]Work, 0)
err := database.PostgresDatabase.Select(&works, "SELECT * FROM works;")
err := rep.db.Select(&works, "SELECT * FROM works;")
return works, err
}