database changes
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user