Documentation ¶
Index ¶
- type Condition
- type ConditionGroup
- type DeleteQuery
- type Direction
- type Field
- type InsertQuery
- type Join
- type OrderBy
- type Query
- type RawCondition
- type Repository
- func (repo Repository) Delete(ctx context.Context, query DeleteQuery) (sql.Result, error)
- func (repo Repository) DeleteFn(ctx context.Context, queryFn func(*DeleteQuery)) (sql.Result, error)
- func (repo Repository) Exec(ctx context.Context, query Query) (sql.Result, error)
- func (repo Repository) Insert(ctx context.Context, query InsertQuery) (sql.Result, error)
- func (repo Repository) InsertFn(ctx context.Context, queryFn func(*InsertQuery)) (sql.Result, error)
- func (repo Repository) Query(ctx context.Context, query SelectQuery) (*sql.Rows, error)
- func (repo Repository) QueryFn(ctx context.Context, queryFn func(*SelectQuery)) (*sql.Rows, error)
- func (repo Repository) QueryRow(ctx context.Context, query SelectQuery) (*sql.Row, error)
- func (repo Repository) QueryRowFn(ctx context.Context, queryFn func(*SelectQuery)) (*sql.Row, error)
- func (repo Repository) Update(ctx context.Context, query UpdateQuery) (sql.Result, error)
- func (repo Repository) UpdateFn(ctx context.Context, queryFn func(*UpdateQuery)) (sql.Result, error)
- type Scanner
- type SelectQuery
- type SimpleCondition
- type TypedDeleteQuery
- type TypedInsertQuery
- type TypedRepository
- func (repo TypedRepository[T]) Delete(ctx context.Context, query TypedDeleteQuery[T]) (sql.Result, error)
- func (repo TypedRepository[T]) DeleteFn(ctx context.Context, queryFn func(*TypedDeleteQuery[T])) (sql.Result, error)
- func (repo TypedRepository[T]) DeleteQuery() TypedDeleteQuery[T]
- func (repo TypedRepository[T]) Insert(ctx context.Context, query TypedInsertQuery[T]) (sql.Result, error)
- func (repo TypedRepository[T]) InsertFn(ctx context.Context, queryFn func(*TypedInsertQuery[T])) (sql.Result, error)
- func (repo TypedRepository[T]) InsertQuery() TypedInsertQuery[T]
- func (repo TypedRepository[T]) Query(ctx context.Context, query TypedSelectQuery[T]) ([]*T, error)
- func (repo TypedRepository[T]) QueryFn(ctx context.Context, queryFn func(*TypedSelectQuery[T])) ([]*T, error)
- func (repo TypedRepository[T]) QueryRow(ctx context.Context, query TypedSelectQuery[T]) (*T, error)
- func (repo TypedRepository[T]) QueryRowFn(ctx context.Context, queryFn func(*TypedSelectQuery[T])) (*T, error)
- func (repo TypedRepository[T]) ScanRow(ctx context.Context, query Query, scanner Scanner, ...) (*T, error)
- func (repo TypedRepository[T]) SelectQuery() TypedSelectQuery[T]
- func (repo TypedRepository[T]) Update(ctx context.Context, query TypedUpdateQuery[T]) (sql.Result, error)
- func (repo TypedRepository[T]) UpdateFn(ctx context.Context, queryFn func(*TypedUpdateQuery[T])) (sql.Result, error)
- func (repo TypedRepository[T]) UpdateQuery() TypedUpdateQuery[T]
- type TypedSelectQuery
- type TypedUpdateQuery
- type UpdateQuery
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Condition ¶
type Condition interface { // Build returns an SQL statement and the related args. Build() (string, []any) }
Condition is a condition that can be used in a where clause.
func Equal ¶
Equal returns a SimpleCondition that will check that the given field has the given value.
func JsonArrayContains ¶
JsonArrayContains returns a Condition that will check if the given value exists in a JSON array stored under the given field.
func NotEqual ¶
NotEqual returns a SimpleCondition that will check that the given field does not have the given value.
func NotJsonArrayContains ¶
NotJsonArrayContains returns a Condition that will check that the given value does not exist in a JSON array stored under the given field.
type ConditionGroup ¶
ConditionGroup is a Condition made up of many Conditions separated by an AND or an OR.
func (*ConditionGroup) Build ¶
func (group *ConditionGroup) Build() (string, []any)
Build returns an SQL statement and the related args. The statement is already wrapped in brackets.
type DeleteQuery ¶
func Delete ¶
func Delete() DeleteQuery
func (DeleteQuery) Build ¶
func (query DeleteQuery) Build() (string, []any)
type Direction ¶
type Direction string
const Ascending Direction = "ASC"
const Descending Direction = "DESC"
type InsertQuery ¶
func Insert ¶
func Insert() InsertQuery
func (InsertQuery) Build ¶
func (query InsertQuery) Build() (string, []any)
type RawCondition ¶
RawCondition is a Condition that can be used to make more complex comparisons.
func (*RawCondition) Build ¶
func (query *RawCondition) Build() (string, []any)
Build returns an SQL statement and the related args.
type Repository ¶
type Repository struct { DB *sql.DB Table string LogFn func(string, []any) StandardSelectFields []Field PreSelectFn func(ctx context.Context, query Query) error PreInsertFn func(ctx context.Context, query Query) error PreUpdateFn func(ctx context.Context, query Query) error PreDeleteFn func(ctx context.Context, query Query) error Tracer trace.Tracer }
func (Repository) Delete ¶
func (repo Repository) Delete(ctx context.Context, query DeleteQuery) (sql.Result, error)
func (Repository) DeleteFn ¶
func (repo Repository) DeleteFn(ctx context.Context, queryFn func(*DeleteQuery)) (sql.Result, error)
func (Repository) Insert ¶
func (repo Repository) Insert(ctx context.Context, query InsertQuery) (sql.Result, error)
func (Repository) InsertFn ¶
func (repo Repository) InsertFn(ctx context.Context, queryFn func(*InsertQuery)) (sql.Result, error)
func (Repository) Query ¶
func (repo Repository) Query(ctx context.Context, query SelectQuery) (*sql.Rows, error)
func (Repository) QueryFn ¶
func (repo Repository) QueryFn(ctx context.Context, queryFn func(*SelectQuery)) (*sql.Rows, error)
func (Repository) QueryRow ¶
func (repo Repository) QueryRow(ctx context.Context, query SelectQuery) (*sql.Row, error)
func (Repository) QueryRowFn ¶
func (repo Repository) QueryRowFn(ctx context.Context, queryFn func(*SelectQuery)) (*sql.Row, error)
func (Repository) Update ¶
func (repo Repository) Update(ctx context.Context, query UpdateQuery) (sql.Result, error)
func (Repository) UpdateFn ¶
func (repo Repository) UpdateFn(ctx context.Context, queryFn func(*UpdateQuery)) (sql.Result, error)
type SelectQuery ¶
type SelectQuery struct { Fields []Field Table string Condition Condition Join []Join OrderBy []OrderBy Limit int64 Offset int64 }
SelectQuery is a Query.
func Select ¶
func Select() SelectQuery
func (SelectQuery) Build ¶
func (query SelectQuery) Build() (string, []any)
type SimpleCondition ¶
SimpleCondition is a Condition that can be used to make a basic comparison. E.g. user_id = "123"
func (*SimpleCondition) Build ¶
func (query *SimpleCondition) Build() (string, []any)
Build returns an SQL statement and the related args.
type TypedDeleteQuery ¶
type TypedDeleteQuery[T any] struct { DeleteQuery Condition func(target *T) Condition Target *T }
func (TypedDeleteQuery[T]) Build ¶
func (query TypedDeleteQuery[T]) Build() (string, []any)
func (TypedDeleteQuery[T]) Prepare ¶
func (query TypedDeleteQuery[T]) Prepare() DeleteQuery
type TypedInsertQuery ¶
type TypedInsertQuery[T any] struct { InsertQuery Values func(target *T) map[Field]any Targets []*T }
func (TypedInsertQuery[T]) Build ¶
func (query TypedInsertQuery[T]) Build() (string, []any)
func (TypedInsertQuery[T]) Prepare ¶
func (query TypedInsertQuery[T]) Prepare() InsertQuery
type TypedRepository ¶
type TypedRepository[T any] struct { Repository StandardSelectFieldReferences func(target *T) []any StandardUpdateValues func(target *T) map[Field]any StandardUpdateCondition func(target *T) Condition StandardInsertValues func(target *T) map[Field]any StandardDeleteCondition func(target *T) Condition PreScanFn func(ctx context.Context, query Query, target *T) error PostScanFn func(ctx context.Context, query Query, target *T) error PreSelectFn func(ctx context.Context, query Query) error PreInsertFn func(ctx context.Context, query Query) error PreUpdateFn func(ctx context.Context, query Query) error PreDeleteFn func(ctx context.Context, query Query) error }
func (TypedRepository[T]) Delete ¶
func (repo TypedRepository[T]) Delete(ctx context.Context, query TypedDeleteQuery[T]) (sql.Result, error)
func (TypedRepository[T]) DeleteFn ¶
func (repo TypedRepository[T]) DeleteFn(ctx context.Context, queryFn func(*TypedDeleteQuery[T])) (sql.Result, error)
func (TypedRepository[T]) DeleteQuery ¶
func (repo TypedRepository[T]) DeleteQuery() TypedDeleteQuery[T]
func (TypedRepository[T]) Insert ¶
func (repo TypedRepository[T]) Insert(ctx context.Context, query TypedInsertQuery[T]) (sql.Result, error)
func (TypedRepository[T]) InsertFn ¶
func (repo TypedRepository[T]) InsertFn(ctx context.Context, queryFn func(*TypedInsertQuery[T])) (sql.Result, error)
func (TypedRepository[T]) InsertQuery ¶
func (repo TypedRepository[T]) InsertQuery() TypedInsertQuery[T]
func (TypedRepository[T]) Query ¶
func (repo TypedRepository[T]) Query(ctx context.Context, query TypedSelectQuery[T]) ([]*T, error)
func (TypedRepository[T]) QueryFn ¶
func (repo TypedRepository[T]) QueryFn(ctx context.Context, queryFn func(*TypedSelectQuery[T])) ([]*T, error)
func (TypedRepository[T]) QueryRow ¶
func (repo TypedRepository[T]) QueryRow(ctx context.Context, query TypedSelectQuery[T]) (*T, error)
func (TypedRepository[T]) QueryRowFn ¶
func (repo TypedRepository[T]) QueryRowFn(ctx context.Context, queryFn func(*TypedSelectQuery[T])) (*T, error)
func (TypedRepository[T]) SelectQuery ¶
func (repo TypedRepository[T]) SelectQuery() TypedSelectQuery[T]
func (TypedRepository[T]) Update ¶
func (repo TypedRepository[T]) Update(ctx context.Context, query TypedUpdateQuery[T]) (sql.Result, error)
func (TypedRepository[T]) UpdateFn ¶
func (repo TypedRepository[T]) UpdateFn(ctx context.Context, queryFn func(*TypedUpdateQuery[T])) (sql.Result, error)
func (TypedRepository[T]) UpdateQuery ¶
func (repo TypedRepository[T]) UpdateQuery() TypedUpdateQuery[T]
type TypedSelectQuery ¶
type TypedSelectQuery[T any] struct { SelectQuery FieldReferences func(target *T) []any }
func (TypedSelectQuery[T]) Build ¶
func (query TypedSelectQuery[T]) Build() (string, []any)
func (TypedSelectQuery[T]) Prepare ¶
func (query TypedSelectQuery[T]) Prepare() SelectQuery
type TypedUpdateQuery ¶
type TypedUpdateQuery[T any] struct { UpdateQuery Values func(target *T) map[Field]any Condition func(target *T) Condition Target *T }
func (TypedUpdateQuery[T]) Build ¶
func (query TypedUpdateQuery[T]) Build() (string, []any)
func (TypedUpdateQuery[T]) Prepare ¶
func (query TypedUpdateQuery[T]) Prepare() UpdateQuery