Documentation ¶
Index ¶
- Constants
- Variables
- func CallModelHook(b Backend, m interface{}, hook string) apperror.Error
- func GetModelCollection(model interface{}) (string, apperror.Error)
- func MustGetModelCollection(model interface{}) string
- func PickRandom(slice interface{}) interface{}
- func PickRandomSubSlice(slice interface{}, count int) interface{}
- func Pluralize(str string) string
- func RandomBool() bool
- func RandomInt(min, max int) int
- func RandomTime(min, max time.Time) time.Time
- func SetPointer(ptr, val interface{})
- func SetSlicePointer(ptr interface{}, values []interface{})
- func StrAfterFirst(str, separator string) string
- func StrAfterLast(str, separator string) string
- func StrBeforeFirst(str, separator string) string
- func StrBeforeLast(str, separator string) string
- func StubText(length int) string
- func StubTextRandom(min, max int) string
- type Attribute
- func (a *Attribute) AutoIncrement() bool
- func (a *Attribute) BackendEmbed() bool
- func (a *Attribute) BackendMarshal() bool
- func (a *Attribute) BackendType() string
- func (a *Attribute) BuildFieldExpression() *FieldExpr
- func (a *Attribute) DefaultValue() interface{}
- func (a *Attribute) IgnoreIfZero() bool
- func (a *Attribute) IndexName() string
- func (a *Attribute) IsIndex() bool
- func (a *Attribute) IsPrimaryKey() bool
- func (a *Attribute) IsUnique() bool
- func (a *Attribute) IsUniqueWith() []string
- func (a *Attribute) Max() float64
- func (a *Attribute) Min() float64
- func (a *Attribute) SetAutoIncrement(val bool)
- func (a *Attribute) SetBackendEmbed(val bool)
- func (a *Attribute) SetBackendMarshal(val bool)
- func (a *Attribute) SetBackendType(val string)
- func (a *Attribute) SetDefaultValue(val interface{})
- func (a *Attribute) SetIgnoreIfZero(val bool)
- func (a *Attribute) SetIndexName(val string)
- func (a *Attribute) SetIsIndex(x bool)
- func (a *Attribute) SetIsPrimaryKey(val bool)
- func (a *Attribute) SetIsUnique(val bool)
- func (a *Attribute) SetIsUniqueWith(val []string)
- func (a *Attribute) SetMax(val float64)
- func (a *Attribute) SetMin(val float64)
- type Backend
- type BaseBackend
- func (b *BaseBackend) Build()
- func (b *BaseBackend) BuildJoins(info *ModelInfo, q *Query) apperror.Error
- func (b *BaseBackend) BuildLogger()
- func (b *BaseBackend) BuildRelationQuery(q *RelationQuery) (*Query, apperror.Error)
- func (b *BaseBackend) Clone() *BaseBackend
- func (b *BaseBackend) Count(q *Query) (int, apperror.Error)
- func (b *BaseBackend) Create(models ...interface{}) apperror.Error
- func (b *BaseBackend) CreateByMap(collection string, data map[string]interface{}) (interface{}, apperror.Error)
- func (b *BaseBackend) CreateCollection(collections ...string) apperror.Error
- func (b *BaseBackend) CreateField(collection, fieldName string) apperror.Error
- func (b *BaseBackend) CreateIndex(collection, indexName string, unique bool, fields ...string) apperror.Error
- func (b *BaseBackend) Debug() bool
- func (b *BaseBackend) Delete(model interface{}) apperror.Error
- func (b *BaseBackend) DeleteMany(query *Query) apperror.Error
- func (b *BaseBackend) DisableProfiling()
- func (b *BaseBackend) DoJoin(baseInfo *ModelInfo, objs []interface{}, joinQ *RelationQuery) apperror.Error
- func (b *BaseBackend) DoJoins(baseInfo *ModelInfo, q *Query, models []interface{}) apperror.Error
- func (b *BaseBackend) DropAllCollections() apperror.Error
- func (b *BaseBackend) DropCollection(collection string, ifExists, cascade bool) apperror.Error
- func (b *BaseBackend) DropField(collection, field string) apperror.Error
- func (b *BaseBackend) DropIndex(indexName string) apperror.Error
- func (b *BaseBackend) EnableProfiling()
- func (b *BaseBackend) FindBy(collection, field string, value interface{}, targetSlice ...interface{}) ([]interface{}, apperror.Error)
- func (b *BaseBackend) FindOne(collection string, id interface{}, targetModel ...interface{}) (interface{}, apperror.Error)
- func (b *BaseBackend) FindOneBy(collection, field string, value interface{}, targetModel ...interface{}) (interface{}, apperror.Error)
- func (b *BaseBackend) GetHooks(hook string) []HookHandler
- func (b *BaseBackend) HasCollection(collection string) bool
- func (b *BaseBackend) HasNativeJoins() bool
- func (b *BaseBackend) InfoForModel(model interface{}) (*ModelInfo, apperror.Error)
- func (b *BaseBackend) Last(q *Query, targetModels ...interface{}) (interface{}, apperror.Error)
- func (b *BaseBackend) Logger() *logrus.Logger
- func (b *BaseBackend) M2M(model interface{}, name string) (M2MCollection, apperror.Error)
- func (b *BaseBackend) ModelInfo(collection string) *ModelInfo
- func (b *BaseBackend) ModelInfos() ModelInfos
- func (b *BaseBackend) ModelToMap(model interface{}, marshal bool, includeRelations bool) (map[string]interface{}, apperror.Error)
- func (b *BaseBackend) Name() string
- func (b *BaseBackend) NewModel(collection string) (interface{}, apperror.Error)
- func (b *BaseBackend) NewModelQuery(model interface{}) (*Query, apperror.Error)
- func (b *BaseBackend) NewModelSlice(collection string) (interface{}, apperror.Error)
- func (b *BaseBackend) NewQuery(collection string) (*Query, apperror.Error)
- func (b *BaseBackend) PersistRelations(action string, beforePersist bool, info *ModelInfo, model interface{}) apperror.Error
- func (b *BaseBackend) Pluck(q *Query) ([]map[string]interface{}, apperror.Error)
- func (b *BaseBackend) ProfilingEnabled() bool
- func (b *BaseBackend) Q(arg interface{}, args ...interface{}) *Query
- func (b *BaseBackend) Query(q *Query, targetSlice ...interface{}) ([]interface{}, apperror.Error)
- func (b *BaseBackend) QueryCursor(q *Query) (Cursor, apperror.Error)
- func (b *BaseBackend) QueryOne(q *Query, targetModels ...interface{}) (interface{}, apperror.Error)
- func (b *BaseBackend) RegisterHook(hook string, handler HookHandler)
- func (b *BaseBackend) RegisterModel(model interface{}) *ModelInfo
- func (b *BaseBackend) Related(model interface{}, name string) (*RelationQuery, apperror.Error)
- func (b *BaseBackend) RenameCollection(collection, newName string) apperror.Error
- func (b *BaseBackend) RenameField(collection, field, newName string) apperror.Error
- func (b *BaseBackend) Save(model interface{}) apperror.Error
- func (b *BaseBackend) SetDebug(x bool)
- func (b *BaseBackend) SetLogger(x *logrus.Logger)
- func (b *BaseBackend) SetName(name string)
- func (b *BaseBackend) Update(model interface{}) apperror.Error
- func (b *BaseBackend) UpdateByMap(query *Query, data map[string]interface{}) apperror.Error
- type BaseMigrationAttempt
- func (m BaseMigrationAttempt) Collection() string
- func (a *BaseMigrationAttempt) GetComplete() bool
- func (a *BaseMigrationAttempt) GetFinishedAt() time.Time
- func (a *BaseMigrationAttempt) GetStartedAt() time.Time
- func (a *BaseMigrationAttempt) GetVersion() int
- func (a *BaseMigrationAttempt) SetComplete(x bool)
- func (a *BaseMigrationAttempt) SetFinishedAt(x time.Time)
- func (a *BaseMigrationAttempt) SetStartedAt(x time.Time)
- func (a *BaseMigrationAttempt) SetVersion(x int)
- type BaseMigrationAttemptIntId
- type Cursor
- type DefaultM2MCollection
- func (c *DefaultM2MCollection) Add(models ...interface{}) apperror.Error
- func (c *DefaultM2MCollection) All() ([]interface{}, apperror.Error)
- func (c *DefaultM2MCollection) Clear() apperror.Error
- func (c *DefaultM2MCollection) Contains(model interface{}) (bool, apperror.Error)
- func (c *DefaultM2MCollection) ContainsId(id interface{}) (bool, apperror.Error)
- func (c *DefaultM2MCollection) Count() (int, apperror.Error)
- func (c *DefaultM2MCollection) Q() *Query
- func (c *DefaultM2MCollection) Remove(models ...interface{}) apperror.Error
- func (c *DefaultM2MCollection) Replace(models ...interface{}) apperror.Error
- type Field
- func (f *Field) BackendName() string
- func (f *Field) EmbeddingStructName() string
- func (f *Field) IsRequired() bool
- func (f *Field) MarshalName() string
- func (f *Field) Name() string
- func (f *Field) SetBackendName(val string)
- func (f *Field) SetEmbeddingStructName(val string)
- func (f *Field) SetIsRequired(val bool)
- func (f *Field) SetMarshalName(val string)
- func (f *Field) SetName(val string)
- func (f *Field) SetStructName(val string)
- func (f *Field) SetStructType(x reflect.Type)
- func (f *Field) SetType(val reflect.Type)
- func (f *Field) StructName() string
- func (f *Field) StructType() reflect.Type
- func (f *Field) Type() reflect.Type
- type HookHandler
- type IntIdModel
- type JoinAssigner
- type M2MCollection
- type Migration
- type MigrationAttempt
- type MigrationBackend
- type MigrationHandler
- func (m *MigrationHandler) Add(migrations ...Migration)
- func (m *MigrationHandler) Get(version int) *Migration
- func (m *MigrationHandler) HasMigration(version int) bool
- func (m *MigrationHandler) Migrate(force bool) apperror.Error
- func (m *MigrationHandler) MigrateTo(targetVersion int, force bool) apperror.Error
- func (handler *MigrationHandler) RunMigration(m *Migration) apperror.Error
- type ModelAfterCreateHook
- type ModelAfterDeleteHook
- type ModelAfterQueryHook
- type ModelAfterUpdateHook
- type ModelBackendNameHook
- type ModelBeforeCreateHook
- type ModelBeforeDeleteHook
- type ModelBeforeUpdateHook
- type ModelCollectionHook
- type ModelIdGetterHook
- type ModelIdSetterHook
- type ModelInfo
- func (m *ModelInfo) AddAttribute(attr *Attribute)
- func (m *ModelInfo) AddRelation(rel *Relation)
- func (m *ModelInfo) Attribute(name string) *Attribute
- func (m *ModelInfo) Attributes() map[string]*Attribute
- func (m *ModelInfo) BackendName() string
- func (info *ModelInfo) BuildCreateStmt(withReferences bool) *CreateCollectionStmt
- func (m *ModelInfo) Collection() string
- func (info *ModelInfo) DetermineModelId(model interface{}) (interface{}, apperror.Error)
- func (info *ModelInfo) DetermineModelStrId(model interface{}) (string, apperror.Error)
- func (m *ModelInfo) FindAttribute(name string) *Attribute
- func (m *ModelInfo) FindRelation(name string) *Relation
- func (m *ModelInfo) FullStructName() string
- func (m *ModelInfo) HasAttribute(name string) bool
- func (m *ModelInfo) HasRelation(name string) bool
- func (m *ModelInfo) HasStruct() bool
- func (m *ModelInfo) Item() interface{}
- func (m *ModelInfo) MarshalName() string
- func (info *ModelInfo) ModelDeleteStmt(model interface{}) *DeleteStmt
- func (info *ModelInfo) ModelFilter(model interface{}) Expression
- func (info *ModelInfo) ModelFromMap(data map[string]interface{}) (interface{}, apperror.Error)
- func (info *ModelInfo) ModelHasId(model interface{}) (bool, apperror.Error)
- func (info *ModelInfo) ModelSelect(model interface{}) *SelectStmt
- func (info *ModelInfo) ModelToFieldExpressions(model interface{}) ([]*FieldValueExpr, apperror.Error)
- func (info *ModelInfo) ModelToMap(model interface{}, forBackend, marshal bool, includeRelations bool) (map[string]interface{}, apperror.Error)
- func (info *ModelInfo) MustDetermineModelId(model interface{}) interface{}
- func (info *ModelInfo) MustDetermineModelStrId(model interface{}) string
- func (m *ModelInfo) New() interface{}
- func (m *ModelInfo) NewReflector() *reflector.StructReflector
- func (m *ModelInfo) NewSlice() *reflector.SliceReflector
- func (m *ModelInfo) PkAttribute() *Attribute
- func (m *ModelInfo) Reflector() *reflector.StructReflector
- func (m *ModelInfo) Relation(name string) *Relation
- func (m *ModelInfo) Relations() map[string]*Relation
- func (m *ModelInfo) SetAttributes(attrs map[string]*Attribute)
- func (m *ModelInfo) SetBackendName(val string)
- func (m *ModelInfo) SetCollection(val string)
- func (m *ModelInfo) SetFullStructName(val string)
- func (m *ModelInfo) SetItem(val interface{})
- func (m *ModelInfo) SetMarshalName(val string)
- func (info *ModelInfo) SetModelId(model, id interface{}) apperror.Error
- func (m *ModelInfo) SetRelations(rels map[string]*Relation)
- func (m *ModelInfo) SetStructName(val string)
- func (m *ModelInfo) SetTransientFields(x map[string]*Field)
- func (m *ModelInfo) StructName() string
- func (m *ModelInfo) TransientFields() map[string]*Field
- func (info *ModelInfo) UpdateModelFromData(model interface{}, data map[string]interface{}) apperror.Error
- func (info *ModelInfo) ValidateModel(m interface{}) apperror.Error
- type ModelInfos
- type ModelMarshalNameHook
- type ModelStrIdGetterHook
- type ModelStrIdSetterHook
- type ModelValidateHook
- type Point
- type Query
- func (q *Query) And(field string, val interface{}) *Query
- func (q *Query) AndCond(field, condition string, val interface{}) *Query
- func (q *Query) AndExpr(filters ...Expression) *Query
- func (q *Query) Count() (int, apperror.Error)
- func (q *Query) Delete() apperror.Error
- func (q *Query) Field(fields ...string) *Query
- func (q *Query) FieldExpr(exprs ...Expression) *Query
- func (q *Query) Filter(field string, val interface{}) *Query
- func (q *Query) FilterCond(field string, condition string, val interface{}) *Query
- func (q *Query) FilterExpr(expressions ...Expression) *Query
- func (q *Query) Find(targetSlice ...interface{}) ([]interface{}, apperror.Error)
- func (q *Query) First(targetModel ...interface{}) (interface{}, apperror.Error)
- func (q *Query) GetBackend() Backend
- func (q *Query) GetCollection() string
- func (q *Query) GetJoin(relationName string) *RelationQuery
- func (q *Query) GetJoinResultAssigner() JoinAssigner
- func (q *Query) GetJoins() map[string]*RelationQuery
- func (q *Query) GetLimit() int
- func (q *Query) GetModels() []interface{}
- func (q *Query) GetName() string
- func (q *Query) GetOffset() int
- func (q *Query) GetStatement() *SelectStmt
- func (q *Query) HasJoin(relationName string) bool
- func (q *Query) Join(relationName string, joinType ...string) *Query
- func (q *Query) JoinQ(jqs ...*RelationQuery) *Query
- func (q *Query) Last(targetModel ...interface{}) (interface{}, apperror.Error)
- func (q *Query) Limit(limit int) *Query
- func (q *Query) Name(x string) *Query
- func (q *Query) Normalize() apperror.Error
- func (q *Query) Not(field string, val interface{}) *Query
- func (q *Query) NotCond(field string, condition string, val interface{}) *Query
- func (q *Query) NotExpr(filters ...Expression) *Query
- func (q *Query) Offset(offset int) *Query
- func (q *Query) Or(field string, val interface{}) *Query
- func (q *Query) OrCond(field string, condition string, val interface{}) *Query
- func (q *Query) OrExpr(filters ...Expression) *Query
- func (q *Query) Pluck() ([]map[string]interface{}, apperror.Error)
- func (q *Query) Related(name string) *RelationQuery
- func (q *Query) SetBackend(x Backend)
- func (q *Query) SetCollection(collection string)
- func (q *Query) SetFieldExpressions(expressions []Expression) *Query
- func (q *Query) SetFields(fields []string) *Query
- func (q *Query) SetFilters(expressions ...Expression) *Query
- func (q *Query) SetJoinResultAssigner(x JoinAssigner)
- func (q *Query) SetModels(x []interface{})
- func (q *Query) SetName(name string)
- func (q *Query) SetSorts(exprs []*SortExpr) *Query
- func (q *Query) SetStatement(stmt *SelectStmt)
- func (q *Query) Sort(field string, asc bool) *Query
- func (q *Query) SortExpr(expr *SortExpr) *Query
- type QueryStat
- type Relation
- func (r *Relation) AutoCreate() bool
- func (r *Relation) AutoDelete() bool
- func (r *Relation) AutoUpdate() bool
- func (r *Relation) ForeignField() string
- func (r *Relation) InversingField() string
- func (f *Relation) IsMany() bool
- func (r *Relation) LocalField() string
- func (r *Relation) Model() *ModelInfo
- func (r *Relation) RelatedModel() *ModelInfo
- func (r *Relation) RelationType() string
- func (r *Relation) SetAutoCreate(val bool)
- func (r *Relation) SetAutoDelete(val bool)
- func (r *Relation) SetAutoUpdate(val bool)
- func (r *Relation) SetForeignField(val string)
- func (r *Relation) SetInversingField(val string)
- func (r *Relation) SetLocalField(val string)
- func (r *Relation) SetModel(val *ModelInfo)
- func (r *Relation) SetRelatedModel(val *ModelInfo)
- func (r *Relation) SetRelationType(val string)
- type RelationQuery
- func (q *RelationQuery) And(field string, val interface{}) *RelationQuery
- func (q *RelationQuery) AndCond(field, condition string, val interface{}) *RelationQuery
- func (q *RelationQuery) AndExpr(filters ...Expression) *RelationQuery
- func (q *RelationQuery) Build() (*Query, apperror.Error)
- func (q *RelationQuery) Count() (int, apperror.Error)
- func (q *RelationQuery) Delete() apperror.Error
- func (q *RelationQuery) Field(fields ...string) *RelationQuery
- func (q *RelationQuery) FieldExpr(exprs ...Expression) *RelationQuery
- func (q *RelationQuery) Filter(field string, val interface{}) *RelationQuery
- func (q *RelationQuery) FilterCond(field string, condition string, val interface{}) *RelationQuery
- func (q *RelationQuery) FilterExpr(expressions ...Expression) *RelationQuery
- func (q *RelationQuery) Find(targetSlice ...interface{}) ([]interface{}, apperror.Error)
- func (q *RelationQuery) First(targetModel ...interface{}) (interface{}, apperror.Error)
- func (q *RelationQuery) GetBaseQuery() *Query
- func (q *RelationQuery) GetJoinType() string
- func (q *RelationQuery) GetRelationName() string
- func (q *RelationQuery) GetStatement() *JoinStmt
- func (q *RelationQuery) Join(fieldName string, joinType ...string) *RelationQuery
- func (q *RelationQuery) JoinQ(jqs ...*RelationQuery) *RelationQuery
- func (q *RelationQuery) Last(targetModel ...interface{}) (interface{}, apperror.Error)
- func (q *RelationQuery) Limit(l int) *RelationQuery
- func (q *RelationQuery) Not(field string, val interface{}) *RelationQuery
- func (q *RelationQuery) NotCond(field string, condition string, val interface{}) *RelationQuery
- func (q *RelationQuery) NotExpr(filters ...Expression) *RelationQuery
- func (q *RelationQuery) Offset(o int) *RelationQuery
- func (q *RelationQuery) Or(field string, val interface{}) *RelationQuery
- func (q *RelationQuery) OrCond(field string, condition string, val interface{}) *RelationQuery
- func (q *RelationQuery) OrExpr(filters ...Expression) *RelationQuery
- func (q *RelationQuery) SetBaseQuery(bq *Query)
- func (q *RelationQuery) SetFieldExpressions(expressions []Expression) *RelationQuery
- func (q *RelationQuery) SetFields(fields []string) *RelationQuery
- func (q *RelationQuery) SetFilters(expressions ...Expression) *RelationQuery
- func (q *RelationQuery) SetJoinType(typ string) *RelationQuery
- func (q *RelationQuery) SetRelationName(name string)
- func (q *RelationQuery) SetSorts(exprs []*SortExpr) *RelationQuery
- func (q *RelationQuery) Sort(name string, asc bool) *RelationQuery
- func (q *RelationQuery) SortExpr(expr *SortExpr) *RelationQuery
- type StrIdModel
- type TimeStampedModel
- type Transaction
- type TransactionBackend
Constants ¶
const ( RELATION_TYPE_HAS_ONE = "has_one" RELATION_TYPE_HAS_MANY = "has_many" RELATION_TYPE_BELONGS_TO = "belongs_to" RELATION_TYPE_M2M = "m2m" )
const ( HOOK_BEFORE_CREATE = "before_create" HOOK_AFTER_CREATE = "after_create" HOOK_BEFORE_UPDATE = "before_update" HOOK_AFTER_UPDATE = "after_update" HOOK_BEFORE_DELETE = "before_delete" HOOK_AFTER_DELETE = "after_delete" )
Variables ¶
Functions ¶
func CallModelHook ¶
func GetModelCollection ¶
func GetModelCollection(model interface{}) (string, apperror.Error)
func MustGetModelCollection ¶
func MustGetModelCollection(model interface{}) string
func PickRandom ¶
func PickRandom(slice interface{}) interface{}
func PickRandomSubSlice ¶
func PickRandomSubSlice(slice interface{}, count int) interface{}
func RandomBool ¶
func RandomBool() bool
func SetPointer ¶
func SetPointer(ptr, val interface{})
Set a pointer to a value with reflect. If the value is a pointer to a type, and the the pointer target is not, the value is automatically dereferenced.
func SetSlicePointer ¶
func SetSlicePointer(ptr interface{}, values []interface{})
func StrAfterFirst ¶
func StrAfterLast ¶
func StrBeforeFirst ¶
func StrBeforeLast ¶
func StubTextRandom ¶
Types ¶
type Attribute ¶
type Attribute struct { // Embed field. Field // contains filtered or unexported fields }
func BuildAttribute ¶
buildAttribute builds up an attribute based on a field.
func (*Attribute) AutoIncrement ¶
func (*Attribute) BackendEmbed ¶
func (*Attribute) BackendMarshal ¶
func (*Attribute) BackendType ¶
func (*Attribute) BuildFieldExpression ¶
func (a *Attribute) BuildFieldExpression() *FieldExpr
func (*Attribute) DefaultValue ¶
func (a *Attribute) DefaultValue() interface{}
func (*Attribute) IgnoreIfZero ¶
func (*Attribute) IsPrimaryKey ¶
func (*Attribute) IsUniqueWith ¶
func (*Attribute) SetAutoIncrement ¶
func (*Attribute) SetBackendEmbed ¶
func (*Attribute) SetBackendMarshal ¶
func (*Attribute) SetBackendType ¶
func (*Attribute) SetDefaultValue ¶
func (a *Attribute) SetDefaultValue(val interface{})
func (*Attribute) SetIgnoreIfZero ¶
func (*Attribute) SetIndexName ¶
func (*Attribute) SetIsIndex ¶
func (*Attribute) SetIsPrimaryKey ¶
func (*Attribute) SetIsUnique ¶
func (*Attribute) SetIsUniqueWith ¶
type Backend ¶
type Backend interface { // Returns the name of the backend. Name() string SetName(name string) // Returns true if the backend uses string Ids like MongoDB. HasStringIds() bool HasNativeJoins() bool // Debug returns true if debugging is enabled. Debug() bool // SetDebug enables or disables the debug mode. // In debug mode, all queries will be logged, and some methods will panic // instead of returning an error. SetDebug(bool) Logger() *logrus.Logger SetLogger(*logrus.Logger) ProfilingEnabled() bool EnableProfiling() DisableProfiling() // Duplicate the backend. Clone() Backend // RegisterHook registers a hook function that will be called for a model. // The available hooks are: (before/after)_(create/update/delete). RegisterHook(hook string, handler HookHandler) // GetHooks returns a slice with all hooks of the hook type. GetHooks(hook string) []HookHandler // Get model info for all registered collections. ModelInfos() ModelInfos // Get the model info for a collection. // Returns nil if not found. ModelInfo(collection string) *ModelInfo // Retrieve the ModelInfo for a model instance. InfoForModel(model interface{}) (*ModelInfo, apperror.Error) // Determine if a collection is registered with the backend. HasCollection(collection string) bool // RegisterModel registers a model type witht the backend. // // The first argument must be a pointer to an instance of the model, // for example: &MyModel{} RegisterModel(model interface{}) *ModelInfo // Build analyzes the relationships between models and does all neccessary // preparations for using the backend. // // Build MUST be called AFTER all models have been registered with // backend.RegisterModel() and BEFORE the backend is used. Build() // NewModel creates a new model instance of the specified collection. NewModel(collection string) (interface{}, apperror.Error) // Build a slice of a model for model Collection. NewModelSlice(collection string) (interface{}, apperror.Error) // ModelToMap converts a model to a map. ModelToMap(model interface{}, marshal bool, includeRelations bool) (map[string]interface{}, apperror.Error) // Exec executes an expression. // The result will be nil for all statements except a SelectStatement. Exec(statement Expression) apperror.Error ExecQuery(statement FieldedExpression) (result []interface{}, err apperror.Error) // Create the specified collection in the backend. // (eg the table or the mongo collection) CreateCollection(collection ...string) apperror.Error // RenameCollection renames a collection to a new name. RenameCollection(collection, newName string) apperror.Error DropCollection(collection string, ifExists, cascade bool) apperror.Error DropAllCollections() apperror.Error // CreateField creates the specified field on a collection. // Note that the field must already be on the model struct, or an error // will be returned. // // If you need to create arbitrary fields that are not on your model, // use Exec() with a CreateFieldStatement. CreateField(collection, field string) apperror.Error // RenameField renames a collection field. // The model must already have the new name, or an error will be returned. RenameField(collection, field, newName string) apperror.Error // DropField drops a field from a collection. // The field must be the backend name. DropField(collection, field string) apperror.Error // Create an index for fields on a collection. // If you need more complex indexes, use Exec() with a CreateIndexStatement. CreateIndex(collection, indexName string, unique bool, fields ...string) apperror.Error // Drop an index. DropIndex(indexName string) apperror.Error NewQuery(collection string) (*Query, apperror.Error) NewModelQuery(model interface{}) (*Query, apperror.Error) // Create a new query. // // Can be used with different signatures: // backend.Q("collection_name") => Get a query for a collection. // backend.Q("collection_name", Id) => Get a query for a model in a collection. Id must be numeric or string. // backend.Q(&myModel) => Get a query for a model. Q(collectionOrModel interface{}, extraModels ...interface{}) *Query // Executes a query, fetches ALL results and returns them. // If you expect a large number of results, you should use QueryCursor(), which // returns an iterable cursor. Query(q *Query, targetSlice ...interface{}) ([]interface{}, apperror.Error) // Executes a query, and returns a cursor. QueryCursor(q *Query) (Cursor, apperror.Error) // Perform a query and get the first result. QueryOne(q *Query, targetModel ...interface{}) (interface{}, apperror.Error) // Perform a query and get the last result. Last(q *Query, targetModel ...interface{}) (interface{}, apperror.Error) // Find first model with primary key Id. FindBy(collection, field string, value interface{}, targetSlice ...interface{}) ([]interface{}, apperror.Error) // Find a model in a collection by Id. FindOne(collection string, id interface{}, targetModel ...interface{}) (interface{}, apperror.Error) // Find a model in a collection based on a field value. FindOneBy(collection, field string, value interface{}, targetModel ...interface{}) (interface{}, apperror.Error) // Retrieve the count for a query. Count(*Query) (int, apperror.Error) // Pluck retrieves all fields specified on a query, and returns them as a // map. Pluck(q *Query) ([]map[string]interface{}, apperror.Error) // Based on a RelationQuery, return a query for the specified // relation. BuildRelationQuery(q *RelationQuery) (*Query, apperror.Error) // Retrieve a query for a relationship. Related(model interface{}, name string) (*RelationQuery, apperror.Error) // Return a M2MCollection instance for a model, which allows // to add/remove/clear items in the m2m relationship. M2M(model interface{}, name string) (M2MCollection, apperror.Error) // Create creates the model in the backend. Create(model ...interface{}) apperror.Error CreateByMap(collection string, data map[string]interface{}) (result interface{}, err apperror.Error) // Update a model. Update(model interface{}) apperror.Error // Save is a convenience method that created the passed model if it // is new, or updates it otherwise. Save(model interface{}) apperror.Error // Updat all models matching a query by values in a map. UpdateByMap(query *Query, data map[string]interface{}) apperror.Error // Delete deletes the model from the backend. Delete(model interface{}) apperror.Error // DeleteQ deletes all models that match the passed query. DeleteMany(*Query) apperror.Error }
type BaseBackend ¶
type BaseBackend struct {
// contains filtered or unexported fields
}
func NewBaseBackend ¶
func NewBaseBackend(backend Backend) BaseBackend
func (*BaseBackend) Build ¶
func (b *BaseBackend) Build()
func (*BaseBackend) BuildJoins ¶
func (b *BaseBackend) BuildJoins(info *ModelInfo, q *Query) apperror.Error
func (*BaseBackend) BuildLogger ¶
func (b *BaseBackend) BuildLogger()
func (*BaseBackend) BuildRelationQuery ¶
func (b *BaseBackend) BuildRelationQuery(q *RelationQuery) (*Query, apperror.Error)
func (*BaseBackend) Clone ¶
func (b *BaseBackend) Clone() *BaseBackend
func (*BaseBackend) Count ¶
func (b *BaseBackend) Count(q *Query) (int, apperror.Error)
func (*BaseBackend) Create ¶
func (b *BaseBackend) Create(models ...interface{}) apperror.Error
func (*BaseBackend) CreateByMap ¶
func (b *BaseBackend) CreateByMap(collection string, data map[string]interface{}) (interface{}, apperror.Error)
func (*BaseBackend) CreateCollection ¶
func (b *BaseBackend) CreateCollection(collections ...string) apperror.Error
func (*BaseBackend) CreateField ¶
func (b *BaseBackend) CreateField(collection, fieldName string) apperror.Error
func (*BaseBackend) CreateIndex ¶
func (b *BaseBackend) CreateIndex(collection, indexName string, unique bool, fields ...string) apperror.Error
func (*BaseBackend) Debug ¶
func (b *BaseBackend) Debug() bool
func (*BaseBackend) Delete ¶
func (b *BaseBackend) Delete(model interface{}) apperror.Error
func (*BaseBackend) DeleteMany ¶
func (b *BaseBackend) DeleteMany(query *Query) apperror.Error
func (*BaseBackend) DisableProfiling ¶
func (b *BaseBackend) DisableProfiling()
func (*BaseBackend) DoJoin ¶
func (b *BaseBackend) DoJoin(baseInfo *ModelInfo, objs []interface{}, joinQ *RelationQuery) apperror.Error
func (*BaseBackend) DoJoins ¶
func (b *BaseBackend) DoJoins(baseInfo *ModelInfo, q *Query, models []interface{}) apperror.Error
func (*BaseBackend) DropAllCollections ¶
func (b *BaseBackend) DropAllCollections() apperror.Error
func (*BaseBackend) DropCollection ¶
func (b *BaseBackend) DropCollection(collection string, ifExists, cascade bool) apperror.Error
func (*BaseBackend) DropField ¶
func (b *BaseBackend) DropField(collection, field string) apperror.Error
func (*BaseBackend) DropIndex ¶
func (b *BaseBackend) DropIndex(indexName string) apperror.Error
func (*BaseBackend) EnableProfiling ¶
func (b *BaseBackend) EnableProfiling()
func (*BaseBackend) FindBy ¶
func (b *BaseBackend) FindBy(collection, field string, value interface{}, targetSlice ...interface{}) ([]interface{}, apperror.Error)
func (*BaseBackend) FindOne ¶
func (b *BaseBackend) FindOne(collection string, id interface{}, targetModel ...interface{}) (interface{}, apperror.Error)
func (*BaseBackend) FindOneBy ¶
func (b *BaseBackend) FindOneBy(collection, field string, value interface{}, targetModel ...interface{}) (interface{}, apperror.Error)
func (*BaseBackend) GetHooks ¶
func (b *BaseBackend) GetHooks(hook string) []HookHandler
func (*BaseBackend) HasCollection ¶
func (b *BaseBackend) HasCollection(collection string) bool
func (*BaseBackend) HasNativeJoins ¶
func (b *BaseBackend) HasNativeJoins() bool
func (*BaseBackend) InfoForModel ¶
func (b *BaseBackend) InfoForModel(model interface{}) (*ModelInfo, apperror.Error)
func (*BaseBackend) Last ¶
func (b *BaseBackend) Last(q *Query, targetModels ...interface{}) (interface{}, apperror.Error)
func (*BaseBackend) Logger ¶
func (b *BaseBackend) Logger() *logrus.Logger
func (*BaseBackend) M2M ¶
func (b *BaseBackend) M2M(model interface{}, name string) (M2MCollection, apperror.Error)
func (*BaseBackend) ModelInfo ¶
func (b *BaseBackend) ModelInfo(collection string) *ModelInfo
func (*BaseBackend) ModelInfos ¶
func (b *BaseBackend) ModelInfos() ModelInfos
func (*BaseBackend) ModelToMap ¶
func (b *BaseBackend) ModelToMap(model interface{}, marshal bool, includeRelations bool) (map[string]interface{}, apperror.Error)
func (*BaseBackend) Name ¶
func (b *BaseBackend) Name() string
func (*BaseBackend) NewModel ¶
func (b *BaseBackend) NewModel(collection string) (interface{}, apperror.Error)
func (*BaseBackend) NewModelQuery ¶
func (b *BaseBackend) NewModelQuery(model interface{}) (*Query, apperror.Error)
func (*BaseBackend) NewModelSlice ¶
func (b *BaseBackend) NewModelSlice(collection string) (interface{}, apperror.Error)
func (*BaseBackend) NewQuery ¶
func (b *BaseBackend) NewQuery(collection string) (*Query, apperror.Error)
func (*BaseBackend) PersistRelations ¶
func (b *BaseBackend) PersistRelations(action string, beforePersist bool, info *ModelInfo, model interface{}) apperror.Error
action may be either "create", "update" or "delete"
func (*BaseBackend) Pluck ¶
func (b *BaseBackend) Pluck(q *Query) ([]map[string]interface{}, apperror.Error)
func (*BaseBackend) ProfilingEnabled ¶
func (b *BaseBackend) ProfilingEnabled() bool
func (*BaseBackend) Q ¶
func (b *BaseBackend) Q(arg interface{}, args ...interface{}) *Query
func (*BaseBackend) Query ¶
func (b *BaseBackend) Query(q *Query, targetSlice ...interface{}) ([]interface{}, apperror.Error)
func (*BaseBackend) QueryCursor ¶
func (b *BaseBackend) QueryCursor(q *Query) (Cursor, apperror.Error)
func (*BaseBackend) QueryOne ¶
func (b *BaseBackend) QueryOne(q *Query, targetModels ...interface{}) (interface{}, apperror.Error)
func (*BaseBackend) RegisterHook ¶
func (b *BaseBackend) RegisterHook(hook string, handler HookHandler)
func (*BaseBackend) RegisterModel ¶
func (b *BaseBackend) RegisterModel(model interface{}) *ModelInfo
func (*BaseBackend) Related ¶
func (b *BaseBackend) Related(model interface{}, name string) (*RelationQuery, apperror.Error)
func (*BaseBackend) RenameCollection ¶
func (b *BaseBackend) RenameCollection(collection, newName string) apperror.Error
func (*BaseBackend) RenameField ¶
func (b *BaseBackend) RenameField(collection, field, newName string) apperror.Error
func (*BaseBackend) Save ¶
func (b *BaseBackend) Save(model interface{}) apperror.Error
func (*BaseBackend) SetDebug ¶
func (b *BaseBackend) SetDebug(x bool)
func (*BaseBackend) SetLogger ¶
func (b *BaseBackend) SetLogger(x *logrus.Logger)
func (*BaseBackend) SetName ¶
func (b *BaseBackend) SetName(name string)
func (*BaseBackend) Update ¶
func (b *BaseBackend) Update(model interface{}) apperror.Error
func (*BaseBackend) UpdateByMap ¶
func (b *BaseBackend) UpdateByMap(query *Query, data map[string]interface{}) apperror.Error
type BaseMigrationAttempt ¶
type BaseMigrationAttempt struct { Version int StartedAt time.Time FinishedAt time.Time Complete bool }
func (BaseMigrationAttempt) Collection ¶
func (m BaseMigrationAttempt) Collection() string
func (*BaseMigrationAttempt) GetComplete ¶
func (a *BaseMigrationAttempt) GetComplete() bool
func (*BaseMigrationAttempt) GetFinishedAt ¶
func (a *BaseMigrationAttempt) GetFinishedAt() time.Time
func (*BaseMigrationAttempt) GetStartedAt ¶
func (a *BaseMigrationAttempt) GetStartedAt() time.Time
func (*BaseMigrationAttempt) GetVersion ¶
func (a *BaseMigrationAttempt) GetVersion() int
func (*BaseMigrationAttempt) SetComplete ¶
func (a *BaseMigrationAttempt) SetComplete(x bool)
func (*BaseMigrationAttempt) SetFinishedAt ¶
func (a *BaseMigrationAttempt) SetFinishedAt(x time.Time)
func (*BaseMigrationAttempt) SetStartedAt ¶
func (a *BaseMigrationAttempt) SetStartedAt(x time.Time)
func (*BaseMigrationAttempt) SetVersion ¶
func (a *BaseMigrationAttempt) SetVersion(x int)
type BaseMigrationAttemptIntId ¶
type BaseMigrationAttemptIntId struct { BaseMigrationAttempt Id uint64 }
func (*BaseMigrationAttemptIntId) GetId ¶
func (a *BaseMigrationAttemptIntId) GetId() string
func (*BaseMigrationAttemptIntId) SetId ¶
func (a *BaseMigrationAttemptIntId) SetId(x string) error
type Cursor ¶
type Cursor interface { // Count returns the total number of items. Count() int // HasNext returns true if a next item exists. HasNext() bool // Retrieve the next result item. // // As with other query methods, you may pass a pointer to the model // that should be filled with the data. Next(targetModel ...interface{}) (interface{}, apperror.Error) }
type DefaultM2MCollection ¶
type DefaultM2MCollection struct {
// contains filtered or unexported fields
}
func (*DefaultM2MCollection) Add ¶
func (c *DefaultM2MCollection) Add(models ...interface{}) apperror.Error
func (*DefaultM2MCollection) All ¶
func (c *DefaultM2MCollection) All() ([]interface{}, apperror.Error)
func (*DefaultM2MCollection) Clear ¶
func (c *DefaultM2MCollection) Clear() apperror.Error
func (*DefaultM2MCollection) Contains ¶
func (c *DefaultM2MCollection) Contains(model interface{}) (bool, apperror.Error)
func (*DefaultM2MCollection) ContainsId ¶
func (c *DefaultM2MCollection) ContainsId(id interface{}) (bool, apperror.Error)
func (*DefaultM2MCollection) Count ¶
func (c *DefaultM2MCollection) Count() (int, apperror.Error)
func (*DefaultM2MCollection) Q ¶
func (c *DefaultM2MCollection) Q() *Query
func (*DefaultM2MCollection) Remove ¶
func (c *DefaultM2MCollection) Remove(models ...interface{}) apperror.Error
func (*DefaultM2MCollection) Replace ¶
func (c *DefaultM2MCollection) Replace(models ...interface{}) apperror.Error
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
func (*Field) BackendName ¶
func (*Field) EmbeddingStructName ¶
func (*Field) IsRequired ¶
func (*Field) MarshalName ¶
func (*Field) SetBackendName ¶
func (*Field) SetEmbeddingStructName ¶
func (*Field) SetIsRequired ¶
func (*Field) SetMarshalName ¶
func (*Field) SetStructName ¶
func (*Field) SetStructType ¶
func (*Field) StructName ¶
func (*Field) StructType ¶
type HookHandler ¶
type HookHandler func(backend Backend, obj interface{}) apperror.Error
type IntIdModel ¶
type IntIdModel struct {
Id uint64
}
Base model with a integer Id.
func (*IntIdModel) GetId ¶
func (m *IntIdModel) GetId() interface{}
func (*IntIdModel) GetStrId ¶
func (m *IntIdModel) GetStrId() string
func (*IntIdModel) SetId ¶
func (m *IntIdModel) SetId(id interface{}) error
func (*IntIdModel) SetStrId ¶
func (m *IntIdModel) SetStrId(rawId string) error
type JoinAssigner ¶
type JoinAssigner func(relation *Relation, joinQ *RelationQuery, resultQuery *Query, objs, joinedModels []interface{})
type M2MCollection ¶
type M2MCollection interface { Add(models ...interface{}) apperror.Error Remove(models ...interface{}) apperror.Error Clear() apperror.Error Replace(models ...interface{}) apperror.Error Count() (int, apperror.Error) Contains(model interface{}) (bool, apperror.Error) ContainsId(id interface{}) (bool, apperror.Error) All() ([]interface{}, apperror.Error) Q() *Query }
func NewM2MCollection ¶
func NewM2MCollection(backend Backend, relation *Relation, model interface{}) (M2MCollection, apperror.Error)
type Migration ¶
type Migration struct { Version int Name string Description string SkipOnNew bool // Determines if this migration can be skipped if setting up a new database. // WrapTransaction specifies if the whole migration should be wrapped in a transaction. WrapTransaction bool Up func(MigrationBackend) error Down func(MigrationBackend) error }
type MigrationAttempt ¶
type MigrationBackend ¶
type MigrationBackend interface { Backend GetMigrationHandler() *MigrationHandler MigrationsSetup() apperror.Error IsMigrationLocked() (bool, apperror.Error) DetermineMigrationVersion() (int, apperror.Error) NewMigrationAttempt() MigrationAttempt }
type MigrationHandler ¶
type MigrationHandler struct { Backend MigrationBackend // contains filtered or unexported fields }
func NewMigrationHandler ¶
func NewMigrationHandler(backend Backend) *MigrationHandler
func (*MigrationHandler) Add ¶
func (m *MigrationHandler) Add(migrations ...Migration)
func (*MigrationHandler) Get ¶
func (m *MigrationHandler) Get(version int) *Migration
func (*MigrationHandler) HasMigration ¶
func (m *MigrationHandler) HasMigration(version int) bool
func (*MigrationHandler) Migrate ¶
func (m *MigrationHandler) Migrate(force bool) apperror.Error
func (*MigrationHandler) MigrateTo ¶
func (m *MigrationHandler) MigrateTo(targetVersion int, force bool) apperror.Error
func (*MigrationHandler) RunMigration ¶
func (handler *MigrationHandler) RunMigration(m *Migration) apperror.Error
type ModelAfterCreateHook ¶
type ModelAfterCreateHook interface {
AfterCreate(Backend)
}
type ModelAfterDeleteHook ¶
type ModelAfterDeleteHook interface {
AfterDelete(Backend)
}
type ModelAfterQueryHook ¶
type ModelAfterQueryHook interface {
AfterQuery(Backend)
}
type ModelAfterUpdateHook ¶
type ModelAfterUpdateHook interface {
AfterUpdate(Backend)
}
type ModelBackendNameHook ¶
type ModelBackendNameHook interface {
BackendName() string
}
type ModelBeforeCreateHook ¶
type ModelBeforeDeleteHook ¶
type ModelBeforeUpdateHook ¶
type ModelCollectionHook ¶
type ModelCollectionHook interface {
Collection() string
}
type ModelIdGetterHook ¶
type ModelIdGetterHook interface {
GetId() interface{}
}
type ModelIdSetterHook ¶
type ModelIdSetterHook interface {
SetId(id interface{}) error
}
type ModelInfo ¶
type ModelInfo struct {
// contains filtered or unexported fields
}
func BuildModelInfo ¶
func BuildModelInfo(model interface{}) (*ModelInfo, apperror.Error)
Builds the ModelInfo for a model and returns it.
func (*ModelInfo) AddAttribute ¶
func (*ModelInfo) AddRelation ¶
func (*ModelInfo) Attributes ¶
func (*ModelInfo) BackendName ¶
func (*ModelInfo) BuildCreateStmt ¶
func (*ModelInfo) Collection ¶
func (*ModelInfo) DetermineModelId ¶
func (info *ModelInfo) DetermineModelId(model interface{}) (interface{}, apperror.Error)
func (*ModelInfo) DetermineModelStrId ¶
Determine the Id for a model and convert it to string.
func (*ModelInfo) FindAttribute ¶
FindField tries to find a field by checking its Name, BackendName and MarshalName.
func (*ModelInfo) FindRelation ¶
func (*ModelInfo) FullStructName ¶
func (*ModelInfo) HasAttribute ¶
func (*ModelInfo) HasRelation ¶
func (*ModelInfo) MarshalName ¶
func (*ModelInfo) ModelDeleteStmt ¶
func (info *ModelInfo) ModelDeleteStmt(model interface{}) *DeleteStmt
func (*ModelInfo) ModelFilter ¶
func (info *ModelInfo) ModelFilter(model interface{}) Expression
func (*ModelInfo) ModelFromMap ¶
ModelFromMap creates a new model, fills it with data from the map, and returns a pointer to the new model struct. Data may contain the struct field names, the backend names or the marshal names as keys.
func (*ModelInfo) ModelHasId ¶
func (*ModelInfo) ModelSelect ¶
func (info *ModelInfo) ModelSelect(model interface{}) *SelectStmt
func (*ModelInfo) ModelToFieldExpressions ¶
func (info *ModelInfo) ModelToFieldExpressions(model interface{}) ([]*FieldValueExpr, apperror.Error)
func (*ModelInfo) ModelToMap ¶
func (*ModelInfo) MustDetermineModelId ¶
func (info *ModelInfo) MustDetermineModelId(model interface{}) interface{}
func (*ModelInfo) MustDetermineModelStrId ¶
Determine the Id for a model and convert it to string. Panics on error.
func (*ModelInfo) NewReflector ¶
func (m *ModelInfo) NewReflector() *reflector.StructReflector
func (*ModelInfo) PkAttribute ¶
func (*ModelInfo) SetAttributes ¶
func (*ModelInfo) SetBackendName ¶
func (*ModelInfo) SetCollection ¶
func (*ModelInfo) SetFullStructName ¶
func (*ModelInfo) SetMarshalName ¶
func (*ModelInfo) SetModelId ¶
func (info *ModelInfo) SetModelId(model, id interface{}) apperror.Error
func (*ModelInfo) SetRelations ¶
func (*ModelInfo) SetStructName ¶
func (*ModelInfo) SetTransientFields ¶
func (*ModelInfo) StructName ¶
func (*ModelInfo) TransientFields ¶
func (*ModelInfo) UpdateModelFromData ¶
func (*ModelInfo) ValidateModel ¶
func (info *ModelInfo) ValidateModel(m interface{}) apperror.Error
type ModelInfos ¶
func (ModelInfos) Add ¶
func (i ModelInfos) Add(info *ModelInfo)
func (ModelInfos) AnalyzeRelations ¶
func (m ModelInfos) AnalyzeRelations() apperror.Error
func (ModelInfos) Find ¶
func (i ModelInfos) Find(name string) *ModelInfo
func (ModelInfos) Get ¶
func (i ModelInfos) Get(collection string) *ModelInfo
func (ModelInfos) Has ¶
func (i ModelInfos) Has(collection string) bool
type ModelMarshalNameHook ¶
type ModelMarshalNameHook interface {
MarshalName() string
}
type ModelStrIdGetterHook ¶
type ModelStrIdGetterHook interface {
GetStrId() string
}
type ModelStrIdSetterHook ¶
type ModelValidateHook ¶
type ModelValidateHook interface {
Validate() error
}
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
func ParseJsonQuery ¶
func ParseQuery ¶
Build a database query based a map[string]interface{} data structure resembling a Mongo query.
It returns a Query equal to the Mongo query, with unsupported features omitted. An error is returned if the building of the query fails.
Format: { // Order by field: order: "field", // Order descending: order: "-field", // Joins: joins: ["myJoin", "my.nestedJoin"], // Filters: Filters conform to the mongo query syntax. See http://docs.mongodb.org/manual/reference/operator/query/. filters: { id: "22", weight: {$gt: 222}, type: {$in: ["type1", "type2"]} }, // Limiting: limit: 100, // Offset: offset: 20 }
func (*Query) FilterCond ¶
func (*Query) FilterExpr ¶
func (*Query) Find ¶
func (q *Query) Find(targetSlice ...interface{}) ([]interface{}, apperror.Error)
func (*Query) First ¶
func (q *Query) First(targetModel ...interface{}) (interface{}, apperror.Error)
func (*Query) GetBackend ¶
func (*Query) GetCollection ¶
func (*Query) GetJoin ¶
func (q *Query) GetJoin(relationName string) *RelationQuery
Retrieve a join query for the specified field. Returns a *RelationQuery, or nil if not found. Supports nested Joins like 'Parent.Tags'.
func (*Query) GetJoinResultAssigner ¶
func (q *Query) GetJoinResultAssigner() JoinAssigner
func (*Query) GetJoins ¶
func (q *Query) GetJoins() map[string]*RelationQuery
func (*Query) GetStatement ¶
func (q *Query) GetStatement() *SelectStmt
func (*Query) JoinQ ¶
func (q *Query) JoinQ(jqs ...*RelationQuery) *Query
func (*Query) Related ¶
func (q *Query) Related(name string) *RelationQuery
func (*Query) SetBackend ¶
func (*Query) SetCollection ¶
func (*Query) SetFieldExpressions ¶
func (*Query) SetFilters ¶
func (*Query) SetJoinResultAssigner ¶
func (q *Query) SetJoinResultAssigner(x JoinAssigner)
func (*Query) SetStatement ¶
func (q *Query) SetStatement(stmt *SelectStmt)
type Relation ¶
type Relation struct { // Embed field. Field // contains filtered or unexported fields }
func BuildRelation ¶
buildRelation builds up a relation based on a field.
func (*Relation) AutoCreate ¶
func (*Relation) AutoDelete ¶
func (*Relation) AutoUpdate ¶
func (*Relation) ForeignField ¶
func (*Relation) InversingField ¶
func (*Relation) LocalField ¶
func (*Relation) RelatedModel ¶
func (*Relation) RelationType ¶
func (*Relation) SetAutoCreate ¶
func (*Relation) SetAutoDelete ¶
func (*Relation) SetAutoUpdate ¶
func (*Relation) SetForeignField ¶
func (*Relation) SetInversingField ¶
func (*Relation) SetLocalField ¶
func (*Relation) SetRelatedModel ¶
func (*Relation) SetRelationType ¶
type RelationQuery ¶
type RelationQuery struct { Query // contains filtered or unexported fields }
func RelQ ¶
func RelQ(q *Query, relationName string, collection string, joinType string) *RelationQuery
func RelQCustom ¶
func RelQCustom(q *Query, collection, joinKey, foreignKey, typ string) *RelationQuery
Create a new relation query that connects two collections via two of their fields. These will normally be the respective primary keys.
func RelQExpr ¶
func RelQExpr(q *Query, collection, typ string, joinCondition Expression) *RelationQuery
RelQExpr creates a new relation query for a collection with an arbitrary join condition.
func (*RelationQuery) And ¶
func (q *RelationQuery) And(field string, val interface{}) *RelationQuery
func (*RelationQuery) AndCond ¶
func (q *RelationQuery) AndCond(field, condition string, val interface{}) *RelationQuery
func (*RelationQuery) AndExpr ¶
func (q *RelationQuery) AndExpr(filters ...Expression) *RelationQuery
func (*RelationQuery) Build ¶
func (q *RelationQuery) Build() (*Query, apperror.Error)
func (*RelationQuery) Count ¶
func (q *RelationQuery) Count() (int, apperror.Error)
func (*RelationQuery) Delete ¶
func (q *RelationQuery) Delete() apperror.Error
func (*RelationQuery) Field ¶
func (q *RelationQuery) Field(fields ...string) *RelationQuery
func (*RelationQuery) FieldExpr ¶
func (q *RelationQuery) FieldExpr(exprs ...Expression) *RelationQuery
func (*RelationQuery) Filter ¶
func (q *RelationQuery) Filter(field string, val interface{}) *RelationQuery
func (*RelationQuery) FilterCond ¶
func (q *RelationQuery) FilterCond(field string, condition string, val interface{}) *RelationQuery
func (*RelationQuery) FilterExpr ¶
func (q *RelationQuery) FilterExpr(expressions ...Expression) *RelationQuery
func (*RelationQuery) Find ¶
func (q *RelationQuery) Find(targetSlice ...interface{}) ([]interface{}, apperror.Error)
func (*RelationQuery) First ¶
func (q *RelationQuery) First(targetModel ...interface{}) (interface{}, apperror.Error)
func (*RelationQuery) GetBaseQuery ¶
func (q *RelationQuery) GetBaseQuery() *Query
func (*RelationQuery) GetJoinType ¶
func (q *RelationQuery) GetJoinType() string
func (*RelationQuery) GetRelationName ¶
func (q *RelationQuery) GetRelationName() string
func (*RelationQuery) GetStatement ¶
func (q *RelationQuery) GetStatement() *JoinStmt
func (*RelationQuery) Join ¶
func (q *RelationQuery) Join(fieldName string, joinType ...string) *RelationQuery
func (*RelationQuery) JoinQ ¶
func (q *RelationQuery) JoinQ(jqs ...*RelationQuery) *RelationQuery
func (*RelationQuery) Last ¶
func (q *RelationQuery) Last(targetModel ...interface{}) (interface{}, apperror.Error)
func (*RelationQuery) Limit ¶
func (q *RelationQuery) Limit(l int) *RelationQuery
func (*RelationQuery) Not ¶
func (q *RelationQuery) Not(field string, val interface{}) *RelationQuery
func (*RelationQuery) NotCond ¶
func (q *RelationQuery) NotCond(field string, condition string, val interface{}) *RelationQuery
func (*RelationQuery) NotExpr ¶
func (q *RelationQuery) NotExpr(filters ...Expression) *RelationQuery
func (*RelationQuery) Offset ¶
func (q *RelationQuery) Offset(o int) *RelationQuery
func (*RelationQuery) Or ¶
func (q *RelationQuery) Or(field string, val interface{}) *RelationQuery
func (*RelationQuery) OrCond ¶
func (q *RelationQuery) OrCond(field string, condition string, val interface{}) *RelationQuery
func (*RelationQuery) OrExpr ¶
func (q *RelationQuery) OrExpr(filters ...Expression) *RelationQuery
func (*RelationQuery) SetBaseQuery ¶
func (q *RelationQuery) SetBaseQuery(bq *Query)
func (*RelationQuery) SetFieldExpressions ¶
func (q *RelationQuery) SetFieldExpressions(expressions []Expression) *RelationQuery
func (*RelationQuery) SetFields ¶
func (q *RelationQuery) SetFields(fields []string) *RelationQuery
func (*RelationQuery) SetFilters ¶
func (q *RelationQuery) SetFilters(expressions ...Expression) *RelationQuery
func (*RelationQuery) SetJoinType ¶
func (q *RelationQuery) SetJoinType(typ string) *RelationQuery
func (*RelationQuery) SetRelationName ¶
func (q *RelationQuery) SetRelationName(name string)
func (*RelationQuery) SetSorts ¶
func (q *RelationQuery) SetSorts(exprs []*SortExpr) *RelationQuery
func (*RelationQuery) Sort ¶
func (q *RelationQuery) Sort(name string, asc bool) *RelationQuery
func (*RelationQuery) SortExpr ¶
func (q *RelationQuery) SortExpr(expr *SortExpr) *RelationQuery
type StrIdModel ¶
type StrIdModel struct {
Id string
}
Base model with a string Id.
func (*StrIdModel) GetId ¶
func (m *StrIdModel) GetId() interface{}
func (*StrIdModel) GetStrId ¶
func (m *StrIdModel) GetStrId() string
func (*StrIdModel) SetId ¶
func (m *StrIdModel) SetId(id interface{}) error
func (*StrIdModel) SetStrId ¶
func (m *StrIdModel) SetStrId(rawId string) error
type TimeStampedModel ¶
type TimeStampedModel struct { CreatedAt time.Time `db:"required"` UpdatedAt time.Time `db:"required"` }
func (*TimeStampedModel) BeforeCreate ¶
func (m *TimeStampedModel) BeforeCreate(b Backend) error
func (*TimeStampedModel) BeforeUpdate ¶
func (m *TimeStampedModel) BeforeUpdate(b Backend) error
type Transaction ¶
type Transaction interface { Backend Rollback() apperror.Error Commit() apperror.Error }
type TransactionBackend ¶
type TransactionBackend interface { Backend Begin() (Transaction, apperror.Error) MustBegin() Transaction }