Documentation
¶
Index ¶
- Variables
- func Delete() *deleteQuery
- func FromError(err error) (*e, bool)
- func Insert(fields ...string) *insertQuery
- func Join(f fromMain, condition string) fromOptions
- func JoinCsv(v []string) *string
- func LeftJoin(f fromMain, condition string) fromOptions
- func NewContextWithTransaction(ctx context.Context, connection Db) (_ context.Context, commit func() error, rollback func() error, _ error)
- func NewError(err error) error
- func NewRepository[Model any, _ ScannableModel[Model]](connection Db, opts ...repositoryOption) (*repository[Model], error)
- func NewStorage[Model any, scan ScannableModel[Model]](connection Db, from *from, opts ...repositoryOption) (*storage[Model], error)
- func Plain(query string, params ...any) *plainBuilder
- func Query(q SelectQuery, alias string) fromQuery
- func RightJoin(f fromMain, condition string) fromOptions
- func Select(fields ...string) *selectQuery
- func SplitCsv(v *string) []string
- func Table(table string) fromTable
- func Update(values map[string]any) *updateQuery
- func WithExtraMapping(mapping map[string]string) repositoryOption
- type BuildOption
- type Builder
- type CountBuilder
- type CountQuery
- type Db
- type DeleteBuilder
- type DeleteQuery
- type Driver
- type Field
- type InsertQuery
- type Json
- func (f *Json[T]) MarshalJSON() ([]byte, error)
- func (f *Json[T]) Scan(value any) error
- func (j *Json[T]) ScanText(v pgtype.Text) error
- func (j Json[T]) TextValue() (pgtype.Text, error)
- func (f *Json[T]) UnmarshalJSON(value []byte) error
- func (f *Json[T]) Unwrap() T
- func (f *Json[T]) Value() (driver.Value, error)
- type Mappable
- type Repository
- type Result
- type Returnable
- type Row
- type Rows
- type Scannable
- type ScannableModel
- type SelectQuery
- type Storage
- type Transactional
- type Tx
- type UpdateQuery
- type Value
- type Valueable
- func Between(field string, from, to any) Valueable
- func Eq(field string, value any) Valueable
- func Ge(field string, value any) Valueable
- func Gt(field string, value any) Valueable
- func ILike(field string, value any) Valueable
- func JsonEq(field string, value any) Valueable
- func JsonIn(field string, value any) Valueable
- func Le(field string, value any) Valueable
- func Like(field string, value any) Valueable
- func Lt(field string, value any) Valueable
- func Ne(field string, value any) Valueable
- type Valuer
- type View
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrCannotConnectDb = errors.New("unable to connect to a db") ErrNoTransactionInContext = errors.New("no started transaction in context") ErrCannotStartTx = errors.New("unable to start a transaction") ErrCannotCreateSavepoint = errors.New("unable to create a savepoint") ErrCannotReleaseSavepoint = errors.New("unable to release a savepoint") ErrCannotRollbackSavepoint = errors.New("unable to rollback a savepoint") ErrCannotCommitTransaction = errors.New("unable to commit a transaction") ErrCannotRollbackTransaction = errors.New("unable to rollback a transaction") ErrExprBuilderNotImplemented = errors.New("expression builder is not defined") ErrUnsupportedQueryMode = errors.New("unsupported query mode") ErrArgumentsMismatch = errors.New("number of placeholders does not match number of arguments") )
View Source
var ( ErrQueryFailed = errors.New("query failed") ErrConflict = errors.New("duplicate key value violates unique constraint") ErrNoRows = errors.New("no rows in result set") ErrBadRequest = errors.New("bad request") ErrDeadlock = errors.New("deadlock") ErrInternal = errors.New("internal error") )
View Source
var Expr = Plain
Functions ¶
func JoinCsv ¶
No elements is NULL rather than an empty string, so an absent column reads back as absent.
func NewRepository ¶
func NewRepository[Model any, _ ScannableModel[Model]](connection Db, opts ...repositoryOption) (*repository[Model], error)
func NewStorage ¶
func NewStorage[Model any, scan ScannableModel[Model]](connection Db, from *from, opts ...repositoryOption) (*storage[Model], error)
func Query ¶
func Query(q SelectQuery, alias string) fromQuery
func SplitCsv ¶
An empty string is no elements: strings.Split would answer one empty element and put a value in the model that nobody stored. A NOT NULL column defaulting to the empty string is the usual way in.
func WithExtraMapping ¶
Types ¶
type BuildOption ¶
type BuildOption func(*builderCfg) error
func WithMappings ¶
func WithMappings(mappings map[string]string) BuildOption
type Builder ¶
type Builder interface {
Build(driver Driver, opts ...BuildOption) (string, []any, error)
}
type CountBuilder ¶
type CountBuilder interface {
Builder
// contains filtered or unexported methods
}
type CountQuery ¶
type CountQuery interface {
CountBuilder
From(main fromMain, opts ...fromOptions) CountQuery
Where(query criteria.Expression) CountQuery
Returning(fields ...string) CountQuery
}
func Count ¶
func Count() CountQuery
type Db ¶
type DeleteBuilder ¶
type DeleteBuilder interface {
Builder
// contains filtered or unexported methods
}
type DeleteQuery ¶
type DeleteQuery interface {
DeleteBuilder
From(main fromTable, opts ...fromOptions) DeleteQuery
Where(query criteria.Expression) DeleteQuery
}
type InsertQuery ¶
type InsertQuery interface {
Builder
Into(table fromTable) InsertQuery
Values(values ...any) InsertQuery
From(main fromMain, opts ...fromOptions) InsertQuery
Conflict(conflict string, excluded ...string) InsertQuery
Returning(fields ...string) InsertQuery
}
type Json ¶
type Json[T any] struct { // contains filtered or unexported fields }
func (*Json[T]) MarshalJSON ¶
func (*Json[T]) UnmarshalJSON ¶
type Repository ¶
type Returnable ¶
type Returnable interface {
Returns() []string
}
type ScannableModel ¶
type ScannableModel[Model any] interface { *Model Scannable Returnable }
type SelectQuery ¶
type SelectQuery interface {
Builder
From(main fromMain, opts ...fromOptions) SelectQuery
Where(query criteria.Expression) SelectQuery
Page(page int, count int) SelectQuery
Sort(sort ...string) SelectQuery
Window(window string) SelectQuery
Returning(fields ...string) SelectQuery
Group(fields ...string) SelectQuery
}
type Transactional ¶
type Tx ¶
type UpdateQuery ¶
type UpdateQuery interface {
Builder
Table(table fromTable) UpdateQuery
From(opts ...fromOptions) UpdateQuery
Where(query criteria.Expression) UpdateQuery
Returning(fields ...string) UpdateQuery
}
type View ¶
type View[Model any] interface { Repository() Repository[Model] Get(ctx context.Context, expr criteria.Expression) (*Model, error) Find(ctx context.Context, expr criteria.Expression) ([]*Model, error) Count(ctx context.Context, expr criteria.Expression) (int, error) }
Source Files
¶
Click to show internal directories.
Click to hide internal directories.