Documentation
¶
Overview ¶
Package pg contains implementations of hohin interfaces for PostgreSQL. It uses the pgx driver.
Index ¶
- func NewSQL(strs ...string) *sqldb.SQL
- type Conf
- type DB
- type Repo
- func (r *Repo[T]) Add(ctx context.Context, d hohin.DB, entity T) error
- func (r *Repo[T]) AddMany(ctx context.Context, d hohin.DB, entities []T) error
- func (r *Repo[T]) Clear(ctx context.Context, d hohin.DB) error
- func (r Repo[T]) Count(ctx context.Context, d hohin.DB, f hohin.Filter) (uint64, error)
- func (r *Repo[T]) CountAll(ctx context.Context, d hohin.DB) (uint64, error)
- func (r *Repo[T]) Delete(ctx context.Context, d hohin.DB, f hohin.Filter) error
- func (r *Repo[T]) Exists(ctx context.Context, d hohin.DB, f hohin.Filter) (bool, error)
- func (r *Repo[T]) Get(ctx context.Context, d hohin.DB, f hohin.Filter) (T, error)
- func (r *Repo[T]) GetFirst(ctx context.Context, d hohin.DB, q hohin.Query) (T, error)
- func (r *Repo[T]) GetForUpdate(ctx context.Context, d hohin.DB, f hohin.Filter) (T, error)
- func (r *Repo[T]) GetMany(ctx context.Context, d hohin.DB, q hohin.Query) ([]T, error)
- func (r *Repo[T]) Simple() hohin.SimpleRepo[T]
- func (r *Repo[T]) Update(ctx context.Context, d hohin.DB, f hohin.Filter, entity T) error
- type Scanner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Conf ¶
type Conf[T any] struct { Table string // name of a database table Mapping map[string]string // mapping of entity fields to table columns Query string // SQL query to select records from the database // function that transforms an entity to a map where keys are // column names of a database table and values are data for a row in that table Dump func(T) (map[string]any, error) // function that loads a result of an SQL query to an entity Load func(Scanner) (T, error) // function that builds and returns a sequence of SQL queries to execute after a call of [Repo.Add] AfterAdd func(T) []*sqldb.SQL // function that builds and returns a sequence of SQL queries to execute after a call of [Repo.Update] AfterUpdate func(T) []*sqldb.SQL }
Conf contains configuration of a Repo.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB implements hohin.DB for PostgreSQL.
func (*DB) Transaction ¶
type Repo ¶
type Repo[T any] struct { // contains filtered or unexported fields }
Implementation of hohin.Repo for PostgreSQL.
func (*Repo[T]) GetForUpdate ¶
func (*Repo[T]) Simple ¶
func (r *Repo[T]) Simple() hohin.SimpleRepo[T]
Click to show internal directories.
Click to hide internal directories.