database

package
v0.0.0-...-341372b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	Prepare(query string) (*sql.Stmt, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
}

DB is an interface for DB and Tx of database/sql

type MasterRepository

type MasterRepository struct {
	// contains filtered or unexported fields
}

MasterRepository is a database repository for master data.

func NewMasterRepository

func NewMasterRepository(transaction *Transaction) *MasterRepository

NewMasterRepository returns a new MasterRepository.

func (*MasterRepository) FindCategoryByID

func (repo *MasterRepository) FindCategoryByID(ctx context.Context, id string) (*domain.Category, error)

FindCategoryByID finds the category by id.

func (*MasterRepository) FindCategoryByNameAndLevel

func (repo *MasterRepository) FindCategoryByNameAndLevel(ctx context.Context, name string, level domain.CategoryLevel) (*domain.Category, error)

FindCategoryByNameAndLevel finds the category by name and level.

func (*MasterRepository) FindOrCreateCategory

func (repo *MasterRepository) FindOrCreateCategory(ctx context.Context, name string, level domain.CategoryLevel, parentID string) (*domain.Category, error)

FindOrCreateCategory finds or creates a category.

func (*MasterRepository) FindOrCreateSource

func (repo *MasterRepository) FindOrCreateSource(ctx context.Context, name string) (*domain.Source, error)

FindOrCreateSource finds or creates a source.

func (*MasterRepository) FindSourceByName

func (repo *MasterRepository) FindSourceByName(ctx context.Context, name string) (*domain.Source, error)

FindSourceByName finds the source by name.

type MoneyForwardRepository

type MoneyForwardRepository struct {
	// contains filtered or unexported fields
}

MoneyForwardRepository is a database repository for money forward data.

func NewMoneyForwardRepository

func NewMoneyForwardRepository(transaction *Transaction) *MoneyForwardRepository

NewMoneyForwardRepository returns a new MoneyForwardRepository.

func (*MoneyForwardRepository) CreateOrUpdateRecord

func (repo *MoneyForwardRepository) CreateOrUpdateRecord(ctx context.Context, record *domain.MoneyForwardRecord) error

CreateOrUpdateRecord creates or updates a money forward record.

func (*MoneyForwardRepository) FindRecord

FindRecord finds the record by id.

type StatsRepository

type StatsRepository struct {
	// contains filtered or unexported fields
}

StatsRepository is a database repository for statistics.

func NewStatsRepository

func NewStatsRepository(transaction *Transaction) *StatsRepository

NewStatsRepository returns a new StatsRepository.

func (*StatsRepository) FindExpensesByMonthAndCategoryInYear

func (repo *StatsRepository) FindExpensesByMonthAndCategoryInYear(ctx context.Context, year int) ([]*domain.AmountByYearMonthCategory, error)

FindExpensesByMonthAndCategoryInYear finds expenses group by month and category for given year.

func (*StatsRepository) FindExpensesByMonthInYear

func (repo *StatsRepository) FindExpensesByMonthInYear(ctx context.Context, year int) ([]*domain.AmountByYearMonth, error)

FindExpensesByMonthInYear finds expenses group by month for given year.

type Transaction

type Transaction struct {
	// contains filtered or unexported fields
}

Transaction manages *sql.DB and current *sql.Tx

func NewTransaction

func NewTransaction(db *sql.DB) *Transaction

NewTransaction returns a new transaction.

func (*Transaction) Begin

func (tx *Transaction) Begin(ctx context.Context) error

Begin starts a transaction.

func (*Transaction) Commit

func (tx *Transaction) Commit(ctx context.Context) error

Commit commits a transaction.

func (*Transaction) Rollback

func (tx *Transaction) Rollback(ctx context.Context) error

Rollback rollbacks a transaction.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL