Documentation
¶
Overview ¶
Package rel is a Database Layer for SQL Database.
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) 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) 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) 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 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) 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) 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)
- 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) 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 ¶ added in v0.7.0
type AlterTable struct {
Table
}
AlterTable Migrator.
func (*AlterTable) DropColumn ¶ added in v0.7.0
func (at *AlterTable) DropColumn(name string, options ...ColumnOption)
DropColumn from this table.
func (*AlterTable) RenameColumn ¶ added in v0.7.0
func (at *AlterTable) RenameColumn(name string, newName string, options ...ColumnOption)
RenameColumn to a new name.
type AssocMutation ¶ added in v0.4.0
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) 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.
type AssociationType ¶
type AssociationType uint8
AssociationType defines the type of association in database.
type Cascade ¶ added in v0.4.0
type Cascade bool
Cascade enable or disable updating associations. Default to true.
type Changeset ¶ added in v0.4.0
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 ¶ added in v0.4.0
func NewChangeset(record interface{}) Changeset
NewChangeset returns new changeset mutator for given record.
func (Changeset) FieldChanged ¶ added in v0.4.0
FieldChanged returns true if field exists and it's already chagned. 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 ¶ added in v0.6.0
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 ¶ added in v0.6.0
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 ¶ added in v0.2.0
func (c Collection) Slice(i, j int) *Collection
Slice returns a new collection that is a slice of the original collection.s
type Column ¶ added in v0.7.0
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 ¶ added in v0.7.0
type ColumnOption interface {
// contains filtered or unexported methods
}
ColumnOption interface. Available options are: Nil, Unsigned, Limit, Precision, Scale, Default, Comment, Options.
func Default ¶ added in v0.7.0
func Default(def interface{}) ColumnOption
Default allows to set a default value on the column.).
type ColumnType ¶ added in v0.7.0
type ColumnType string
ColumnType definition.
const ( // ID ColumnType. ID ColumnType = "ID" // Bool ColumnType. Bool ColumnType = "BOOL" // 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 ¶ added in v0.3.0
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 ¶ added in v0.2.0
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) Persisted ¶ added in v0.6.0
Persisted returns true if document primary key is not zero.
func (Document) PrimaryField ¶
PrimaryField column name of this document. panic if document uses composite key.
func (Document) PrimaryFields ¶ added in v0.6.0
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 ¶ added in v0.6.0
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 ¶ added in v0.2.0
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 ¶ added in v0.2.0
func (df DocumentFlag) Is(flag DocumentFlag) bool
Is returns true if it's defined.
type ErrorFunc ¶ added in v0.5.0
ErrorFunc allows conversion REL's error to Application custom errors.
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 ¶ added in v0.7.0
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 ¶ added in v0.7.0
type Index struct { Op SchemaOp Table string Name string Unique bool Columns []string Optional bool Options string }
Index definition.
type IndexOption ¶ added in v0.7.0
type IndexOption interface {
// contains filtered or unexported methods
}
IndexOption interface. Available options are: Comment, Options.
type Instrumenter ¶ added in v0.3.0
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 ¶ added in v0.3.0
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 ¶ added in v0.3.0
func BatchSize(size int) IteratorOption
BatchSize specifies the size of iterator batch. Defaults to 1000.
func Finish ¶ added in v0.3.0
func Finish(id ...interface{}) IteratorOption
Finish specfies the primary value to finish at (inclusive).
func Start ¶ added in v0.3.0
func Start(id ...interface{}) IteratorOption
Start specfies 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 ¶ added in v0.7.0
type Key struct { Op SchemaOp Name string Type KeyType Columns []string Rename string Reference ForeignKeyReference Options string }
Key definition.
type KeyOption ¶ added in v0.7.0
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 ¶ added in v0.7.0
type Migration interface {
// contains filtered or unexported methods
}
Migration definition.
type Mutate ¶ added in v0.4.0
Mutate stores mutation instruction.
func SetFragment ¶ added in v0.2.0
SetFragment create a mutate operation using randoc fragment operation. Only available for Update.
type Mutation ¶ added in v0.4.0
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 ¶ added in v0.4.0
IsAssocEmpty returns true if no assoc's mutation is defined.
func (*Mutation) IsEmpty ¶ added in v0.4.0
IsEmpty returns true if no mutates operation and assoc's mutation is defined.
func (*Mutation) IsMutatesEmpty ¶ added in v0.4.0
IsMutatesEmpty returns true if no mutates operation is defined.
func (*Mutation) SetDeletedIDs ¶ added in v0.4.0
SetDeletedIDs mutation. nil slice will clear association.
type NotFoundError ¶ added in v0.2.0
type NotFoundError struct{}
NotFoundError returned whenever Find returns no result.
type Optional ¶ added in v0.7.0
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 ¶ added in v0.7.0
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 UnscopedQuery Unscoped ReloadQuery Reload SQLQuery SQLQuery // 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.
type Reload ¶ added in v0.2.0
type Reload bool
Reload force reload after insert/update. Default to false.
type Repository ¶
type Repository interface { Adapter(ctx context.Context) Adapter Instrumentation(instrumenter Instrumenter) Ping(ctx context.Context) error Iterate(ctx context.Context, query Query, option ...IteratorOption) Iterator Aggregate(ctx context.Context, query Query, aggregate string, field string) (int, error) MustAggregate(ctx context.Context, query Query, aggregate string, field string) int Count(ctx context.Context, collection string, queriers ...Querier) (int, error) MustCount(ctx context.Context, collection string, queriers ...Querier) int Find(ctx context.Context, record interface{}, queriers ...Querier) error MustFind(ctx context.Context, record interface{}, queriers ...Querier) FindAll(ctx context.Context, records interface{}, queriers ...Querier) error MustFindAll(ctx context.Context, records interface{}, queriers ...Querier) FindAndCountAll(ctx context.Context, records interface{}, queriers ...Querier) (int, error) MustFindAndCountAll(ctx context.Context, records interface{}, queriers ...Querier) int Insert(ctx context.Context, record interface{}, mutators ...Mutator) error MustInsert(ctx context.Context, record interface{}, mutators ...Mutator) InsertAll(ctx context.Context, records interface{}) error MustInsertAll(ctx context.Context, records interface{}) Update(ctx context.Context, record interface{}, mutators ...Mutator) error MustUpdate(ctx context.Context, record interface{}, mutators ...Mutator) UpdateAll(ctx context.Context, query Query, mutates ...Mutate) error MustUpdateAll(ctx context.Context, query Query, mutates ...Mutate) Delete(ctx context.Context, record interface{}, options ...Cascade) error MustDelete(ctx context.Context, record interface{}, options ...Cascade) DeleteAll(ctx context.Context, query Query) error MustDeleteAll(ctx context.Context, query Query) Preload(ctx context.Context, records interface{}, field string, queriers ...Querier) error MustPreload(ctx context.Context, records interface{}, field string, queriers ...Querier) Transaction(ctx context.Context, fn func(ctx context.Context) error) error }
Repository defines sets of available database operations.
type SQLQuery ¶ added in v0.4.0
type SQLQuery struct { Statement string Values []interface{} }
SQLQuery allows querying using native query supported by database.
type Scale ¶ added in v0.7.0
type Scale int
Scale Defines the scale for the decimal fields, representing the number of digits after the decimal point.
type Schema ¶ added in v0.7.0
type Schema struct {
Migrations []Migration
}
Schema builder.
func (*Schema) AddColumn ¶ added in v0.7.0
func (s *Schema) AddColumn(table string, name string, typ ColumnType, options ...ColumnOption)
AddColumn with name and type.
func (*Schema) AlterTable ¶ added in v0.7.0
func (s *Schema) AlterTable(name string, fn func(t *AlterTable), options ...TableOption)
AlterTable with name and its definition.
func (*Schema) CreateIndex ¶ added in v0.7.0
func (s *Schema) CreateIndex(table string, name string, column []string, options ...IndexOption)
CreateIndex for columns on a table.
func (*Schema) CreateTable ¶ added in v0.7.0
func (s *Schema) CreateTable(name string, fn func(t *Table), options ...TableOption)
CreateTable with name and its definition.
func (*Schema) CreateTableIfNotExists ¶ added in v0.7.0
func (s *Schema) CreateTableIfNotExists(name string, fn func(t *Table), options ...TableOption)
CreateTableIfNotExists with name and its definition.
func (*Schema) CreateUniqueIndex ¶ added in v0.7.0
func (s *Schema) CreateUniqueIndex(table string, name string, column []string, options ...IndexOption)
CreateUniqueIndex for columns on a table.
func (*Schema) DropColumn ¶ added in v0.7.0
func (s *Schema) DropColumn(table string, name string, options ...ColumnOption)
DropColumn by name.
func (*Schema) DropIndex ¶ added in v0.7.0
func (s *Schema) DropIndex(table string, name string, options ...IndexOption)
DropIndex by name.
func (*Schema) DropTable ¶ added in v0.7.0
func (s *Schema) DropTable(name string, options ...TableOption)
DropTable by name.
func (*Schema) DropTableIfExists ¶ added in v0.7.0
func (s *Schema) DropTableIfExists(name string, options ...TableOption)
DropTableIfExists by name.
func (*Schema) RenameColumn ¶ added in v0.7.0
func (s *Schema) RenameColumn(table string, name string, newName string, options ...ColumnOption)
RenameColumn by name.
func (*Schema) RenameTable ¶ added in v0.7.0
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 ¶ added in v0.7.0
type Table struct { Op SchemaOp Name string Rename string Definitions []TableDefinition Optional bool Options string }
Table definition.
func (*Table) BigInt ¶ added in v0.7.0
func (t *Table) BigInt(name string, options ...ColumnOption)
BigInt defines a column with name and BigInt type.
func (*Table) Bool ¶ added in v0.7.0
func (t *Table) Bool(name string, options ...ColumnOption)
Bool defines a column with name and Bool type.
func (*Table) Column ¶ added in v0.7.0
func (t *Table) Column(name string, typ ColumnType, options ...ColumnOption)
Column defines a column with name and type.
func (*Table) Date ¶ added in v0.7.0
func (t *Table) Date(name string, options ...ColumnOption)
Date defines a column with name and Date type.
func (*Table) DateTime ¶ added in v0.7.0
func (t *Table) DateTime(name string, options ...ColumnOption)
DateTime defines a column with name and DateTime type.
func (*Table) Decimal ¶ added in v0.7.0
func (t *Table) Decimal(name string, options ...ColumnOption)
Decimal defines a column with name and Decimal type.
func (*Table) Float ¶ added in v0.7.0
func (t *Table) Float(name string, options ...ColumnOption)
Float defines a column with name and Float type.
func (*Table) ForeignKey ¶ added in v0.7.0
ForeignKey defines foreign key index.
func (*Table) ID ¶ added in v0.7.0
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 ¶ added in v0.7.0
func (t *Table) Int(name string, options ...ColumnOption)
Int defines a column with name and Int type.
func (*Table) PrimaryKey ¶ added in v0.7.0
PrimaryKey defines a primary key for table.
func (*Table) PrimaryKeys ¶ added in v0.7.0
PrimaryKeys defines composite primary keys for table.
func (*Table) String ¶ added in v0.7.0
func (t *Table) String(name string, options ...ColumnOption)
String defines a column with name and String type.
func (*Table) Text ¶ added in v0.7.0
func (t *Table) Text(name string, options ...ColumnOption)
Text defines a column with name and Text type.
func (*Table) Time ¶ added in v0.7.0
func (t *Table) Time(name string, options ...ColumnOption)
Time defines a column with name and Time type.
func (*Table) Timestamp ¶ added in v0.7.0
func (t *Table) Timestamp(name string, options ...ColumnOption)
Timestamp defines a column with name and Timestamp type.
type TableDefinition ¶ added in v0.7.0
type TableDefinition interface {
// contains filtered or unexported methods
}
TableDefinition interface.
type TableOption ¶ added in v0.7.0
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. |