Documentation
¶
Index ¶
- func Any[M any](query *bun.SelectQuery, field string, arr []M) *bun.SelectQuery
- func CursorPagination(query *bun.SelectQuery, id, limit uint64, order storage.SortOrder, ...) *bun.SelectQuery
- func In[M any](query *bun.SelectQuery, field string, arr []M) *bun.SelectQuery
- func Pagination(query *bun.SelectQuery, limit, offset uint64, order storage.SortOrder) *bun.SelectQuery
- type Init
- type Numeric
- func (b *Numeric) Add(x *Numeric) *Numeric
- func (b *Numeric) Div(x *Numeric) *Numeric
- func (b *Numeric) FromBigInt(x *big.Int) *Numeric
- func (b *Numeric) Mul(x *Numeric) *Numeric
- func (b *Numeric) Neg() *Numeric
- func (b *Numeric) Scan(value interface{}) error
- func (b *Numeric) String() string
- func (b *Numeric) Sub(x *Numeric) *Numeric
- func (b *Numeric) ToInt64() int64
- func (b *Numeric) ToUInt64() uint64
- func (b *Numeric) Value() (driver.Value, error)
- type Storage
- type Table
- func (s *Table[M]) CursorList(ctx context.Context, id, limit uint64, order storage.SortOrder, ...) ([]M, error)
- func (s *Table[M]) DB() *bun.DB
- func (s *Table[M]) GetByID(ctx context.Context, id uint64) (m M, err error)
- func (s *Table[M]) IsNoRows(err error) bool
- func (s *Table[M]) LastID(ctx context.Context) (uint64, error)
- func (s *Table[M]) List(ctx context.Context, limit, offset uint64, order storage.SortOrder) ([]M, error)
- func (s *Table[M]) Save(ctx context.Context, m M) error
- func (s *Table[M]) Update(ctx context.Context, m M) error
- type Transactable
- type Transaction
- func (t *Transaction) Add(ctx context.Context, model any) error
- func (t *Transaction) BulkSave(ctx context.Context, models []any) error
- func (t *Transaction) Close(ctx context.Context) error
- func (t *Transaction) CopyFrom(ctx context.Context, tableName string, data []storage.Copiable) error
- func (t *Transaction) Exec(ctx context.Context, query string, params ...any) (int64, error)
- func (t *Transaction) Flush(ctx context.Context) error
- func (t *Transaction) HandleError(ctx context.Context, err error) error
- func (t *Transaction) Rollback(ctx context.Context) error
- func (t *Transaction) Tx() *bun.Tx
- func (t *Transaction) Update(ctx context.Context, model any) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Any ¶
func Any[M any](query *bun.SelectQuery, field string, arr []M) *bun.SelectQuery
In - adds ANY clause to query:
WHERE field = Any (1,2,3)
If length of array equals 0 condition skips.
func CursorPagination ¶
func CursorPagination(query *bun.SelectQuery, id, limit uint64, order storage.SortOrder, cmp storage.Comparator) *bun.SelectQuery
CursorPagination - adds limit, id where clause and sort to query. Query being like this:
query.Where("id > ?", id).Limit(limit).Order("id ?", order)
func In ¶
func In[M any](query *bun.SelectQuery, field string, arr []M) *bun.SelectQuery
In - adds IN clause to query:
WHERE field IN (1,2,3)
If length of array equals 0 condition skips.
func Pagination ¶
func Pagination(query *bun.SelectQuery, limit, offset uint64, order storage.SortOrder) *bun.SelectQuery
Pagination - adds limit, offset and sort to query. Query being like this:
query.Limit(limit).Offset(offset).Order("id ?", order)
Types ¶
type Init ¶
Init - type of initialization function which called after creating connection to database. For example, can be used for indexes creation.
type Storage ¶
type Storage struct { Transactable storage.Transactable // contains filtered or unexported fields }
Storage - default storage structure containing Transactable interface and connection to database
func (*Storage) Connection ¶
Connection - returns connection structure
type Table ¶
Table - Postgres realization of Table interface
func (*Table[M]) CursorList ¶
func (s *Table[M]) CursorList(ctx context.Context, id, limit uint64, order storage.SortOrder, cmp storage.Comparator) ([]M, error)
CursorList - returns array of rows by cursor pagination
func (*Table[M]) List ¶
func (s *Table[M]) List(ctx context.Context, limit, offset uint64, order storage.SortOrder) ([]M, error)
List - returns array of rows
type Transactable ¶
type Transactable struct {
// contains filtered or unexported fields
}
Transactable - realization of Transactable interface for Postgres
func NewTransactable ¶
func NewTransactable(db *database.Bun) *Transactable
NewTransactable - creates Transactable structure
func (*Transactable) BeginTransaction ¶
func (t *Transactable) BeginTransaction(ctx context.Context) (storage.Transaction, error)
BeginTransaction - opens atomic transaction to communication with Postgres
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction -
func (*Transaction) BulkSave ¶
func (t *Transaction) BulkSave(ctx context.Context, models []any) error
BulkSave -
func (*Transaction) CopyFrom ¶
func (t *Transaction) CopyFrom(ctx context.Context, tableName string, data []storage.Copiable) error
CopyFrom -
func (*Transaction) HandleError ¶
func (t *Transaction) HandleError(ctx context.Context, err error) error
HandleError -
func (*Transaction) Tx ¶
func (t *Transaction) Tx() *bun.Tx
Tx - returns bun.Tx pointer for custom queries