Documentation ¶
Index ¶
- Constants
- Variables
- func Save[T Modeler](db DB, m *T) error
- func SetLogger(f func(a ...any))
- func UseDeletedAt(enabled bool)
- type DB
- type DBWrap
- type JoinConf
- type JoinType
- type Model
- type ModelConfig
- type Modeler
- type Q
- func (q *Q[T]) Find(db DB, id ...uuid.UUID) (*T, error)
- func (q *Q[T]) First(db DB) (*T, error)
- func (q *Q[T]) Get(db DB) ([]T, error)
- func (q *Q[T]) GroupBy(field string) *Q[T]
- func (q *Q[T]) Having(column, op string, value any) *Q[T]
- func (q *Q[T]) HavingF(f func(q *Q[T]) *Q[T]) *Q[T]
- func (q *Q[T]) Join(f func(t T) *JoinConf) *Q[T]
- func (q *Q[T]) MustFind(db DB, id ...uuid.UUID) *T
- func (q *Q[T]) MustFirst(db DB) *T
- func (q *Q[T]) MustGet(db DB) []T
- func (q *Q[T]) OrHaving(column, op string, value any) *Q[T]
- func (q *Q[T]) OrHavingF(f func(q *Q[T]) *Q[T]) *Q[T]
- func (q *Q[T]) OrWhere(column, op string, value any) *Q[T]
- func (q *Q[T]) OrWhereF(f func(q *Q[T]) *Q[T]) *Q[T]
- func (q *Q[T]) OrderBy(column string, asc bool) *Q[T]
- func (q *Q[T]) Select(selects []string, selectScan func(scan func(...any))) *Q[T]
- func (q *Q[T]) Skip(number int) *Q[T]
- func (q *Q[T]) Take(number int) *Q[T]
- func (q *Q[T]) Where(column, op string, value any) *Q[T]
- func (q *Q[T]) WhereF(f func(q *Q[T]) *Q[T]) *Q[T]
- func (q *Q[T]) With(f func(m T, r []T) error) *Q[T]
- func (q *Q[T]) WithDeleted() *Q[T]
- type Raw
- type Relation
- func (r *Relation[F, T]) Execute(db DB, result []F) error
- func (r *Relation[F, T]) Find(db DB, id ...uuid.UUID) (*T, error)
- func (r *Relation[F, T]) First(db DB) (*T, error)
- func (r *Relation[F, T]) Get(db DB) ([]T, error)
- func (r *Relation[F, T]) Join(joinType JoinType) *JoinConf
- func (r *Relation[F, T]) MustFind(db DB, id ...uuid.UUID) *T
- func (r *Relation[F, T]) MustFirst(db DB) *T
- func (r *Relation[F, T]) MustGet(db DB) []T
- func (r *Relation[F, T]) OrWhere(column, op string, value any) *Relation[F, T]
- func (r *Relation[F, T]) OrWhereF(f func(q *Q[T]) *Q[T]) *Relation[F, T]
- func (r *Relation[F, T]) OrderBy(column string, asc bool) *Relation[F, T]
- func (r *Relation[F, T]) Skip(number int) *Relation[F, T]
- func (r *Relation[F, T]) Take(number int) *Relation[F, T]
- func (r *Relation[F, T]) Unload() *Relation[F, T]
- func (r *Relation[F, T]) Where(column, op string, value any) *Relation[F, T]
- func (r *Relation[F, T]) WhereF(f func(q *Q[T]) *Q[T]) *Relation[F, T]
- func (r *Relation[F, T]) With(f func(m T, r []T) error) *Relation[F, T]
- func (r *Relation[F, T]) WithDeleted() *Relation[F, T]
- type RelationData
- type Rows
- type RowsWrap
- type SqlDB
Constants ¶
const ( INNER JoinType = "INNER" LEFT = "LEFT" RIGHT = "RIGHT" FULL = "FULL" )
Variables ¶
var (
ResourceNotFoundError = errors.New("resource not found")
)
Functions ¶
func SetLogger ¶
func SetLogger(f func(a ...any))
SetLogger will set a logger function for debugging all queries.
func UseDeletedAt ¶
func UseDeletedAt(enabled bool)
UseDeletedAt can disable or enable the usage of deleted_at in query generations.
Types ¶
type DB ¶
type DB interface { Query(query string, args ...any) (Rows, error) Exec(query string, args ...any) (any, error) }
DB is based on `sql.DB`, but generalized with an implementation independent version of `Rows`.
type ModelConfig ¶
type Q ¶
type Q[T Modeler] struct { // contains filtered or unexported fields }
func (*Q[T]) Find ¶
Find will return the one element in the query result. This will be successful IFF there was one result. The variadic parameter `id` is used to make it optional. If present, only the first element is used.
func (*Q[T]) Join ¶
Join adds a join on the query. Can be used with `join` a `Relation` to automate the condition.
func (*Q[T]) WithDeleted ¶
WithDeleted will ignore the deleted timestamp.
type Relation ¶
type Relation[F, T Modeler] struct { // contains filtered or unexported fields }
Relation is the configuration for a relationship between two objects. F is `from` and T is `to`, so the relation is defined as seen from ´F´.
func BelongsTo ¶
func BelongsTo[F, T Modeler](model F, refFieldName, fieldName string, relationDataFunc func(f *F) *RelationData[T]) *Relation[F, T]
BelongsTo is a relationship where the object in question (F) has a reference to the other object (T) Example: | F | | T | |------| |----| | ID | | | | T_ID | --> | ID |
func HasMany ¶
func HasMany[F, T Modeler](model F, refFieldName, fieldName string, relationDataFunc func(f *F) *RelationData[T]) *Relation[F, T]
HasMany is a relationship where there are MULTIPLE other objects (T) that points to this one (F). Example: | F | | T | |------| |------| | | | ID | | ID | <-- | F_ID |
func HasOne ¶
func HasOne[F, T Modeler](model F, refFieldName, fieldName string, relationDataFunc func(f *F) *RelationData[T]) *Relation[F, T]
HasOne is a relationship where there are ONE other objects (T) that points to this one (F). Example: | F | | T | |------| |------| | | | ID | | ID | <-- | F_ID |
func (*Relation[F, T]) WithDeleted ¶
type RelationData ¶
type RelationData[T Modeler] struct { // contains filtered or unexported fields }