Documentation ¶
Overview ¶
Package rel contains all rel primary APIs, such as Repository.
Index ¶
- Constants
- Variables
- func DefaultLogger(ctx context.Context, op string, message string) func(err error)
- func Nullable(dest interface{}) interface{}
- type Adapter
- type AlterTable
- type AssocMutation
- type Association
- func (a Association) Autoload() bool
- func (a Association) Autosave() bool
- func (a Association) Collection() (*Collection, bool)
- func (a Association) Document() (*Document, bool)
- func (a Association) ForeignField() string
- func (a Association) ForeignValue() interface{}
- func (a Association) IsZero() bool
- func (a Association) ReferenceField() string
- func (a Association) ReferenceValue() interface{}
- func (a Association) Through() string
- func (a Association) Type() AssociationType
- type AssociationType
- type Cascade
- type ChangeOp
- type Changeset
- type Collection
- func (c Collection) Add() *Document
- func (c Collection) Get(index int) *Document
- func (c Collection) Len() int
- func (c Collection) PrimaryField() string
- func (c Collection) PrimaryFields() []string
- func (c Collection) PrimaryValue() interface{}
- func (c Collection) PrimaryValues() []interface{}
- func (c Collection) ReflectValue() reflect.Value
- func (c Collection) Reset()
- func (c Collection) Slice(i, j int) *Collection
- func (c Collection) Swap(i, j int)
- func (c *Collection) Table() string
- func (c Collection) Truncate(i, j int)
- type Column
- type ColumnOption
- type ColumnType
- type ConstraintError
- type ConstraintType
- type Cursor
- type Do
- type Document
- func (d *Document) Add() *Document
- func (d Document) Association(name string) Association
- func (d Document) BelongsTo() []string
- func (d Document) Fields() []string
- func (d Document) Flag(flag DocumentFlag) bool
- func (d *Document) Get(index int) *Document
- func (d Document) HasMany() []string
- func (d Document) HasOne() []string
- func (d Document) Index() map[string]int
- func (d *Document) Len() int
- func (d Document) Persisted() bool
- func (d Document) Preload() []string
- func (d Document) PrimaryField() string
- func (d Document) PrimaryFields() []string
- func (d Document) PrimaryValue() interface{}
- func (d Document) PrimaryValues() []interface{}
- func (d Document) ReflectValue() reflect.Value
- func (d Document) Reset()
- func (d Document) Scanners(fields []string) []interface{}
- func (d Document) SetValue(field string, value interface{}) bool
- func (d Document) Table() string
- func (d Document) Type(field string) (reflect.Type, bool)
- func (d Document) Value(field string) (interface{}, bool)
- type DocumentFlag
- type ErrorFunc
- type FilterOp
- type FilterQuery
- func And(inner ...FilterQuery) FilterQuery
- func Eq(field string, value interface{}) FilterQuery
- func FilterFragment(expr string, values ...interface{}) FilterQuery
- func Gt(field string, value interface{}) FilterQuery
- func Gte(field string, value interface{}) FilterQuery
- func In(field string, values ...interface{}) FilterQuery
- func InInt(field string, values []int) FilterQuery
- func InString(field string, values []string) FilterQuery
- func InUint(field string, values []uint) FilterQuery
- func Like(field string, pattern string) FilterQuery
- func Lt(field string, value interface{}) FilterQuery
- func Lte(field string, value interface{}) FilterQuery
- func Ne(field string, value interface{}) FilterQuery
- func Nil(field string) FilterQuery
- func Nin(field string, values ...interface{}) FilterQuery
- func NinInt(field string, values []int) FilterQuery
- func NinString(field string, values []string) FilterQuery
- func NinUint(field string, values []uint) FilterQuery
- func Not(inner ...FilterQuery) FilterQuery
- func NotLike(field string, pattern string) FilterQuery
- func NotNil(field string) FilterQuery
- func Or(inner ...FilterQuery) FilterQuery
- func (fq FilterQuery) And(filters ...FilterQuery) FilterQuery
- func (fq FilterQuery) AndEq(field string, value interface{}) FilterQuery
- func (fq FilterQuery) AndFragment(expr string, values ...interface{}) FilterQuery
- func (fq FilterQuery) AndGt(field string, value interface{}) FilterQuery
- func (fq FilterQuery) AndGte(field string, value interface{}) FilterQuery
- func (fq FilterQuery) AndIn(field string, values ...interface{}) FilterQuery
- func (fq FilterQuery) AndLike(field string, pattern string) FilterQuery
- func (fq FilterQuery) AndLt(field string, value interface{}) FilterQuery
- func (fq FilterQuery) AndLte(field string, value interface{}) FilterQuery
- func (fq FilterQuery) AndNe(field string, value interface{}) FilterQuery
- func (fq FilterQuery) AndNil(field string) FilterQuery
- func (fq FilterQuery) AndNin(field string, values ...interface{}) FilterQuery
- func (fq FilterQuery) AndNotLike(field string, pattern string) FilterQuery
- func (fq FilterQuery) AndNotNil(field string) FilterQuery
- func (fq FilterQuery) Build(query *Query)
- func (fq FilterQuery) None() bool
- func (fq FilterQuery) Or(filter ...FilterQuery) FilterQuery
- func (fq FilterQuery) OrEq(field string, value interface{}) FilterQuery
- func (fq FilterQuery) OrFragment(expr string, values ...interface{}) FilterQuery
- func (fq FilterQuery) OrGt(field string, value interface{}) FilterQuery
- func (fq FilterQuery) OrGte(field string, value interface{}) FilterQuery
- func (fq FilterQuery) OrIn(field string, values ...interface{}) FilterQuery
- func (fq FilterQuery) OrLike(field string, pattern string) FilterQuery
- func (fq FilterQuery) OrLt(field string, value interface{}) FilterQuery
- func (fq FilterQuery) OrLte(field string, value interface{}) FilterQuery
- func (fq FilterQuery) OrNe(field string, value interface{}) FilterQuery
- func (fq FilterQuery) OrNil(field string) FilterQuery
- func (fq FilterQuery) OrNin(field string, values ...interface{}) FilterQuery
- func (fq FilterQuery) OrNotLike(field string, pattern string) FilterQuery
- func (fq FilterQuery) OrNotNil(field string) FilterQuery
- type ForeignKeyReference
- type GroupQuery
- type Index
- type IndexOption
- type Instrumenter
- type Iterator
- type IteratorOption
- type JoinQuery
- func NewFullJoin(table string) JoinQuery
- func NewFullJoinOn(table string, from string, to string) JoinQuery
- func NewInnerJoin(table string) JoinQuery
- func NewInnerJoinOn(table string, from string, to string) JoinQuery
- func NewJoin(table string) JoinQuery
- func NewJoinFragment(expr string, args ...interface{}) JoinQuery
- func NewJoinOn(table string, from string, to string) JoinQuery
- func NewJoinWith(mode string, table string, from string, to string) JoinQuery
- func NewLeftJoin(table string) JoinQuery
- func NewLeftJoinOn(table string, from string, to string) JoinQuery
- func NewRightJoin(table string) JoinQuery
- func NewRightJoinOn(table string, from string, to string) JoinQuery
- type Key
- type KeyOption
- type KeyType
- type Limit
- type Lock
- type Map
- type Migration
- type Mutate
- type Mutation
- type Mutator
- type Name
- type NotFoundError
- type Offset
- type OnDelete
- type OnUpdate
- type Optional
- type Options
- type Precision
- type Preload
- type Querier
- type Query
- func Build(table string, queriers ...Querier) Query
- func From(table string) Query
- func Join(table string) Query
- func JoinOn(table string, from string, to string) Query
- func JoinWith(mode string, table string, from string, to string) Query
- func Joinf(expr string, args ...interface{}) Query
- func Select(fields ...string) Query
- func Where(filters ...FilterQuery) Query
- func (q Query) Build(query *Query)
- func (q Query) Cascade(c bool) Query
- func (q Query) Distinct() Query
- func (q Query) From(table string) Query
- func (q Query) Group(fields ...string) Query
- func (q Query) Having(filters ...FilterQuery) Query
- func (q Query) Havingf(expr string, args ...interface{}) Query
- func (q Query) Join(table string) Query
- func (q Query) JoinOn(table string, from string, to string) Query
- func (q Query) JoinWith(mode string, table string, from string, to string) Query
- func (q Query) Joinf(expr string, args ...interface{}) Query
- func (q Query) Limit(limit int) Query
- func (q Query) Lock(lock string) Query
- func (q Query) Offset(offset int) Query
- func (q Query) OrHaving(filters ...FilterQuery) Query
- func (q Query) OrHavingf(expr string, args ...interface{}) Query
- func (q Query) OrWhere(filters ...FilterQuery) Query
- func (q Query) OrWheref(expr string, args ...interface{}) Query
- func (q Query) Preload(field string) Query
- func (q Query) Reload() Query
- func (q Query) Select(fields ...string) Query
- func (q Query) Sort(fields ...string) Query
- func (q Query) SortAsc(fields ...string) Query
- func (q Query) SortDesc(fields ...string) Query
- func (q Query) Unscoped() Query
- func (q Query) Where(filters ...FilterQuery) Query
- func (q Query) Wheref(expr string, args ...interface{}) Query
- type Raw
- type Reload
- type Repository
- type Required
- type SQLQuery
- type Scale
- type Schema
- func (s *Schema) AddColumn(table string, name string, typ ColumnType, options ...ColumnOption)
- func (s *Schema) AlterTable(name string, fn func(t *AlterTable), options ...TableOption)
- func (s *Schema) CreateIndex(table string, name string, column []string, options ...IndexOption)
- func (s *Schema) CreateTable(name string, fn func(t *Table), options ...TableOption)
- func (s *Schema) CreateTableIfNotExists(name string, fn func(t *Table), options ...TableOption)
- func (s *Schema) CreateUniqueIndex(table string, name string, column []string, options ...IndexOption)
- func (s *Schema) Do(fn Do)
- func (s *Schema) DropColumn(table string, name string, options ...ColumnOption)
- func (s *Schema) DropIndex(table string, name string, options ...IndexOption)
- func (s *Schema) DropTable(name string, options ...TableOption)
- func (s *Schema) DropTableIfExists(name string, options ...TableOption)
- func (s *Schema) Exec(raw Raw)
- func (s *Schema) RenameColumn(table string, name string, newName string, options ...ColumnOption)
- func (s *Schema) RenameTable(name string, newName string, options ...TableOption)
- func (s Schema) String() string
- type SchemaOp
- type SelectQuery
- type SortQuery
- type Structset
- type Table
- func (t *Table) BigInt(name string, options ...ColumnOption)
- func (t *Table) Bool(name string, options ...ColumnOption)
- func (t *Table) Column(name string, typ ColumnType, options ...ColumnOption)
- func (t *Table) Date(name string, options ...ColumnOption)
- func (t *Table) DateTime(name string, options ...ColumnOption)
- func (t *Table) Decimal(name string, options ...ColumnOption)
- func (t *Table) Float(name string, options ...ColumnOption)
- func (t *Table) ForeignKey(column string, refTable string, refColumn string, options ...KeyOption)
- func (t *Table) Fragment(fragment string)
- func (t *Table) ID(name string, options ...ColumnOption)
- func (t *Table) Int(name string, options ...ColumnOption)
- func (t *Table) PrimaryKey(column string, options ...KeyOption)
- func (t *Table) PrimaryKeys(columns []string, options ...KeyOption)
- func (t *Table) SmallInt(name string, options ...ColumnOption)
- func (t *Table) String(name string, options ...ColumnOption)
- func (t *Table) Text(name string, options ...ColumnOption)
- func (t *Table) Time(name string, options ...ColumnOption)
- func (t *Table) Timestamp(name string, options ...ColumnOption)
- func (t *Table) Unique(columns []string, options ...KeyOption)
- type TableDefinition
- type TableOption
- type Unique
- type Unscoped
- type Unsigned
Constants ¶
const ( // BelongsTo association. BelongsTo = iota // HasOne association. HasOne // HasMany association. HasMany )
Variables ¶
var ( // ErrNotFound returned when records not found. ErrNotFound = NotFoundError{} // ErrCheckConstraint is an auxiliary variable for error handling. // This is only to be used when checking error with errors.Is(err, ErrCheckConstraint). ErrCheckConstraint = ConstraintError{Type: CheckConstraint} // ErrNotNullConstraint is an auxiliary variable for error handling. // This is only to be used when checking error with errors.Is(err, ErrNotNullConstraint). ErrNotNullConstraint = ConstraintError{Type: NotNullConstraint} // ErrUniqueConstraint is an auxiliary variable for error handling. // This is only to be used when checking error with errors.Is(err, ErrUniqueConstraint). ErrUniqueConstraint = ConstraintError{Type: UniqueConstraint} // ErrPrimaryKeyConstraint is an auxiliary variable for error handling. // This is only to be used when checking error with errors.Is(err, ErrPrimaryKeyConstraint). ErrPrimaryKeyConstraint = ConstraintError{Type: PrimaryKeyConstraint} // ErrForeignKeyConstraint is an auxiliary variable for error handling. // This is only to be used when checking error with errors.Is(err, ErrForeignKeyConstraint). ErrForeignKeyConstraint = ConstraintError{Type: ForeignKeyConstraint} )
var Setf = SetFragment
Setf is an alias for SetFragment
Functions ¶
func DefaultLogger ¶
DefaultLogger instrumentation to log queries and rel operation.
Types ¶
type Adapter ¶
type Adapter interface { Instrumentation(instrumenter Instrumenter) Ping(ctx context.Context) error Aggregate(ctx context.Context, query Query, mode string, field string) (int, error) Query(ctx context.Context, query Query) (Cursor, error) Insert(ctx context.Context, query Query, primaryField string, mutates map[string]Mutate) (interface{}, error) InsertAll(ctx context.Context, query Query, primaryField string, fields []string, bulkMutates []map[string]Mutate) ([]interface{}, error) Update(ctx context.Context, query Query, mutates map[string]Mutate) (int, error) Delete(ctx context.Context, query Query) (int, error) Begin(ctx context.Context) (Adapter, error) Commit(ctx context.Context) error Rollback(ctx context.Context) error Apply(ctx context.Context, migration Migration) error }
Adapter interface
type AlterTable ¶
type AlterTable struct {
Table
}
AlterTable Migrator.
func (*AlterTable) DropColumn ¶
func (at *AlterTable) DropColumn(name string, options ...ColumnOption)
DropColumn from this table.
func (*AlterTable) RenameColumn ¶
func (at *AlterTable) RenameColumn(name string, newName string, options ...ColumnOption)
RenameColumn to a new name.
type AssocMutation ¶
type AssocMutation struct { Mutations []Mutation DeletedIDs []interface{} // This is array of single id, and doesn't support composite primary key. }
AssocMutation represents mutation for association.
type Association ¶
type Association struct {
// contains filtered or unexported fields
}
Association provides abstraction to work with association of document or collection.
func (Association) Autoload ¶ added in v0.10.0
func (a Association) Autoload() bool
Autoload assoc setting when parent is loaded.
func (Association) Autosave ¶ added in v0.9.0
func (a Association) Autosave() bool
Autosave setting when parent is created/updated/deleted.
func (Association) Collection ¶
func (a Association) Collection() (*Collection, bool)
Collection returns association target as collection. If association is zero, second return value will be false.
func (Association) Document ¶
func (a Association) Document() (*Document, bool)
Document returns association target as document. If association is zero, second return value will be false.
func (Association) ForeignField ¶
func (a Association) ForeignField() string
ForeignField of the association.
func (Association) ForeignValue ¶
func (a Association) ForeignValue() interface{}
ForeignValue of the association. It'll panic if association type is has many.
func (Association) IsZero ¶
func (a Association) IsZero() bool
IsZero returns true if association is not loaded.
func (Association) ReferenceField ¶
func (a Association) ReferenceField() string
ReferenceField of the association.
func (Association) ReferenceValue ¶
func (a Association) ReferenceValue() interface{}
ReferenceValue of the association.
func (Association) Through ¶ added in v0.9.0
func (a Association) Through() string
Through return intermediary association.
type AssociationType ¶
type AssociationType uint8
AssociationType defines the type of association in database.
type Changeset ¶
type Changeset struct {
// contains filtered or unexported fields
}
Changeset mutator for structs. This allows REL to efficiently to perform update operation only on updated fields and association. The catch is, enabling changeset will duplicates the original struct values which consumes more memory.
func NewChangeset ¶
func NewChangeset(record interface{}) Changeset
NewChangeset returns new changeset mutator for given record.
func (Changeset) FieldChanged ¶
FieldChanged returns true if field exists and it's already changed. returns false otherwise.
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection provides an abstraction over reflect to easily works with slice for database purpose.
func NewCollection ¶
func NewCollection(records interface{}, readonly ...bool) *Collection
NewCollection used to create abstraction to work with slice. COllection can be created using interface or reflect.Value.
func (Collection) Get ¶
func (c Collection) Get(index int) *Document
Get an element from the underlying slice as a document.
func (Collection) PrimaryField ¶
func (c Collection) PrimaryField() string
PrimaryField column name of this document. panic if document uses composite key.
func (Collection) PrimaryFields ¶
func (c Collection) PrimaryFields() []string
PrimaryFields column name of this collection.
func (Collection) PrimaryValue ¶
func (c Collection) PrimaryValue() interface{}
PrimaryValue of this document. panic if document uses composite key.
func (Collection) PrimaryValues ¶
func (c Collection) PrimaryValues() []interface{}
PrimaryValues of collection. Returned value will be interface of slice interface.
func (Collection) ReflectValue ¶
func (c Collection) ReflectValue() reflect.Value
ReflectValue of referenced document.
func (Collection) Slice ¶
func (c Collection) Slice(i, j int) *Collection
Slice returns a new collection that is a slice of the original collection.s
type Column ¶
type Column struct { Op SchemaOp Name string Type ColumnType Rename string Unique bool Required bool Unsigned bool Limit int Precision int Scale int Default interface{} Options string }
Column definition.
type ColumnOption ¶
type ColumnOption interface {
// contains filtered or unexported methods
}
ColumnOption interface. Available options are: Nil, Unsigned, Limit, Precision, Scale, Default, Comment, Options.
func Default ¶
func Default(def interface{}) ColumnOption
Default allows to set a default value on the column.).
type ColumnType ¶
type ColumnType string
ColumnType definition.
const ( // ID ColumnType. ID ColumnType = "ID" // Bool ColumnType. Bool ColumnType = "BOOL" // SmallInt ColumnType. SmallInt ColumnType = "SMALLINT" // Int ColumnType. Int ColumnType = "INT" // BigInt ColumnType. BigInt ColumnType = "BIGINT" // Float ColumnType. Float ColumnType = "FLOAT" // Decimal ColumnType. Decimal ColumnType = "DECIMAL" // String ColumnType. String ColumnType = "STRING" // Text ColumnType. Text ColumnType = "TEXT" // Date ColumnType. Date ColumnType = "DATE" // DateTime ColumnType. DateTime ColumnType = "DATETIME" // Time ColumnType. Time ColumnType = "TIME" // Timestamp ColumnType. Timestamp ColumnType = "TIMESTAMP" )
type ConstraintError ¶
type ConstraintError struct { Key string Type ConstraintType Err error }
ConstraintError returned whenever constraint error encountered.
func (ConstraintError) Is ¶
func (ce ConstraintError) Is(target error) bool
Is returns true when target error have the same type and key if defined.
func (ConstraintError) Unwrap ¶
func (ce ConstraintError) Unwrap() error
Unwrap internal error returned by database driver.
type ConstraintType ¶
type ConstraintType int8
ConstraintType defines the type of constraint error.
const ( // CheckConstraint error type. CheckConstraint ConstraintType = iota // NotNullConstraint error type.1 NotNullConstraint // UniqueConstraint error type.1 UniqueConstraint // PrimaryKeyConstraint error type.1 PrimaryKeyConstraint // ForeignKeyConstraint error type.1 ForeignKeyConstraint )
func (ConstraintType) String ¶
func (ct ConstraintType) String() string
String representation of the constraint type.
type Cursor ¶
type Cursor interface { Close() error Fields() ([]string, error) Next() bool Scan(...interface{}) error NopScanner() interface{} // TODO: conflict with manual scanners interface }
Cursor is interface to work with database result (used by adapter).
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document provides an abstraction over reflect to easily works with struct for database purpose.
func NewDocument ¶
NewDocument used to create abstraction to work with struct. Document can be created using interface or reflect.Value.
func (Document) Association ¶
func (d Document) Association(name string) Association
Association of this document with given name.
func (Document) Flag ¶
func (d Document) Flag(flag DocumentFlag) bool
Flag returns true if struct contains specified flag.
func (*Document) Get ¶
Get always returns this document, this is a noop for compatibility with collection.
func (*Document) Len ¶
Len always returns 1 for document, this is a noop for compatibility with collection.
func (Document) PrimaryField ¶
PrimaryField column name of this document. panic if document uses composite key.
func (Document) PrimaryFields ¶
PrimaryFields column name of this document.
func (Document) PrimaryValue ¶
func (d Document) PrimaryValue() interface{}
PrimaryValue of this document. panic if document uses composite key.
func (Document) PrimaryValues ¶
func (d Document) PrimaryValues() []interface{}
PrimaryValues of this document.
func (Document) ReflectValue ¶
ReflectValue of referenced document.
func (Document) Reset ¶
func (d Document) Reset()
Reset this document, this is a noop for compatibility with collection.
func (Document) SetValue ¶
SetValue of the field, it returns false if field does not exist, or it's not assignable.
type DocumentFlag ¶
type DocumentFlag int8
DocumentFlag stores information about document as a flag.
const ( // Invalid flag. Invalid DocumentFlag = 1 << iota // HasCreatedAt flag. HasCreatedAt // HasUpdatedAt flag. HasUpdatedAt // HasDeletedAt flag. HasDeletedAt )
func (DocumentFlag) Is ¶
func (df DocumentFlag) Is(flag DocumentFlag) bool
Is returns true if it's defined.
type FilterOp ¶
type FilterOp int
FilterOp defines enumeration of all supported filter types.
const ( // FilterAndOp is filter type for and operator. FilterAndOp FilterOp = iota // FilterOrOp is filter type for or operator. FilterOrOp // FilterNotOp is filter type for not operator. FilterNotOp // FilterEqOp is filter type for equal comparison. FilterEqOp // FilterNeOp is filter type for not equal comparison. FilterNeOp // FilterLtOp is filter type for less than comparison. FilterLtOp // FilterLteOp is filter type for less than or equal comparison. FilterLteOp // FilterGtOp is filter type for greater than comparison. FilterGtOp // FilterGteOp is filter type for greter than or equal comparison. FilterGteOp // FilterNilOp is filter type for nil check. FilterNilOp // FilterNotNilOp is filter type for not nil check. FilterNotNilOp // FilterInOp is filter type for inclusion comparison. FilterInOp // FilterNinOp is filter type for not inclusion comparison. FilterNinOp // FilterLikeOp is filter type for like comparison. FilterLikeOp // FilterNotLikeOp is filter type for not like comparison. FilterNotLikeOp // FilterFragmentOp is filter type for custom filter. FilterFragmentOp )
type FilterQuery ¶
type FilterQuery struct { Type FilterOp Field string Value interface{} Inner []FilterQuery }
FilterQuery defines details of a coundition type.
func FilterFragment ¶
func FilterFragment(expr string, values ...interface{}) FilterQuery
FilterFragment add custom filter.
func Gt ¶
func Gt(field string, value interface{}) FilterQuery
Gt compares that left value is greater than to right value.
func Gte ¶
func Gte(field string, value interface{}) FilterQuery
Gte compares that left value is greater than or equal to right value.
func In ¶
func In(field string, values ...interface{}) FilterQuery
In check whethers value of the field is included in values.
func InInt ¶
func InInt(field string, values []int) FilterQuery
InInt check whethers integer values of the field is included.
func InString ¶
func InString(field string, values []string) FilterQuery
InString check whethers string values of the field is included.
func InUint ¶
func InUint(field string, values []uint) FilterQuery
InUint check whethers unsigned integer values of the field is included.
func Like ¶
func Like(field string, pattern string) FilterQuery
Like compares value of field to match string pattern.
func Lt ¶
func Lt(field string, value interface{}) FilterQuery
Lt compares that left value is less than to right value.
func Lte ¶
func Lte(field string, value interface{}) FilterQuery
Lte compares that left value is less than or equal to right value.
func Ne ¶
func Ne(field string, value interface{}) FilterQuery
Ne compares that left value is not equal to right value.
func Nin ¶
func Nin(field string, values ...interface{}) FilterQuery
Nin check whethers value of the field is not included in values.
func NinInt ¶
func NinInt(field string, values []int) FilterQuery
NinInt check whethers integer values of the is not included.
func NinString ¶
func NinString(field string, values []string) FilterQuery
NinString check whethers string values of the is not included.
func NinUint ¶
func NinUint(field string, values []uint) FilterQuery
NinUint check whethers unsigned integer values of the is not included.
func Not ¶
func Not(inner ...FilterQuery) FilterQuery
Not wraps filters using not. It'll negate the filter type if possible.
func NotLike ¶
func NotLike(field string, pattern string) FilterQuery
NotLike compares value of field to not match string pattern.
func (FilterQuery) And ¶
func (fq FilterQuery) And(filters ...FilterQuery) FilterQuery
And wraps filters using and.
func (FilterQuery) AndEq ¶
func (fq FilterQuery) AndEq(field string, value interface{}) FilterQuery
AndEq append equal expression using and.
func (FilterQuery) AndFragment ¶
func (fq FilterQuery) AndFragment(expr string, values ...interface{}) FilterQuery
AndFragment append fragment using and.
func (FilterQuery) AndGt ¶
func (fq FilterQuery) AndGt(field string, value interface{}) FilterQuery
AndGt append greater than expression using and.
func (FilterQuery) AndGte ¶
func (fq FilterQuery) AndGte(field string, value interface{}) FilterQuery
AndGte append greater than or equal expression using and.
func (FilterQuery) AndIn ¶
func (fq FilterQuery) AndIn(field string, values ...interface{}) FilterQuery
AndIn append is in expression using and.
func (FilterQuery) AndLike ¶
func (fq FilterQuery) AndLike(field string, pattern string) FilterQuery
AndLike append like expression using and.
func (FilterQuery) AndLt ¶
func (fq FilterQuery) AndLt(field string, value interface{}) FilterQuery
AndLt append lesser than expression using and.
func (FilterQuery) AndLte ¶
func (fq FilterQuery) AndLte(field string, value interface{}) FilterQuery
AndLte append lesser than or equal expression using and.
func (FilterQuery) AndNe ¶
func (fq FilterQuery) AndNe(field string, value interface{}) FilterQuery
AndNe append not equal expression using and.
func (FilterQuery) AndNil ¶
func (fq FilterQuery) AndNil(field string) FilterQuery
AndNil append is nil expression using and.
func (FilterQuery) AndNin ¶
func (fq FilterQuery) AndNin(field string, values ...interface{}) FilterQuery
AndNin append is not in expression using and.
func (FilterQuery) AndNotLike ¶
func (fq FilterQuery) AndNotLike(field string, pattern string) FilterQuery
AndNotLike append not like expression using and.
func (FilterQuery) AndNotNil ¶
func (fq FilterQuery) AndNotNil(field string) FilterQuery
AndNotNil append is not nil expression using and.
func (FilterQuery) None ¶
func (fq FilterQuery) None() bool
None returns true if no filter is specified.
func (FilterQuery) Or ¶
func (fq FilterQuery) Or(filter ...FilterQuery) FilterQuery
Or wraps filters using or.
func (FilterQuery) OrEq ¶
func (fq FilterQuery) OrEq(field string, value interface{}) FilterQuery
OrEq append equal expression using or.
func (FilterQuery) OrFragment ¶
func (fq FilterQuery) OrFragment(expr string, values ...interface{}) FilterQuery
OrFragment append fragment using or.
func (FilterQuery) OrGt ¶
func (fq FilterQuery) OrGt(field string, value interface{}) FilterQuery
OrGt append greater than expression using or.
func (FilterQuery) OrGte ¶
func (fq FilterQuery) OrGte(field string, value interface{}) FilterQuery
OrGte append greater than or equal expression using or.
func (FilterQuery) OrIn ¶
func (fq FilterQuery) OrIn(field string, values ...interface{}) FilterQuery
OrIn append is in expression using or.
func (FilterQuery) OrLike ¶
func (fq FilterQuery) OrLike(field string, pattern string) FilterQuery
OrLike append like expression using or.
func (FilterQuery) OrLt ¶
func (fq FilterQuery) OrLt(field string, value interface{}) FilterQuery
OrLt append lesser than expression using or.
func (FilterQuery) OrLte ¶
func (fq FilterQuery) OrLte(field string, value interface{}) FilterQuery
OrLte append lesser than or equal expression using or.
func (FilterQuery) OrNe ¶
func (fq FilterQuery) OrNe(field string, value interface{}) FilterQuery
OrNe append not equal expression using or.
func (FilterQuery) OrNil ¶
func (fq FilterQuery) OrNil(field string) FilterQuery
OrNil append is nil expression using or.
func (FilterQuery) OrNin ¶
func (fq FilterQuery) OrNin(field string, values ...interface{}) FilterQuery
OrNin append is not in expression using or.
func (FilterQuery) OrNotLike ¶
func (fq FilterQuery) OrNotLike(field string, pattern string) FilterQuery
OrNotLike append not like expression using or.
func (FilterQuery) OrNotNil ¶
func (fq FilterQuery) OrNotNil(field string) FilterQuery
OrNotNil append is not nil expression using or.
type ForeignKeyReference ¶
ForeignKeyReference definition.
type GroupQuery ¶
type GroupQuery struct { Fields []string Filter FilterQuery }
GroupQuery defines group clause of the query.
func (GroupQuery) Having ¶
func (gq GroupQuery) Having(filters ...FilterQuery) GroupQuery
Having appends filter for group query with and operand.
func (GroupQuery) OrHaving ¶
func (gq GroupQuery) OrHaving(filters ...FilterQuery) GroupQuery
OrHaving appends filter for group query with or operand.
func (GroupQuery) OrWhere ¶
func (gq GroupQuery) OrWhere(filters ...FilterQuery) GroupQuery
OrWhere is alias for OrHaving.
func (GroupQuery) Where ¶
func (gq GroupQuery) Where(filters ...FilterQuery) GroupQuery
Where is alias for having.
type Index ¶
type Index struct { Op SchemaOp Table string Name string Unique bool Columns []string Optional bool Options string }
Index definition.
type IndexOption ¶
type IndexOption interface {
// contains filtered or unexported methods
}
IndexOption interface. Available options are: Comment, Options.
type Instrumenter ¶
Instrumenter defines function type that can be used for instrumetation. This function should return a function with no argument as a callback for finished execution.
type IteratorOption ¶
type IteratorOption interface {
// contains filtered or unexported methods
}
IteratorOption is used to configure iteration behaviour, such as batch size, start id and finish id.
func BatchSize ¶
func BatchSize(size int) IteratorOption
BatchSize specifies the size of iterator batch. Defaults to 1000.
func Finish ¶
func Finish(id ...interface{}) IteratorOption
Finish specifies the primary value to finish at (inclusive).
func Start ¶
func Start(id ...interface{}) IteratorOption
Start specifies the primary value to start from (inclusive).
type JoinQuery ¶
JoinQuery defines join clause in query.
func NewFullJoinOn ¶
NewFullJoinOn table with given field.
func NewInnerJoinOn ¶
NewInnerJoinOn table with given field.
func NewJoinFragment ¶
NewJoinFragment defines a join clause using raw query.
func NewJoinWith ¶
NewJoinWith query with custom join mode, table and field.
func NewLeftJoinOn ¶
NewLeftJoinOn table with given field.
func NewRightJoinOn ¶
NewRightJoinOn table with given field.
type Key ¶
type Key struct { Op SchemaOp Name string Type KeyType Columns []string Rename string Reference ForeignKeyReference Options string }
Key definition.
type KeyOption ¶
type KeyOption interface {
// contains filtered or unexported methods
}
KeyOption interface. Available options are: Comment, Options.
type Limit ¶
type Limit int
Limit options. When passed as query, it limits returned result from database. When passed as column option, it sets the maximum size of the string/text/binary/integer columns.
type Map ¶
type Map map[string]interface{}
Map can be used as mutation for repository insert or update operation. This allows inserting or updating only on specified field. Insert/Update of has one or belongs to can be done using other Map as a value. Insert/Update of has many can be done using slice of Map as a value. Map is intended to be used internally within application, and not to be exposed directly as an APIs.
type Migration ¶
type Migration interface {
// contains filtered or unexported methods
}
Migration definition.
type Mutate ¶
Mutate stores mutation instruction.
func SetFragment ¶
SetFragment create a mutate operation using randoc fragment operation. Only available for Update.
type Mutation ¶
type Mutation struct { Mutates map[string]Mutate Assoc map[string]AssocMutation Unscoped Unscoped Reload Reload Cascade Cascade ErrorFunc ErrorFunc }
Mutation represents value to be inserted or updated to database. It's not safe to be used multiple time. some operation my alter mutation data.
func (*Mutation) IsAssocEmpty ¶
IsAssocEmpty returns true if no assoc's mutation is defined.
func (*Mutation) IsEmpty ¶
IsEmpty returns true if no mutates operation and assoc's mutation is defined.
func (*Mutation) IsMutatesEmpty ¶
IsMutatesEmpty returns true if no mutates operation is defined.
func (*Mutation) SetDeletedIDs ¶
SetDeletedIDs mutation. nil slice will clear association.
type NotFoundError ¶
type NotFoundError struct{}
NotFoundError returned whenever Find returns no result.
type Optional ¶
type Optional bool
Optional option. when used with create table, will create table only if it's not exists. when used with drop table, will drop table only if it's exists.
type Precision ¶
type Precision int
Precision defines the precision for the decimal fields, representing the total number of digits in the number.
type Querier ¶
type Querier interface {
Build(*Query)
}
Querier interface defines contract to be used for query builder.
type Query ¶
type Query struct { Table string SelectQuery SelectQuery JoinQuery []JoinQuery WhereQuery FilterQuery GroupQuery GroupQuery SortQuery []SortQuery OffsetQuery Offset LimitQuery Limit LockQuery Lock SQLQuery SQLQuery UnscopedQuery Unscoped ReloadQuery Reload CascadeQuery Cascade PreloadQuery []string // contains filtered or unexported fields }
Query defines information about query generated by query builder.
func Select ¶
Select query create a query with chainable syntax, using select as the starting point.
func Where ¶
func Where(filters ...FilterQuery) Query
Where create a query with chainable syntax, using where as the starting point.
func (Query) Cascade ¶ added in v0.10.0
Cascade enable/disable autoload association on Find and FindAll query.
type Repository ¶
type Repository interface { // Adapter used in this repository. Adapter(ctx context.Context) Adapter // Instrumentation defines callback to be used as instrumenter. Instrumentation(instrumenter Instrumenter) // Ping database. Ping(ctx context.Context) error // Iterate through a collection of records from database in batches. // This function returns iterator that can be used to loop all records. // Limit, Offset and Sort query is automatically ignored. Iterate(ctx context.Context, query Query, option ...IteratorOption) Iterator // Aggregate over the given field. // Supported aggregate: count, sum, avg, max, min. // Any select, group, offset, limit and sort query will be ignored automatically. // If complex aggregation is needed, consider using All instead. Aggregate(ctx context.Context, query Query, aggregate string, field string) (int, error) // MustAggregate over the given field. // Supported aggregate: count, sum, avg, max, min. // Any select, group, offset, limit and sort query will be ignored automatically. // If complex aggregation is needed, consider using All instead. // It'll panic if any error eccured. MustAggregate(ctx context.Context, query Query, aggregate string, field string) int // Count records that match the query. Count(ctx context.Context, collection string, queriers ...Querier) (int, error) // MustCount records that match the query. // It'll panic if any error eccured. MustCount(ctx context.Context, collection string, queriers ...Querier) int // Find a record that match the query. // If no result found, it'll return not found error. Find(ctx context.Context, record interface{}, queriers ...Querier) error // MustFind a record that match the query. // If no result found, it'll panic. MustFind(ctx context.Context, record interface{}, queriers ...Querier) // FindAll records that match the query. FindAll(ctx context.Context, records interface{}, queriers ...Querier) error // MustFindAll records that match the query. // It'll panic if any error eccured. MustFindAll(ctx context.Context, records interface{}, queriers ...Querier) // FindAndCountAll records that match the query. // This is a convenient method that combines FindAll and Count. It's useful when dealing with queries related to pagination. // Limit and Offset property will be ignored when performing count query. FindAndCountAll(ctx context.Context, records interface{}, queriers ...Querier) (int, error) // MustFindAndCountAll records that match the query. // This is a convenient method that combines FindAll and Count. It's useful when dealing with queries related to pagination. // Limit and Offset property will be ignored when performing count query. // It'll panic if any error eccured. MustFindAndCountAll(ctx context.Context, records interface{}, queriers ...Querier) int // Insert a record to database. Insert(ctx context.Context, record interface{}, mutators ...Mutator) error // MustInsert an record to database. // It'll panic if any error occurred. MustInsert(ctx context.Context, record interface{}, mutators ...Mutator) // InsertAll records. InsertAll(ctx context.Context, records interface{}) error // MustInsertAll records. // It'll panic if any error occurred. MustInsertAll(ctx context.Context, records interface{}) // Update a record in database. // It'll panic if any error occurred. Update(ctx context.Context, record interface{}, mutators ...Mutator) error // MustUpdate a record in database. // It'll panic if any error occurred. MustUpdate(ctx context.Context, record interface{}, mutators ...Mutator) // UpdateAll records tha match the query. UpdateAll(ctx context.Context, query Query, mutates ...Mutate) error // MustUpdateAll records that match the query. // It'll panic if any error occurred. MustUpdateAll(ctx context.Context, query Query, mutates ...Mutate) // Delete a record. Delete(ctx context.Context, record interface{}, options ...Cascade) error // MustDelete a record. // It'll panic if any error eccured. MustDelete(ctx context.Context, record interface{}, options ...Cascade) // DeleteAll records that match the query. DeleteAll(ctx context.Context, query Query) error // MustDeleteAll records that match the query. // It'll panic if any error eccured. MustDeleteAll(ctx context.Context, query Query) // Preload association with given query. // If association is already loaded, this will do nothing. // To force preloading even though association is already loaeded, add `Reload(true)` as query. Preload(ctx context.Context, records interface{}, field string, queriers ...Querier) error // MustPreload association with given query. // It'll panic if any error occurred. MustPreload(ctx context.Context, records interface{}, field string, queriers ...Querier) // Transaction performs transaction with given function argument. // Transaction scope/connection is automatically passed using context. Transaction(ctx context.Context, fn func(ctx context.Context) error) error }
Repository for interacting with database.
type SQLQuery ¶
type SQLQuery struct { Statement string Values []interface{} }
SQLQuery allows querying using native query supported by database.
type Scale ¶
type Scale int
Scale Defines the scale for the decimal fields, representing the number of digits after the decimal point.
type Schema ¶
type Schema struct {
Migrations []Migration
}
Schema builder.
func (*Schema) AddColumn ¶
func (s *Schema) AddColumn(table string, name string, typ ColumnType, options ...ColumnOption)
AddColumn with name and type.
func (*Schema) AlterTable ¶
func (s *Schema) AlterTable(name string, fn func(t *AlterTable), options ...TableOption)
AlterTable with name and its definition.
func (*Schema) CreateIndex ¶
func (s *Schema) CreateIndex(table string, name string, column []string, options ...IndexOption)
CreateIndex for columns on a table.
func (*Schema) CreateTable ¶
func (s *Schema) CreateTable(name string, fn func(t *Table), options ...TableOption)
CreateTable with name and its definition.
func (*Schema) CreateTableIfNotExists ¶
func (s *Schema) CreateTableIfNotExists(name string, fn func(t *Table), options ...TableOption)
CreateTableIfNotExists with name and its definition.
func (*Schema) CreateUniqueIndex ¶
func (s *Schema) CreateUniqueIndex(table string, name string, column []string, options ...IndexOption)
CreateUniqueIndex for columns on a table.
func (*Schema) DropColumn ¶
func (s *Schema) DropColumn(table string, name string, options ...ColumnOption)
DropColumn by name.
func (*Schema) DropIndex ¶
func (s *Schema) DropIndex(table string, name string, options ...IndexOption)
DropIndex by name.
func (*Schema) DropTable ¶
func (s *Schema) DropTable(name string, options ...TableOption)
DropTable by name.
func (*Schema) DropTableIfExists ¶
func (s *Schema) DropTableIfExists(name string, options ...TableOption)
DropTableIfExists by name.
func (*Schema) RenameColumn ¶
func (s *Schema) RenameColumn(table string, name string, newName string, options ...ColumnOption)
RenameColumn by name.
func (*Schema) RenameTable ¶
func (s *Schema) RenameTable(name string, newName string, options ...TableOption)
RenameTable by name.
type SelectQuery ¶
SelectQuery defines select clause of the query.
type SortQuery ¶
SortQuery defines sort information of query.
func NewSortAsc ¶
NewSortAsc sorts field with ascending sort.
func NewSortDesc ¶
NewSortDesc sorts field with descending sort.
type Structset ¶
type Structset struct {
// contains filtered or unexported fields
}
Structset can be used as mutation for repository insert or update operation. This will save every field in struct and it's association as long as it's loaded. This is the default mutator used by repository.
func NewStructset ¶
NewStructset from a struct.
type Table ¶
type Table struct { Op SchemaOp Name string Rename string Definitions []TableDefinition Optional bool Options string }
Table definition.
func (*Table) BigInt ¶
func (t *Table) BigInt(name string, options ...ColumnOption)
BigInt defines a column with name and BigInt type.
func (*Table) Bool ¶
func (t *Table) Bool(name string, options ...ColumnOption)
Bool defines a column with name and Bool type.
func (*Table) Column ¶
func (t *Table) Column(name string, typ ColumnType, options ...ColumnOption)
Column defines a column with name and type.
func (*Table) Date ¶
func (t *Table) Date(name string, options ...ColumnOption)
Date defines a column with name and Date type.
func (*Table) DateTime ¶
func (t *Table) DateTime(name string, options ...ColumnOption)
DateTime defines a column with name and DateTime type.
func (*Table) Decimal ¶
func (t *Table) Decimal(name string, options ...ColumnOption)
Decimal defines a column with name and Decimal type.
func (*Table) Float ¶
func (t *Table) Float(name string, options ...ColumnOption)
Float defines a column with name and Float type.
func (*Table) ForeignKey ¶
ForeignKey defines foreign key index.
func (*Table) ID ¶
func (t *Table) ID(name string, options ...ColumnOption)
ID defines a column with name and ID type. the resulting database type will depends on database.
func (*Table) Int ¶
func (t *Table) Int(name string, options ...ColumnOption)
Int defines a column with name and Int type.
func (*Table) PrimaryKey ¶
PrimaryKey defines a primary key for table.
func (*Table) PrimaryKeys ¶
PrimaryKeys defines composite primary keys for table.
func (*Table) SmallInt ¶ added in v0.10.0
func (t *Table) SmallInt(name string, options ...ColumnOption)
SmallInt defines a column with name and Small type.
func (*Table) String ¶
func (t *Table) String(name string, options ...ColumnOption)
String defines a column with name and String type.
func (*Table) Text ¶
func (t *Table) Text(name string, options ...ColumnOption)
Text defines a column with name and Text type.
func (*Table) Time ¶
func (t *Table) Time(name string, options ...ColumnOption)
Time defines a column with name and Time type.
func (*Table) Timestamp ¶
func (t *Table) Timestamp(name string, options ...ColumnOption)
Timestamp defines a column with name and Timestamp type.
type TableDefinition ¶
type TableDefinition interface {
// contains filtered or unexported methods
}
TableDefinition interface.
type TableOption ¶
type TableOption interface {
// contains filtered or unexported methods
}
TableOption interface. Available options are: Comment, Options.
Source Files ¶
- adapter.go
- association.go
- changeset.go
- collection.go
- column.go
- context_wrapper.go
- convert.go
- cursor.go
- document.go
- errors.go
- filter_query.go
- group_query.go
- index.go
- instrumentation.go
- iterator.go
- join_query.go
- key.go
- map.go
- mutation.go
- nullable.go
- query.go
- rel.go
- repository.go
- schema.go
- schema_options.go
- select_query.go
- sort_query.go
- sql_query.go
- structset.go
- table.go
- util.go
Directories ¶
Path | Synopsis |
---|---|
adapter
|
|
mysql
Package mysql wraps mysql driver as an adapter for REL.
|
Package mysql wraps mysql driver as an adapter for REL. |
postgres
Package postgres wraps postgres (pq) driver as an adapter for REL.
|
Package postgres wraps postgres (pq) driver as an adapter for REL. |
specs
Package specs defines test specifications for rel's adapter.
|
Package specs defines test specifications for rel's adapter. |
sql
Package sql is general sql adapter that wraps database/sql.
|
Package sql is general sql adapter that wraps database/sql. |
sqlite3
Package sqlite3 wraps go-sqlite3 driver as an adapter for rel.
|
Package sqlite3 wraps go-sqlite3 driver as an adapter for rel. |
cmd
|
|
Package group is syntatic sugar for building group query.
|
Package group is syntatic sugar for building group query. |
Package join is syntatic sugar for building join query.
|
Package join is syntatic sugar for building join query. |
Package sort is syntatic sugar for building sort query.
|
Package sort is syntatic sugar for building sort query. |
Package where is syntatic sugar for building where query.
|
Package where is syntatic sugar for building where query. |