35 lines
785 B
Go
35 lines
785 B
Go
package psql
|
|
|
|
import (
|
|
"github.com/shopspring/decimal"
|
|
"github.com/vinovest/sqlx"
|
|
)
|
|
|
|
type Fraction struct {
|
|
ID int32
|
|
Name string
|
|
OwnerID int `db:"owner_id"`
|
|
Owner *User
|
|
Money decimal.Decimal
|
|
Exp int
|
|
Level int
|
|
}
|
|
type FractionRepository struct {
|
|
db *sqlx.DB
|
|
}
|
|
|
|
func NewFractionRepository(db *sqlx.DB) *FractionRepository {
|
|
return &FractionRepository{db: db}
|
|
}
|
|
|
|
func (rep *FractionRepository) GetAll() ([]*Fraction, error) {
|
|
fractions := make([]*Fraction, 0)
|
|
err := rep.db.Select(&fractions, "SELECT * FROM fractions ORDER BY id DESC;")
|
|
return fractions, err
|
|
}
|
|
func (rep *FractionRepository) GetById(id int32) (*Fraction, error) {
|
|
fraction := new(Fraction)
|
|
err := rep.db.Get(fraction, "SELECT * FROM fractions WHERE id = $1", id)
|
|
return fraction, err
|
|
}
|