Documentation
¶
Overview ¶
Package pg provides a PostgreSQL implementation for DB
Index ¶
- type Config
- type DB
- func (db DB) AddIncome(ctx context.Context, args common.AddIncomeArgs) (id uint, err error)
- func (db DB) AddMonthlyPayment(ctx context.Context, args common.AddMonthlyPaymentArgs) (id uint, err error)
- func (db DB) AddSpend(ctx context.Context, args common.AddSpendArgs) (id uint, err error)
- func (db DB) AddSpendType(ctx context.Context, args common.AddSpendTypeArgs) (id uint, err error)
- func (db *DB) DropDB() error
- func (db DB) EditIncome(ctx context.Context, args common.EditIncomeArgs) error
- func (db DB) EditMonthlyPayment(ctx context.Context, args common.EditMonthlyPaymentArgs) error
- func (db DB) EditSpend(ctx context.Context, args common.EditSpendArgs) error
- func (db DB) EditSpendType(ctx context.Context, args common.EditSpendTypeArgs) error
- func (db DB) GetDay(ctx context.Context, id uint) (common.Day, error)
- func (db DB) GetDayIDByDate(ctx context.Context, year int, month int, day int) (id uint, err error)
- func (db DB) GetMonth(ctx context.Context, id uint) (common.Month, error)
- func (db DB) GetMonthID(ctx context.Context, year, month int) (id uint, err error)
- func (db DB) GetMonths(ctx context.Context, years ...int) ([]common.Month, error)
- func (db DB) GetSpendType(ctx context.Context, id uint) (common.SpendType, error)
- func (db DB) GetSpendTypes(ctx context.Context) ([]common.SpendType, error)
- func (db *DB) Prepare() error
- func (db DB) RemoveIncome(ctx context.Context, id uint) error
- func (db DB) RemoveMonthlyPayment(ctx context.Context, id uint) error
- func (db DB) RemoveSpend(ctx context.Context, id uint) error
- func (db DB) RemoveSpendType(ctx context.Context, id uint) error
- func (db DB) SearchSpends(ctx context.Context, args common.SearchSpendsArgs) ([]common.Spend, error)
- func (db *DB) Shutdown() error
- type Day
- type Income
- type Month
- type MonthlyPayment
- type Spend
- type SpendType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func NewDB ¶
func NewDB(config Config, log logrus.FieldLogger) (*DB, error)
NewDB creates a new connection to the db and pings it
func (DB) AddMonthlyPayment ¶
func (db DB) AddMonthlyPayment(ctx context.Context, args common.AddMonthlyPaymentArgs) (id uint, err error)
AddMonthlyPayment adds new Monthly Payment
func (DB) AddSpendType ¶
AddSpendType adds new Spend Type
func (DB) EditIncome ¶
EditIncome edits income with passed id, nil args are ignored
func (DB) EditMonthlyPayment ¶
EditMonthlyPayment modifies existing Monthly Payment
func (DB) EditSpendType ¶
EditSpendType modifies existing Spend Type
func (DB) GetDayIDByDate ¶
func (DB) GetMonthID ¶
func (DB) GetMonths ¶
GetMonths returns months of passed years. Months doesn't contains relations (Incomes, Days and etc.)
func (DB) GetSpendType ¶
GetSpendType returns Spend Type with passed id
func (DB) GetSpendTypes ¶
GetSpendTypes returns all Spend Types
func (*DB) Prepare ¶
Prepare prepares the database:
- create tables
- init tables (add days for current month if needed)
- run some subproccess
func (DB) RemoveIncome ¶
RemoveIncome removes income with passed id
func (DB) RemoveMonthlyPayment ¶
RemoveMonthlyPayment removes Monthly Payment with passed id
func (DB) RemoveSpend ¶
RemoveSpend removes Spend with passed id
func (DB) RemoveSpendType ¶
RemoveSpendType removes Spend Type with passed id
func (DB) SearchSpends ¶ added in v0.2.0
type Day ¶ added in v0.2.0
type Day struct { ID uint `pg:"id,pk"` // MonthID is a foreign key to 'months' table MonthID uint `pg:"month_id"` Day int `pg:"day"` // Saldo is a DailyBudget - Cost of all Spends multiplied by 100 (can be negative) Saldo money.Money `pg:"saldo,use_zero"` Spends []Spend `pg:"rel:has-many,join_fk:day_id"` // contains filtered or unexported fields }
Day represents day entity in PostgreSQL db
type Income ¶ added in v0.2.0
type Income struct { ID uint `pg:"id,pk"` // MonthID is a foreign key to 'months' table MonthID uint `pg:"month_id"` Title string `pg:"title"` Notes string `pg:"notes"` Income money.Money `pg:"income"` // contains filtered or unexported fields }
Income represents income entity in PostgreSQL db
type Month ¶ added in v0.2.0
type Month struct { ID uint `pg:"id,pk"` Year int `pg:"year"` Month time.Month `pg:"month"` Incomes []Income `pg:"rel:has-many,join_fk:month_id"` MonthlyPayments []MonthlyPayment `pg:"rel:has-many,join_fk:month_id"` // DailyBudget is a (TotalIncome - Cost of Monthly Payments) / Number of Days DailyBudget money.Money `pg:"daily_budget,use_zero"` Days []Day `pg:"rel:has-many,join_fk:month_id"` TotalIncome money.Money `pg:"total_income,use_zero"` // TotalSpend is a cost of all Monthly Payments and Spends TotalSpend money.Money `pg:"total_spend,use_zero"` // Result is TotalIncome - TotalSpend Result money.Money `pg:"result,use_zero"` // contains filtered or unexported fields }
Month represents month entity in PostgreSQL db
type MonthlyPayment ¶ added in v0.2.0
type MonthlyPayment struct { ID uint `pg:"id,pk"` // MonthID is a foreign key to 'months' table MonthID uint `pg:"month_id"` Title string `pg:"title"` TypeID uint `pg:"type_id"` Type *SpendType `pg:"rel:has-one,fk:type_id"` Notes string `pg:"notes"` Cost money.Money `pg:"cost"` // contains filtered or unexported fields }
MonthlyPayment represents monthly payment entity in PostgreSQL db
func (MonthlyPayment) ToCommon ¶ added in v0.2.0
func (mp MonthlyPayment) ToCommon(year int, month time.Month) common.MonthlyPayment
ToCommon converts MonthlyPayment to common MonthlyPayment structure from "github.com/ShoshinNikita/budget-manager/internal/db" package
type Spend ¶ added in v0.2.0
type Spend struct { // DayID is a foreign key to 'days' table DayID uint `pg:"day_id"` ID uint `pg:"id,pk"` Title string `pg:"title"` TypeID uint `pg:"type_id"` Type *SpendType `pg:"rel:has-one,fk:type_id"` Notes string `pg:"notes"` Cost money.Money `pg:"cost,use_zero"` // contains filtered or unexported fields }
Spend represents spend entity in PostgreSQL db
type SpendType ¶ added in v0.2.0
type SpendType struct { ID uint `pg:"id,pk"` Name string `pg:"name"` ParentID uint `pg:"parent_id"` // contains filtered or unexported fields }
SpendType represents spend type entity in PostgreSQL db