db

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddAkunBalanceParams

type AddAkunBalanceParams struct {
	Amount int64 `json:"amount"`
	ID     int64 `json:"id"`
}

type Akun

type Akun struct {
	ID        int64     `json:"id"`
	Owner     string    `json:"owner"`
	Balance   int64     `json:"balance"`
	Currency  string    `json:"currency"`
	CreatedAt time.Time `json:"created_at"`
}

type CreateAuthorParams

type CreateAuthorParams struct {
	Owner    string `json:"owner"`
	Balance  int64  `json:"balance"`
	Currency string `json:"currency"`
}

type CreateEntryParams

type CreateEntryParams struct {
	AkunID int64 `json:"akun_id"`
	Amount int64 `json:"amount"`
}

type CreateTransfersParams

type CreateTransfersParams struct {
	FromAkun int64 `json:"from_akun"`
	ToAkun   int64 `json:"to_akun"`
	Amount   int64 `json:"amount"`
}

type DBTX

type DBTX interface {
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

type Entry

type Entry struct {
	ID int64 `json:"id"`
	// can be negative or positive
	AkunID    int64     `json:"akun_id"`
	Amount    int64     `json:"amount"`
	CreatedAt time.Time `json:"created_at"`
}

type ListAuthorsParams

type ListAuthorsParams struct {
	Limit  int32 `json:"limit"`
	Offset int32 `json:"offset"`
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) AddAkunBalance

func (q *Queries) AddAkunBalance(ctx context.Context, arg AddAkunBalanceParams) (Akun, error)

func (*Queries) CreateAuthor

func (q *Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Akun, error)

func (*Queries) CreateEntry

func (q *Queries) CreateEntry(ctx context.Context, arg CreateEntryParams) (Entry, error)

func (*Queries) CreateTransfers

func (q *Queries) CreateTransfers(ctx context.Context, arg CreateTransfersParams) (Transfer, error)

func (*Queries) DeleteAkun

func (q *Queries) DeleteAkun(ctx context.Context, id int64) error

func (*Queries) GetAkunForUpdate

func (q *Queries) GetAkunForUpdate(ctx context.Context, id int64) (Akun, error)

func (*Queries) GetAuthor

func (q *Queries) GetAuthor(ctx context.Context, id int64) (Akun, error)

func (*Queries) GetEntry

func (q *Queries) GetEntry(ctx context.Context, id int64) (Entry, error)

func (*Queries) GetTransfer

func (q *Queries) GetTransfer(ctx context.Context, id int64) (Transfer, error)

func (*Queries) ListAuthors

func (q *Queries) ListAuthors(ctx context.Context, arg ListAuthorsParams) ([]Akun, error)

func (*Queries) UpdateAkun

func (q *Queries) UpdateAkun(ctx context.Context, arg UpdateAkunParams) (Akun, error)

func (*Queries) WithTx

func (q *Queries) WithTx(tx *sql.Tx) *Queries

type Store

type Store struct {
	*Queries
	// contains filtered or unexported fields
}

Store provides all functions to execute db queries and transactions

func NewStore

func NewStore(db *sql.DB) *Store

NewStore returns a new Store

func (*Store) TransferTx

func (store *Store) TransferTx(ctx context.Context, arg TransferTxParams) (TransferTxResult, error)

TransferTx performs a money transfer from one akun to the other It creates a transfer record, add akun entries, and update akun, balance within a single database transaksi

type Transfer

type Transfer struct {
	ID       int64 `json:"id"`
	FromAkun int64 `json:"from_akun"`
	ToAkun   int64 `json:"to_akun"`
	// must be positive
	Amount    int64     `json:"amount"`
	CreatedAt time.Time `json:"created_at"`
}

type TransferTxParams

type TransferTxParams struct {
	FromAkun int64 `json:"from_akun"`
	ToAkun   int64 `json:"to_akun"`
	Amount   int64 `json:"amount"`
}

TransferTxParams contains the input parameters of the transfer transaction

type TransferTxResult

type TransferTxResult struct {
	Transfer  Transfer `json:"transfer"`
	FromAkun  Akun     `json:"from_akun"`
	ToAkun    Akun     `json:"To_akun"`
	FromEntry Entry    `json:"from_entry"`
	ToEntry   Entry    `json:"to_entry"`
}

TransferTxResult is the result of the transfer transaction

type UpdateAkunParams

type UpdateAkunParams struct {
	ID      int64 `json:"id"`
	Balance int64 `json:"balance"`
}

Jump to

Keyboard shortcuts

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