database changes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package psql
|
||||
|
||||
import (
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/vinovest/sqlx"
|
||||
)
|
||||
@@ -21,15 +22,19 @@ type GroupRepository struct {
|
||||
db *sqlx.DB
|
||||
}
|
||||
|
||||
func NewGroupRepository(db *sqlx.DB) *GroupRepository {
|
||||
return &GroupRepository{db: db}
|
||||
func newGroupRepository(db *sqlx.DB) GroupRepository {
|
||||
return GroupRepository{db}
|
||||
}
|
||||
func (rep *GroupRepository) GetAll() ([]*Group, error) {
|
||||
groups := make([]*Group, 0)
|
||||
func NewGroupRepository(db *laniakea.DatabaseContext) GroupRepository {
|
||||
return newGroupRepository(db.PostgresSQL)
|
||||
}
|
||||
|
||||
func (rep GroupRepository) GetAll() ([]Group, error) {
|
||||
groups := make([]Group, 0)
|
||||
err := rep.db.Select(&groups, "SELECT * FROM groups ORDER BY id DESC;")
|
||||
return groups, err
|
||||
}
|
||||
func (rep *GroupRepository) GetById(id int) (*Group, error) {
|
||||
func (rep GroupRepository) GetById(id int) (Group, error) {
|
||||
group, err := sqlx.One[Group](rep.db, "SELECT * FROM groups WHERE id = $1", id)
|
||||
return &group, err
|
||||
return group, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user