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,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
}