Documentation ¶
Index ¶
- Constants
- Variables
- func BootStrap()
- func BootStrapped() bool
- func ConvertLimitToInt(limit interface{}) int
- func CreateM2MRelModelInfo(relModelName, model1, model2, field1, field2 string, mixin bool) (*Model, *Field, *Field)
- func DBClose()
- func DBConnect(params ConnectionParams)
- func DefaultValue(value interface{}) func(env Environment) interface{}
- func ExecuteInNewEnvironment(uid int64, fnct func(Environment)) error
- func FreeTransientModels()
- func LoadCSVDataFile(fileName string)
- func RegisterModelDataWrapper(modelName string, obj interface{})
- func RegisterRecordSetWrapper(modelName string, obj interface{})
- func RegisterWorker(wf WorkerFunction)
- func RunWorkerLoop()
- func SimulateInNewEnvironment(uid int64, fnct func(Environment)) error
- func SnakeCaseFieldName(fName string, typ fieldtype.Type) string
- func StopWorkerLoop()
- func SyncDatabase()
- type ClientEvaluatedString
- type ColumnData
- type Condition
- func (c Condition) And() *ConditionStart
- func (c Condition) AndCond(cond *Condition) *Condition
- func (c Condition) AndNot() *ConditionStart
- func (c Condition) AndNotCond(cond *Condition) *Condition
- func (c Condition) HasField(f *Field) bool
- func (c *Condition) IsEmpty() bool
- func (c Condition) Or() *ConditionStart
- func (c Condition) OrCond(cond *Condition) *Condition
- func (c Condition) OrNot() *ConditionStart
- func (c Condition) OrNotCond(cond *Condition) *Condition
- func (c Condition) PredicatesWithField(f *Field) []*predicate
- func (c Condition) Serialize() []interface{}
- func (c Condition) String() string
- func (c Condition) Underlying() *Condition
- type ConditionField
- func (c ConditionField) AddOperator(op operator.Operator, data interface{}) *Condition
- func (c ConditionField) ChildOf(data interface{}) *Condition
- func (c ConditionField) Contains(data interface{}) *Condition
- func (c ConditionField) Equals(data interface{}) *Condition
- func (c ConditionField) Greater(data interface{}) *Condition
- func (c ConditionField) GreaterOrEqual(data interface{}) *Condition
- func (c ConditionField) IContains(data interface{}) *Condition
- func (c ConditionField) ILike(data interface{}) *Condition
- func (c ConditionField) In(data interface{}) *Condition
- func (c ConditionField) IsNotNull() *Condition
- func (c ConditionField) IsNull() *Condition
- func (c ConditionField) JSON() string
- func (c ConditionField) Like(data interface{}) *Condition
- func (c ConditionField) Lower(data interface{}) *Condition
- func (c ConditionField) LowerOrEqual(data interface{}) *Condition
- func (c ConditionField) Name() string
- func (c ConditionField) NotContains(data interface{}) *Condition
- func (c ConditionField) NotEquals(data interface{}) *Condition
- func (c ConditionField) NotIContains(data interface{}) *Condition
- func (c ConditionField) NotIn(data interface{}) *Condition
- type ConditionStart
- type Conditioner
- type ConnectionParams
- type Cursor
- type DummyField
- type Environment
- type Field
- func (f *Field) AddContexts(value FieldContexts) *Field
- func (f *Field) JSON() string
- func (f *Field) Name() string
- func (f *Field) SetCompute(value Methoder) *Field
- func (f *Field) SetConstraint(value Methoder) *Field
- func (f *Field) SetContexts(value FieldContexts) *Field
- func (f *Field) SetDefault(value func(Environment) interface{}) *Field
- func (f *Field) SetDepends(value []string) *Field
- func (f *Field) SetDigits(value nbutils.Digits) *Field
- func (f *Field) SetEmbed(value bool) *Field
- func (f *Field) SetFieldType(value fieldtype.Type) *Field
- func (f *Field) SetFilter(value Conditioner) *Field
- func (f *Field) SetGroupOperator(value string) *Field
- func (f *Field) SetHelp(value string) *Field
- func (f *Field) SetIndex(value bool) *Field
- func (f *Field) SetInverse(value Methoder) *Field
- func (f *Field) SetInvisibleFunc(value func(Environment) (bool, Conditioner)) *Field
- func (f *Field) SetM2MOurField(value *Field) *Field
- func (f *Field) SetM2MRelModel(value Modeler) *Field
- func (f *Field) SetM2MTheirField(value *Field) *Field
- func (f *Field) SetNoCopy(value bool) *Field
- func (f *Field) SetOnDelete(value OnDeleteAction) *Field
- func (f *Field) SetOnchange(value Methoder) *Field
- func (f *Field) SetOnchangeFilters(value Methoder) *Field
- func (f *Field) SetOnchangeWarning(value Methoder) *Field
- func (f *Field) SetProperty(property string, value interface{})
- func (f *Field) SetReadOnly(value bool) *Field
- func (f *Field) SetReadOnlyFunc(value func(Environment) (bool, Conditioner)) *Field
- func (f *Field) SetRelated(value string) *Field
- func (f *Field) SetRelationModel(value Modeler) *Field
- func (f *Field) SetRequired(value bool) *Field
- func (f *Field) SetRequiredFunc(value func(Environment) (bool, Conditioner)) *Field
- func (f *Field) SetReverseFK(value string) *Field
- func (f *Field) SetSelection(value types.Selection) *Field
- func (f *Field) SetSelectionFunc(value func() types.Selection) *Field
- func (f *Field) SetSize(value int) *Field
- func (f *Field) SetStored(value bool) *Field
- func (f *Field) SetString(value string) *Field
- func (f *Field) SetTranslate(value bool) *Field
- func (f *Field) SetUnique(value bool) *Field
- func (f *Field) UpdateSelection(value types.Selection) *Field
- type FieldContexts
- type FieldDefinition
- type FieldInfo
- type FieldMap
- func (fm FieldMap) Copy() FieldMap
- func (fm *FieldMap) Delete(field FieldName)
- func (fm FieldMap) FieldNames(model *Model) FieldNames
- func (fm FieldMap) Get(field FieldName) (interface{}, bool)
- func (fm FieldMap) Keys() (res []string)
- func (fm *FieldMap) MergeWith(other FieldMap, model *Model)
- func (fm FieldMap) MustGet(field FieldName) interface{}
- func (fm FieldMap) OrderedKeys() []string
- func (fm *FieldMap) RemovePK()
- func (fm *FieldMap) RemovePKIfZero()
- func (fm *FieldMap) Set(field FieldName, value interface{})
- func (fm FieldMap) Underlying() FieldMap
- func (fm FieldMap) Values() (res []interface{})
- type FieldMapper
- type FieldName
- type FieldNames
- type FieldsCollection
- type FieldsGetArgs
- type GroupAggregateRow
- type Method
- func (m *Method) AllowGroup(group *security.Group, callers ...Methoder) *Method
- func (m *Method) Call(rc *RecordCollection, params ...interface{}) interface{}
- func (m *Method) CallMulti(rc *RecordCollection, params ...interface{}) []interface{}
- func (m *Method) Extend(fnct interface{}) *Method
- func (m *Method) MethodType() reflect.Type
- func (m *Method) Name() string
- func (m *Method) RevokeGroup(group *security.Group) *Method
- func (m *Method) Underlying() *Method
- type Methoder
- type MethodsCollection
- type Model
- func (m *Model) AddEmptyMethod(methodName string) *Method
- func (m *Model) AddFields(fields map[string]FieldDefinition)
- func (m *Model) AddRecordRule(rule *RecordRule)
- func (m *Model) AddSQLConstraint(name, sql, errorString string)
- func (m *Model) Browse(env Environment, ids []int64) *RecordCollection
- func (m *Model) BrowseOne(env Environment, id int64) *RecordCollection
- func (m *Model) Create(env Environment, data interface{}) *RecordCollection
- func (m *Model) Field(name FieldName) *ConditionField
- func (m *Model) FieldName(name string) FieldName
- func (m *Model) FieldNames() FieldNames
- func (m *Model) Fields() *FieldsCollection
- func (m *Model) FieldsGet(fields ...FieldName) map[string]*FieldInfo
- func (m *Model) FilteredOn(field FieldName, condition *Condition) *Condition
- func (m *Model) InheritModel(mixInModel Modeler)
- func (m *Model) IsM2MLink() bool
- func (m *Model) IsManual() bool
- func (m *Model) IsMixin() bool
- func (m *Model) IsTransient() bool
- func (m *Model) JSONizeFieldName(fieldName string) string
- func (m *Model) Methods() *MethodsCollection
- func (m *Model) Name() string
- func (m *Model) NewMethod(methodName string, fnct interface{}) *Method
- func (m *Model) RemoveRecordRule(name string)
- func (m *Model) RemoveSQLConstraint(name string)
- func (m *Model) Search(env Environment, cond Conditioner) *RecordCollection
- func (m *Model) SetDefaultOrder(orders ...string)
- func (m *Model) TableName() string
- func (m *Model) Underlying() *Model
- type ModelData
- func (md *ModelData) Copy() *ModelData
- func (md *ModelData) Create(field FieldName, related *ModelData) *ModelData
- func (md *ModelData) FieldNames() FieldNames
- func (md *ModelData) Get(field FieldName) interface{}
- func (md *ModelData) Has(field FieldName) bool
- func (md *ModelData) MarshalJSON() ([]byte, error)
- func (md *ModelData) MergeWith(other *ModelData)
- func (md *ModelData) Scan(src interface{}) error
- func (md *ModelData) Set(field FieldName, value interface{}) *ModelData
- func (md *ModelData) Underlying() *ModelData
- func (md *ModelData) Unset(field FieldName) *ModelData
- func (md ModelData) Wrap() interface{}
- type Modeler
- type OnDeleteAction
- type OnchangeParams
- type OnchangeResult
- type Option
- type Query
- type RecordCollection
- func (rc *RecordCollection) Aggregates(fieldNames ...FieldName) []GroupAggregateRow
- func (rc *RecordCollection) All() []*ModelData
- func (rc *RecordCollection) Call(methName string, args ...interface{}) interface{}
- func (rc *RecordCollection) CallMulti(methName string, args ...interface{}) []interface{}
- func (rc *RecordCollection) CartesianProduct(records ...RecordSet) []*RecordCollection
- func (rc *RecordCollection) CheckConstraints(fields FieldNames)
- func (rc *RecordCollection) CheckExecutionPermission(method *Method, dontPanic ...bool) bool
- func (rc *RecordCollection) Collection() *RecordCollection
- func (rc *RecordCollection) Condition() *Condition
- func (rc *RecordCollection) EnsureOne()
- func (rc *RecordCollection) Env() Environment
- func (rc *RecordCollection) Equals(other RecordSet) bool
- func (rc *RecordCollection) Fetch() *RecordCollection
- func (rc *RecordCollection) Filtered(test func(rs RecordSet) bool) *RecordCollection
- func (rc *RecordCollection) First() *ModelData
- func (rc *RecordCollection) ForceLoad(fieldNames ...FieldName) *RecordCollection
- func (rc *RecordCollection) Get(fieldName FieldName) interface{}
- func (rc *RecordCollection) GetRecord(externalID string) *RecordCollection
- func (rc *RecordCollection) GroupBy(fields ...FieldName) *RecordCollection
- func (rc *RecordCollection) Ids() []int64
- func (rc *RecordCollection) Intersect(other RecordSet) *RecordCollection
- func (rc *RecordCollection) InvalidateCache()
- func (rc *RecordCollection) IsEmpty() bool
- func (rc *RecordCollection) IsNotEmpty() bool
- func (rc *RecordCollection) IsValid() bool
- func (rc *RecordCollection) Len() int
- func (rc *RecordCollection) Limit(limit int) *RecordCollection
- func (rc *RecordCollection) Load(fields ...FieldName) *RecordCollection
- func (rc *RecordCollection) MethodType(methName string) reflect.Type
- func (rc *RecordCollection) Model() *Model
- func (rc *RecordCollection) ModelName() string
- func (rc *RecordCollection) Offset(offset int) *RecordCollection
- func (rc *RecordCollection) OrderBy(exprs ...string) *RecordCollection
- func (rc *RecordCollection) Records() []*RecordCollection
- func (rc *RecordCollection) SQLFromCondition(c *Condition) (string, SQLParams)
- func (rc *RecordCollection) Scan(src interface{}) error
- func (rc *RecordCollection) Search(cond *Condition) *RecordCollection
- func (rc *RecordCollection) SearchAll() *RecordCollection
- func (rc *RecordCollection) SearchCount() int
- func (rc *RecordCollection) Set(fieldName FieldName, value interface{})
- func (rc *RecordCollection) Sorted(less func(rs1 RecordSet, rs2 RecordSet) bool) *RecordCollection
- func (rc *RecordCollection) SortedByField(name FieldName, reverse bool) *RecordCollection
- func (rc *RecordCollection) SortedDefault() *RecordCollection
- func (rc *RecordCollection) String() string
- func (rc *RecordCollection) Subtract(other RecordSet) *RecordCollection
- func (rc *RecordCollection) Sudo(userId ...int64) *RecordCollection
- func (rc *RecordCollection) Super() *RecordCollection
- func (rc *RecordCollection) T(src string, args ...interface{}) string
- func (rc *RecordCollection) Union(other RecordSet) *RecordCollection
- func (rc *RecordCollection) WithContext(key string, value interface{}) *RecordCollection
- func (rc *RecordCollection) WithEnv(env Environment) *RecordCollection
- func (rc *RecordCollection) WithNewContext(context *types.Context) *RecordCollection
- func (rc *RecordCollection) Wrap(modelName ...string) interface{}
- type RecordData
- type RecordRef
- type RecordRule
- type RecordSet
- type SQLParams
- type Sequence
- type WorkerFunction
Constants ¶
const ( ExprSep = "." ContextSep = "|" )
Expression separation symbols
const DBSerializationMaxRetries uint8 = 5
DBSerializationMaxRetries defines the number of time a transaction that failed due to serialization error should be retried.
Variables ¶
var ( // Testing is true if we are testing the framework Testing bool // ID is a FieldName that represents the PK of a model ID = fieldName{/* contains filtered or unexported fields */} // Name is a fieldName that represents the Name field of a model Name = fieldName{/* contains filtered or unexported fields */} )
var Registry *modelCollection
Registry is the registry of all Model instances.
var ( // Views is a map to store views created automatically. // It will be processed by the views package and added to the views registry. Views map[*Model][]string )
Functions ¶
func BootStrap ¶
func BootStrap()
BootStrap freezes model, fields and method caches and syncs the database structure with the declared data.
func BootStrapped ¶
func BootStrapped() bool
BootStrapped returns true if the models have been bootstrapped
func ConvertLimitToInt ¶
func ConvertLimitToInt(limit interface{}) int
ConvertLimitToInt converts the given limit as interface{} to an int
func CreateM2MRelModelInfo ¶
func CreateM2MRelModelInfo(relModelName, model1, model2, field1, field2 string, mixin bool) (*Model, *Field, *Field)
CreateM2MRelModelInfo creates a Model relModelName (if it does not exist) for the m2m relation defined between model1 and model2. It returns the Model of the intermediate model, the Field of that model pointing to our model, and the Field pointing to the other model.
If mixin is true, the created M2M model is created as a mixin model.
func DBClose ¶
func DBClose()
DBClose is a wrapper around sqlx.Close It closes the connection to the database
func DBConnect ¶
func DBConnect(params ConnectionParams)
DBConnect connects to a database using the given driver and arguments.
func DefaultValue ¶
func DefaultValue(value interface{}) func(env Environment) interface{}
DefaultValue returns a function that is suitable for the Default parameter of model fields and that simply returns value.
func ExecuteInNewEnvironment ¶
func ExecuteInNewEnvironment(uid int64, fnct func(Environment)) error
ExecuteInNewEnvironment executes the given fnct in a new Environment within a new transaction.
This function commits the transaction if everything went right or rolls it back otherwise, returning an arror. Database serialization errors are automatically retried several times before returning an error if they still occur.
func FreeTransientModels ¶
func FreeTransientModels()
FreeTransientModels remove transient models records from database which are older than the given timeout.
func LoadCSVDataFile ¶
func LoadCSVDataFile(fileName string)
LoadCSVDataFile loads the data of the given file into the database.
func RegisterModelDataWrapper ¶
func RegisterModelDataWrapper(modelName string, obj interface{})
RegisterModelDataWrapper registers the object passed as obj as the ModelData type for the given model.
- typ must be a struct that embeds ModelData - modelName must be the name of a model that exists in the registry
func RegisterRecordSetWrapper ¶
func RegisterRecordSetWrapper(modelName string, obj interface{})
RegisterRecordSetWrapper registers the object passed as obj as the RecordSet type for the given model.
- typ must be a struct that embeds *RecordCollection - modelName must be the name of a model that exists in the registry
func RegisterWorker ¶
func RegisterWorker(wf WorkerFunction)
RegisterWorker registers a WorkerFunction so that it will be called by the core loop.
func RunWorkerLoop ¶
func RunWorkerLoop()
RunWorkerLoop launches the hexya core worker loop.
This function must be called only once or it will panic
func SimulateInNewEnvironment ¶
func SimulateInNewEnvironment(uid int64, fnct func(Environment)) error
SimulateInNewEnvironment executes the given fnct in a new Environment within a new transaction and rolls back the transaction at the end.
This function always rolls back the transaction but returns an error only if fnct panicked during its execution.
func SnakeCaseFieldName ¶
SnakeCaseFieldName returns a snake cased field name, adding '_id' on x2one relation fields and '_ids' to x2many relation fields.
func StopWorkerLoop ¶
func StopWorkerLoop()
StopWorkerLoop stops the hexya core worker loop.
Calling this method if the core worker loop is not running will cause panic.
func SyncDatabase ¶
func SyncDatabase()
SyncDatabase creates or updates database tables with the data in the model registry
Types ¶
type ClientEvaluatedString ¶
type ClientEvaluatedString string
A ClientEvaluatedString is a string that contains code that will be evaluated by the client
type ColumnData ¶
type ColumnData struct { ColumnName string DataType string IsNullable string ColumnDefault sql.NullString }
A ColumnData holds information from the db schema about one column
type Condition ¶
type Condition struct {
// contains filtered or unexported fields
}
A Condition represents a WHERE clause of an SQL query.
func (Condition) And ¶
func (c Condition) And() *ConditionStart
And completes the current condition with a simple AND clause : c.And().nextCond => c AND nextCond.
No brackets are added so AND precedence over OR applies.
func (Condition) AndCond ¶
AndCond completes the current condition with the given cond as an AND clause between brackets : c.And(cond) => (c) AND (cond)
func (Condition) AndNot ¶
func (c Condition) AndNot() *ConditionStart
AndNot completes the current condition with a simple AND NOT clause : c.AndNot().nextCond => c AND NOT nextCond
No brackets are added so AND precedence over OR applies.
func (Condition) AndNotCond ¶
AndNotCond completes the current condition with an AND NOT clause between brackets : c.AndNot(cond) => (c) AND NOT (cond)
func (Condition) HasField ¶
HasField returns true if the given field is in at least one of the the predicates of this condition or of one of its nested conditions.
func (Condition) Or ¶
func (c Condition) Or() *ConditionStart
Or completes the current condition both with a simple OR clause : c.Or().nextCond => c OR nextCond
No brackets are added so AND precedence over OR applies.
func (Condition) OrCond ¶
OrCond completes the current condition both with an OR clause between brackets : c.Or(cond) => (c) OR (cond)
func (Condition) OrNot ¶
func (c Condition) OrNot() *ConditionStart
OrNot completes the current condition both with a simple OR NOT clause : c.OrNot().nextCond => c OR NOT nextCond
No brackets are added so AND precedence over OR applies.
func (Condition) OrNotCond ¶
OrNotCond completes the current condition both with an OR NOT clause between brackets : c.OrNot(cond) => (c) OR NOT (cond)
func (Condition) PredicatesWithField ¶
PredicatesWithField returns all predicates of this condition (including nested conditions) that concern the given field.
func (Condition) Serialize ¶
func (c Condition) Serialize() []interface{}
Serialize returns the condition as a list which mimics Odoo domains.
func (Condition) Underlying ¶
Underlying returns the underlying Condition (i.e. itself)
type ConditionField ¶
type ConditionField struct {
// contains filtered or unexported fields
}
A ConditionField is a partial Condition when we have set a field name in a predicate and are about to add an operator.
func (ConditionField) AddOperator ¶
func (c ConditionField) AddOperator(op operator.Operator, data interface{}) *Condition
AddOperator adds a condition value to the condition with the given operator and data If multi is true, a recordset will be converted into a slice of int64 otherwise, it will return an int64 and panic if the recordset is not a singleton.
This method is low level and should be avoided. Use operator methods such as Equals() instead.
func (ConditionField) ChildOf ¶
func (c ConditionField) ChildOf(data interface{}) *Condition
ChildOf appends the 'child of' operator to the current Condition
func (ConditionField) Contains ¶
func (c ConditionField) Contains(data interface{}) *Condition
Contains appends the 'LIKE %%' operator to the current Condition
func (ConditionField) Equals ¶
func (c ConditionField) Equals(data interface{}) *Condition
Equals appends the '=' operator to the current Condition
func (ConditionField) Greater ¶
func (c ConditionField) Greater(data interface{}) *Condition
Greater appends the '>' operator to the current Condition
func (ConditionField) GreaterOrEqual ¶
func (c ConditionField) GreaterOrEqual(data interface{}) *Condition
GreaterOrEqual appends the '>=' operator to the current Condition
func (ConditionField) IContains ¶
func (c ConditionField) IContains(data interface{}) *Condition
IContains appends the 'ILIKE %%' operator to the current Condition
func (ConditionField) ILike ¶
func (c ConditionField) ILike(data interface{}) *Condition
ILike appends the 'ILIKE' operator to the current Condition
func (ConditionField) In ¶
func (c ConditionField) In(data interface{}) *Condition
In appends the 'IN' operator to the current Condition
func (ConditionField) IsNotNull ¶
func (c ConditionField) IsNotNull() *Condition
IsNotNull checks if the current condition field is not null
func (ConditionField) IsNull ¶
func (c ConditionField) IsNull() *Condition
IsNull checks if the current condition field is null
func (ConditionField) JSON ¶
func (c ConditionField) JSON() string
JSON returns the json field name of this ConditionField
func (ConditionField) Like ¶
func (c ConditionField) Like(data interface{}) *Condition
Like appends the 'LIKE' operator to the current Condition
func (ConditionField) Lower ¶
func (c ConditionField) Lower(data interface{}) *Condition
Lower appends the '<' operator to the current Condition
func (ConditionField) LowerOrEqual ¶
func (c ConditionField) LowerOrEqual(data interface{}) *Condition
LowerOrEqual appends the '<=' operator to the current Condition
func (ConditionField) NotContains ¶
func (c ConditionField) NotContains(data interface{}) *Condition
NotContains appends the 'NOT LIKE %%' operator to the current Condition
func (ConditionField) NotEquals ¶
func (c ConditionField) NotEquals(data interface{}) *Condition
NotEquals appends the '!=' operator to the current Condition
func (ConditionField) NotIContains ¶
func (c ConditionField) NotIContains(data interface{}) *Condition
NotIContains appends the 'NOT ILIKE %%' operator to the current Condition
func (ConditionField) NotIn ¶
func (c ConditionField) NotIn(data interface{}) *Condition
NotIn appends the 'NOT IN' operator to the current Condition
type ConditionStart ¶
type ConditionStart struct {
// contains filtered or unexported fields
}
A ConditionStart is an object representing a Condition when we just added a logical operator (AND, OR, ...) and we are about to add a predicate.
func (ConditionStart) Field ¶
func (cs ConditionStart) Field(name FieldName) *ConditionField
Field adds a field path (dot separated) to this condition
func (ConditionStart) FilteredOn ¶
func (cs ConditionStart) FilteredOn(field FieldName, condition *Condition) *Condition
FilteredOn adds a condition with a table join on the given field and filters the result with the given condition
type Conditioner ¶
type Conditioner interface {
Underlying() *Condition
}
A Conditioner can return a Condition object through its Underlying() method
type ConnectionParams ¶
type ConnectionParams struct { Driver string Host string Port string User string Password string DBName string SSLMode string SSLCert string SSLKey string SSLCA string }
ConnectionParams are the database agnostic parameters to connect to the database
func DBParams ¶
func DBParams() ConnectionParams
DBParams returns the DB connection parameters currently in use
func (ConnectionParams) ConnectionString ¶
func (cp ConnectionParams) ConnectionString() string
ConnectionString returns the connection string for these connection params
type Cursor ¶
type Cursor struct {
// contains filtered or unexported fields
}
Cursor is a wrapper around a database transaction
func (*Cursor) Execute ¶
Execute a query without returning any rows. It panics in case of error. The args are for any placeholder parameters in the query.
type DummyField ¶
type DummyField struct{}
DummyField is used internally to inflate mixins. It should not be used.
func (DummyField) DeclareField ¶
func (df DummyField) DeclareField(fc *FieldsCollection, name string) *Field
DeclareField creates a dummy field for the given FieldsCollection with the given name.
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
An Environment stores various contextual data used by the models: - the database cursor (current open transaction), - the current user ID (for access rights checking) - the current context (for storing arbitrary metadata). The Environment also stores caches.
func (Environment) Context ¶
func (env Environment) Context() *types.Context
Context returns the Context of the Environment
func (Environment) Cr ¶
func (env Environment) Cr() *Cursor
Cr returns a pointer to the Cursor of the Environment
func (Environment) DumpCache ¶
func (env Environment) DumpCache() string
DumpCache returns a human readable string of this Environment's cache for debugging purposes.
func (Environment) Pool ¶
func (env Environment) Pool(modelName string) *RecordCollection
Pool returns an empty RecordCollection for the given modelName
func (Environment) Uid ¶
func (env Environment) Uid() int64
Uid returns the user id of the Environment
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field holds the meta information about a field
func CreateFieldFromStruct ¶
func CreateFieldFromStruct(fc *FieldsCollection, fStruct interface{}, name string, fieldType fieldtype.Type, goType interface{}) *Field
CreateFieldFromStruct creates a generic Field with the data from the given fStruct
fStruct must be a pointer to a struct and goType a pointer to a type instance
func (*Field) AddContexts ¶
func (f *Field) AddContexts(value FieldContexts) *Field
AddContexts adds the given contexts to the Contexts parameter of this Field
func (*Field) SetCompute ¶
SetCompute overrides the value of the Compute parameter of this Field
func (*Field) SetConstraint ¶
SetConstraint overrides the value of the Constraint parameter of this Field
func (*Field) SetContexts ¶
func (f *Field) SetContexts(value FieldContexts) *Field
SetContexts overrides the value of the Contexts parameter of this Field
func (*Field) SetDefault ¶
func (f *Field) SetDefault(value func(Environment) interface{}) *Field
SetDefault overrides the value of the Default parameter of this Field
func (*Field) SetDepends ¶
SetDepends overrides the value of the Depends parameter of this Field
func (*Field) SetFieldType ¶
SetFieldType overrides the type of Field. This may fail at database sync if the table already has values and the old type cannot be casted into the new type by the database.
func (*Field) SetFilter ¶
func (f *Field) SetFilter(value Conditioner) *Field
SetFilter overrides the value of the Filter parameter of this Field
func (*Field) SetGroupOperator ¶
SetGroupOperator overrides the value of the GroupOperator parameter of this Field
func (*Field) SetInverse ¶
SetInverse overrides the value of the Inverse parameter of this Field
func (*Field) SetInvisibleFunc ¶
func (f *Field) SetInvisibleFunc(value func(Environment) (bool, Conditioner)) *Field
SetInvisibleFunc overrides the value of the InvisibleFunc parameter of this Field
func (*Field) SetM2MOurField ¶
SetM2MOurField sets the field of the M2MRelModel pointing to this model.
func (*Field) SetM2MRelModel ¶
SetM2MRelModel sets the relation model between this model and the target model.
func (*Field) SetM2MTheirField ¶
SetM2MTheirField sets the field of the M2MRelModel pointing to the other model.
func (*Field) SetOnDelete ¶
func (f *Field) SetOnDelete(value OnDeleteAction) *Field
SetOnDelete overrides the value of the OnDelete parameter of this Field
func (*Field) SetOnchange ¶
SetOnchange overrides the value of the Onchange parameter of this Field
func (*Field) SetOnchangeFilters ¶
SetOnchangeFilters overrides the value of the OnChangeFilters parameter of this Field
func (*Field) SetOnchangeWarning ¶
SetOnchangeWarning overrides the value of the OnChangeWarning parameter of this Field
func (*Field) SetProperty ¶
SetProperty sets the given property value in this field This method uses switch as they are unexported struct fields
func (*Field) SetReadOnly ¶
SetReadOnly overrides the value of the ReadOnly parameter of this Field
func (*Field) SetReadOnlyFunc ¶
func (f *Field) SetReadOnlyFunc(value func(Environment) (bool, Conditioner)) *Field
SetReadOnlyFunc overrides the value of the ReadOnlyFunc parameter of this Field
func (*Field) SetRelated ¶
SetRelated overrides the value of the Related parameter of this Field
func (*Field) SetRelationModel ¶
SetRelationModel overrides the value of the Filter parameter of this Field
func (*Field) SetRequired ¶
SetRequired overrides the value of the Required parameter of this Field
func (*Field) SetRequiredFunc ¶
func (f *Field) SetRequiredFunc(value func(Environment) (bool, Conditioner)) *Field
SetRequiredFunc overrides the value of the RequiredFunc parameter of this Field
func (*Field) SetReverseFK ¶
SetReverseFK sets the name of the FK pointing to this model in a O2M or R2O relation
func (*Field) SetSelection ¶
SetSelection overrides the value of the Selection parameter of this Field
func (*Field) SetSelectionFunc ¶
SetSelectionFunc defines the function that will return the selection of this field
func (*Field) SetTranslate ¶
SetTranslate overrides the value of the Translate parameter of this Field
type FieldContexts ¶
FieldContexts define the different contexts for a field, that will define different values for this field.
The key is a context name and the value is a function that returns the context value for the given recordset.
type FieldDefinition ¶
type FieldDefinition interface { // DeclareField creates a field for the given FieldsCollection with the given name and returns the created field. DeclareField(*FieldsCollection, string) *Field }
A FieldDefinition is a struct that declares a new field in a fields collection;
type FieldInfo ¶
type FieldInfo struct { ChangeDefault bool `json:"change_default"` Help string `json:"help"` Searchable bool `json:"searchable"` Views map[string]interface{} `json:"views"` Required bool `json:"required"` Manual bool `json:"manual"` ReadOnly bool `json:"readonly"` Depends []string `json:"depends"` CompanyDependent bool `json:"company_dependent"` Sortable bool `json:"sortable"` Translate bool `json:"translate"` Type fieldtype.Type `json:"type"` Store bool `json:"store"` String string `json:"string"` Relation string `json:"relation"` Selection types.Selection `json:"selection"` Domain interface{} `json:"domain"` OnChange bool `json:"-"` ReverseFK string `json:"-"` Name string `json:"-"` JSON string `json:"-"` ReadOnlyFunc func(Environment) (bool, Conditioner) `json:"-"` RequiredFunc func(Environment) (bool, Conditioner) `json:"-"` InvisibleFunc func(Environment) (bool, Conditioner) `json:"-"` DefaultFunc func(Environment) interface{} `json:"-"` GoType reflect.Type `json:"-"` Index bool `json:"-"` }
FieldInfo is the exportable field information struct
type FieldMap ¶
type FieldMap map[string]interface{}
FieldMap is a map of interface{} specifically used for holding model fields values.
func (*FieldMap) Delete ¶
Delete removes the given field from this FieldMap. Calling Del on a non existent field is a no op.
func (FieldMap) FieldNames ¶
func (fm FieldMap) FieldNames(model *Model) FieldNames
FieldNames returns the keys of this FieldMap as FieldNames of the given model
func (FieldMap) Get ¶
Get returns the value of the given field referring to the given model. field can be either a field name (or path) or a field JSON name (or path). The second returned value is true if the field has been found in the FieldMap
func (*FieldMap) MergeWith ¶
MergeWith updates this FieldMap with the given other FieldMap If a key of the other FieldMap already exists here, the value is overridden, otherwise, the key is inserted with its json name.
func (FieldMap) MustGet ¶
MustGet returns the value of the given field referring to the given model. field can be either a field name (or path) or a field JSON name (or path). It panics if the field is not found.
func (FieldMap) OrderedKeys ¶
OrderedKeys returns the keys of this FieldMap ordered.
This has the convenient side effect of having shorter paths come before longer paths, which is particularly useful when creating or updating related records.
func (*FieldMap) RemovePK ¶
func (fm *FieldMap) RemovePK()
RemovePK removes the entries of our FieldMap which references the ID field.
func (*FieldMap) RemovePKIfZero ¶
func (fm *FieldMap) RemovePKIfZero()
RemovePKIfZero removes the entries of our FieldMap which references the ID field if the referenced id is 0.
func (*FieldMap) Set ¶
Set sets the given field with the given value. If the field already exists, then it is updated with value. Otherwise, a new entry is inserted in the FieldMap with the JSON name of the field.
func (FieldMap) Underlying ¶
Underlying returns the object converted to a FieldMap i.e. itself
type FieldMapper ¶
type FieldMapper interface { // Underlying returns the object converted to a FieldMap. Underlying() FieldMap }
A FieldMapper is an object that can convert itself into a FieldMap
type FieldName ¶
A FieldName is a type that can represents a field in a model. It can yield the field name or the field's JSON name as a string
func NewFieldName ¶
NewFieldName returns a fieldName instance with the given name and json
type FieldNames ¶
type FieldNames []FieldName
FieldNames is a slice of FieldName that can be sorted
func (FieldNames) JSON ¶
func (f FieldNames) JSON() []string
JSON returns a slice with the JSON names of each field
func (FieldNames) Less ¶
func (f FieldNames) Less(i, j int) bool
Less returns true if f[i] < f[j]. FieldNames are ordered by JSON names
func (FieldNames) Names ¶
func (f FieldNames) Names() []string
Names returns a slice with the names of each field
func (*FieldNames) UnmarshalJSON ¶
func (f *FieldNames) UnmarshalJSON(data []byte) error
UnmarshalJSON for the FieldNames type
type FieldsCollection ¶
FieldsCollection is a collection of Field instances in a model.
func (*FieldsCollection) Get ¶
func (fc *FieldsCollection) Get(name string) (fi *Field, ok bool)
Get returns the Field of the field with the given name. name can be either the name of the field or its JSON name.
func (*FieldsCollection) Model ¶
func (fc *FieldsCollection) Model() *Model
Model returns this FieldsCollection Model
func (*FieldsCollection) MustGet ¶
func (fc *FieldsCollection) MustGet(name string) *Field
MustGet returns the Field of the field with the given name or panics name can be either the name of the field or its JSON name.
type FieldsGetArgs ¶
type FieldsGetArgs struct { // Fields is a list of fields to document, all if empty or not provided Fields FieldNames `json:"allfields"` }
FieldsGetArgs is the args struct for the FieldsGet method
type GroupAggregateRow ¶
A GroupAggregateRow holds a row of results of a query with a group by clause - Values holds the values of the actual query - Count is the number of lines aggregated into this one - Condition can be used to query the aggregated rows separately if needed
type Method ¶
A Method is a definition of a model's method
func (*Method) AllowGroup ¶
AllowGroup grants the execution permission on this method to the given group If callers are defined, then the permission is granted only when this method is called from one of the callers, otherwise it is granted from any caller.
func (*Method) Call ¶
func (m *Method) Call(rc *RecordCollection, params ...interface{}) interface{}
Call executes the given method with the given parameters and returns (only) the first returned value
func (*Method) CallMulti ¶
func (m *Method) CallMulti(rc *RecordCollection, params ...interface{}) []interface{}
CallMulti executes the given method with the given parameters and returns all returned value as []interface{}.
func (*Method) Extend ¶
Extend adds the given fnct function as a new layer on this method. fnct must be of the same signature as the first layer of this method.
func (*Method) MethodType ¶
MethodType returns the methodType of a Method
func (*Method) RevokeGroup ¶
RevokeGroup revokes the execution permission on the method to the given group if it has been given previously, otherwise does nothing. Note that this methods revokes all permissions, whatever the caller.
func (*Method) Underlying ¶
Underlying returns the underlysing method data object
type Methoder ¶
type Methoder interface {
Underlying() *Method
}
A Methoder can return a Method data object through its Underlying() method
type MethodsCollection ¶
type MethodsCollection struct {
// contains filtered or unexported fields
}
A MethodsCollection is a collection of methods for use in a model
func (*MethodsCollection) AllowAllToGroup ¶
func (mc *MethodsCollection) AllowAllToGroup(group *security.Group)
AllowAllToGroup grants the given group access to all the CRUD methods of this collection
func (*MethodsCollection) Get ¶
func (mc *MethodsCollection) Get(methodName string) (*Method, bool)
Get returns the Method with the given method name.
The second return value is true if a method has been found.
func (*MethodsCollection) MustGet ¶
func (mc *MethodsCollection) MustGet(methodName string) *Method
MustGet returns the Method of the given method. It panics if the method is not found.
func (*MethodsCollection) RevokeAllFromGroup ¶
func (mc *MethodsCollection) RevokeAllFromGroup(group *security.Group)
RevokeAllFromGroup revokes permissions on all CRUD methods given by AllowAllToGroup
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
A Model is the definition of a business object (e.g. a partner, a sale order, etc.) including fields and methods.
func CreateModel ¶
CreateModel creates a new Model with the given name and options. You should not use this function directly. Use NewModel instead.
func NewManualModel ¶
NewManualModel creates a model whose table is not automatically generated in the database. This is particularly useful for SQL view models.
func NewMixinModel ¶
NewMixinModel creates a new mixin model with the given name.
func NewTransientModel ¶
NewTransientModel creates a new mixin model with the given name.
func (*Model) AddEmptyMethod ¶
AddEmptyMethod creates a new method without function layer The resulting method cannot be called until finalize is called
func (*Model) AddFields ¶
func (m *Model) AddFields(fields map[string]FieldDefinition)
AddFields adds the given fields to the model.
func (*Model) AddRecordRule ¶
func (m *Model) AddRecordRule(rule *RecordRule)
AddRecordRule registers the given RecordRule to the registry for the given model with the given name.
func (*Model) AddSQLConstraint ¶
AddSQLConstraint adds a table constraint in the database.
- name is an arbitrary name to reference this constraint. It will be appended by the table name in the database, so there is only need to ensure that it is unique in this model.
- sql is constraint definition to pass to the database.
- errorString is the text to display to the user when the constraint is violated
func (*Model) Browse ¶
func (m *Model) Browse(env Environment, ids []int64) *RecordCollection
Browse returns a new RecordSet with the records with the given ids. Note that this function is just a shorcut for Search on a list of ids.
func (*Model) BrowseOne ¶
func (m *Model) BrowseOne(env Environment, id int64) *RecordCollection
BrowseOne returns a new RecordSet with the record with the given id. Note that this function is just a shorcut for Search the given id.
func (*Model) Create ¶
func (m *Model) Create(env Environment, data interface{}) *RecordCollection
Create creates a new record in this model with the given data.
func (*Model) Field ¶
func (m *Model) Field(name FieldName) *ConditionField
Field starts a condition on this model
func (*Model) FieldName ¶
FieldName returns a FieldName for the field with the given name. name may be a dot separated path from this model. It returns nil if the name is empty and panics if the path is invalid.
func (*Model) FieldNames ¶
func (m *Model) FieldNames() FieldNames
FieldNames returns the slice of all field's names for this model
func (*Model) Fields ¶
func (m *Model) Fields() *FieldsCollection
Fields returns the fields collection of this model
func (*Model) FieldsGet ¶
FieldsGet returns the definition of each field. The embedded fields are included.
If no fields are given, then all fields are returned.
The result map is indexed by the fields JSON names.
func (*Model) FilteredOn ¶
FilteredOn adds a condition with a table join on the given field and filters the result with the given condition
func (*Model) InheritModel ¶
InheritModel extends this Model by importing all fields and methods of mixInModel. MixIn methods and fields have a lower priority than those of the model and are overridden by the them when applicable.
func (*Model) IsTransient ¶
IsTransient returns true if this Model is transient
func (*Model) JSONizeFieldName ¶
JSONizeFieldName returns the json name of the given fieldName If fieldName is already the json name, returns it without modifying it. fieldName may be a dot separated path from this model. It panics if the path is invalid.
func (*Model) Methods ¶
func (m *Model) Methods() *MethodsCollection
Methods returns the methods collection of this model
func (*Model) RemoveRecordRule ¶
RemoveRecordRule removes the Record Rule with the given name from the rule registry of the given model.
func (*Model) RemoveSQLConstraint ¶
RemoveSQLConstraint removes the sql constraint with the given name from the database.
func (*Model) Search ¶
func (m *Model) Search(env Environment, cond Conditioner) *RecordCollection
Search searches the database and returns records matching the given condition.
func (*Model) SetDefaultOrder ¶
SetDefaultOrder sets the default order used by this model when no OrderBy() is specified in a query. When unspecified, default order is 'id asc'.
Give the order fields in separate strings, such as model.SetDefaultOrder("Name desc", "date asc", "id")
func (*Model) Underlying ¶
Underlying returns the underlying Model data object, i.e. itself
type ModelData ¶
A ModelData is used to hold values of an object instance for creating or updating a RecordSet. It is mainly designed to be embedded in a type-safe struct.
func NewModelData ¶
NewModelData returns a pointer to a new instance of ModelData for the given model. If FieldMaps are given they are added to the ModelData.
func NewModelDataFromRS ¶
NewModelDataFromRS creates a pointer to a new instance of ModelData. If FieldMaps are given they are added to the ModelData.
Unlike NewModelData, this method translates relation fields in64 and []int64 values as RecordSets
func (*ModelData) Create ¶
Create stores the related ModelData to be used to create a related record on the fly and link it to this field.
This method can be called multiple times to create multiple records
func (*ModelData) FieldNames ¶
func (md *ModelData) FieldNames() FieldNames
FieldNames returns the ModelData keys as a slice of FieldNames.
func (*ModelData) Get ¶
Get returns the value of the given field.
The field can be either its name or is JSON name.
func (*ModelData) Has ¶
Has returns true if this ModelData has values for the given field.
The field can be either its name or is JSON name.
func (*ModelData) MarshalJSON ¶
MarshalJSON function for ModelData. Returns the FieldMap.
func (*ModelData) MergeWith ¶
MergeWith updates this ModelData with the given other ModelData. If a key of the other ModelData already exists here, the value is overridden, otherwise, the key is inserted with its json name.
func (*ModelData) Set ¶
Set sets the given field with the given value. If the field already exists, then it is updated with value. Otherwise, a new entry is inserted.
It returns the given ModelData so that calls can be chained
func (*ModelData) Underlying ¶
Underlying returns the ModelData
type Modeler ¶
type Modeler interface {
Underlying() *Model
}
A Modeler can return a Model data object through its Underlying() method
type OnDeleteAction ¶
type OnDeleteAction string
An OnDeleteAction defines what to be done with this record when the target record is deleted.
const ( // SetNull sets the foreign key to null in referencing records. This is the default SetNull OnDeleteAction = "set null" // Restrict throws an error if there are record referencing the deleted one. Restrict OnDeleteAction = "restrict" // Cascade deletes all referencing records. Cascade OnDeleteAction = "cascade" )
type OnchangeParams ¶
type OnchangeParams struct { Values RecordData `json:"values"` Fields FieldNames `json:"field_name"` Onchange map[string]string `json:"field_onchange"` }
OnchangeParams is the args struct of the Onchange function
type OnchangeResult ¶
type OnchangeResult struct { Value RecordData `json:"value"` Warning string `json:"warning"` Filters map[FieldName]Conditioner `json:"domain"` }
OnchangeResult is the result struct type of the Onchange function
type Option ¶
type Option int
Option describes a optional feature of a model
const ( // TransientModel means that the records of this model will be automatically // removed periodically. Transient models are mainly used for wizards. TransientModel Option = 1 << iota // MixinModel means that this model will not be accessible like a regular model // but is meant to be mixed in other models. MixinModel // Many2ManyLinkModel is a model that abstracts the link // table of a many2many relationship Many2ManyLinkModel // ContextsModel is a model for holding fields values that depend on contexts ContextsModel // ManualModel is a model whose table is not automatically generated in the // database. Such models include SQL views and materialized SQL views. ManualModel // SystemModel is a model that is used internally by the Hexya Framework SystemModel )
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
A Query defines the common part an SQL Query, i.e. all that come after the FROM keyword.
type RecordCollection ¶
type RecordCollection struct {
// contains filtered or unexported fields
}
RecordCollection is a generic struct representing several records of a model.
func InvalidRecordCollection ¶
func InvalidRecordCollection(modelName string) *RecordCollection
InvalidRecordCollection returns an invalid RecordCollection without an environment.
You should really not use this function, but use env.Pool("ModelName") instead.
func (*RecordCollection) Aggregates ¶
func (rc *RecordCollection) Aggregates(fieldNames ...FieldName) []GroupAggregateRow
Aggregates returns the result of this RecordCollection query, which must by a grouped query.
func (*RecordCollection) All ¶
func (rc *RecordCollection) All() []*ModelData
All returns the values of all records of the RecordCollection as a slice of ModelData.
func (*RecordCollection) Call ¶
func (rc *RecordCollection) Call(methName string, args ...interface{}) interface{}
Call calls the given method name methName on the given RecordCollection with the given arguments and returns (only) the first result as interface{}.
func (*RecordCollection) CallMulti ¶
func (rc *RecordCollection) CallMulti(methName string, args ...interface{}) []interface{}
CallMulti calls the given method name methName on the given RecordCollection with the given arguments and return the result as []interface{}.
func (*RecordCollection) CartesianProduct ¶
func (rc *RecordCollection) CartesianProduct(records ...RecordSet) []*RecordCollection
CartesianProduct returns the cartesian product of this RecordCollection with others.
This function panics if all records are not pf the same model
func (*RecordCollection) CheckConstraints ¶
func (rc *RecordCollection) CheckConstraints(fields FieldNames)
CheckConstraints executes the constraint method for each field defined in the given FieldNames. Each method is only executed once, even if it is called by several fields. It panics as soon as one constraint fails.
func (*RecordCollection) CheckExecutionPermission ¶
func (rc *RecordCollection) CheckExecutionPermission(method *Method, dontPanic ...bool) bool
CheckExecutionPermission panics if the current user is not allowed to execute the given method.
If dontPanic is false, this function will panic, otherwise it returns true if the user has the execution permission and false otherwise.
func (*RecordCollection) Collection ¶
func (rc *RecordCollection) Collection() *RecordCollection
Collection returns the underlying RecordCollection instance i.e. itself
func (*RecordCollection) Condition ¶
func (rc *RecordCollection) Condition() *Condition
Condition returns the query condition associated with this RecordSet.
func (*RecordCollection) EnsureOne ¶
func (rc *RecordCollection) EnsureOne()
EnsureOne panics if rc is not a singleton
func (*RecordCollection) Env ¶
func (rc *RecordCollection) Env() Environment
Env returns the RecordSet's Environment
func (*RecordCollection) Equals ¶
func (rc *RecordCollection) Equals(other RecordSet) bool
Equals returns true if this RecordCollection is the same as other i.e. they are of the same model and have the same ids
func (*RecordCollection) Fetch ¶
func (rc *RecordCollection) Fetch() *RecordCollection
Fetch query the database with the current filter and returns a RecordSet with the queries ids.
Fetch is lazy and only return ids. Use Load() instead if you want to fetch all fields.
func (*RecordCollection) Filtered ¶
func (rc *RecordCollection) Filtered(test func(rs RecordSet) bool) *RecordCollection
Filtered returns a new record set with only the elements of this record set for which test is true.
Note that if this record set is not fully loaded, this function will call the database to load the fields before doing the filtering. In this case, it might be more efficient to search the database directly with the filter condition.
func (*RecordCollection) First ¶
func (rc *RecordCollection) First() *ModelData
First returns the values of the first Record of the RecordCollection as a ModelData.
If this RecordCollection is empty, it returns an empty ModelData.
func (*RecordCollection) ForceLoad ¶
func (rc *RecordCollection) ForceLoad(fieldNames ...FieldName) *RecordCollection
ForceLoad query all data of the RecordCollection and store in cache. fields are the fields to retrieve in the path format, i.e. "User.Profile.Age" or "user_id.profile_id.age".
If no fields are given, all DB columns of the RecordCollection's model are retrieved as well as related fields. Non-DB fields must be explicitly given in fields to be retrieved.
func (*RecordCollection) Get ¶
func (rc *RecordCollection) Get(fieldName FieldName) interface{}
Get returns the value of the given fieldName for the first record of this RecordCollection. It returns the type's zero value if the RecordCollection is empty.
func (*RecordCollection) GetRecord ¶
func (rc *RecordCollection) GetRecord(externalID string) *RecordCollection
GetRecord returns the Recordset with the given externalID. It panics if the externalID does not exist.
func (*RecordCollection) GroupBy ¶
func (rc *RecordCollection) GroupBy(fields ...FieldName) *RecordCollection
GroupBy returns a new RecordSet grouped with the given GROUP BY expressions
func (*RecordCollection) Ids ¶
func (rc *RecordCollection) Ids() []int64
Ids returns the ids of the RecordSet, fetching from db if necessary.
func (*RecordCollection) Intersect ¶
func (rc *RecordCollection) Intersect(other RecordSet) *RecordCollection
Intersect returns a new RecordCollection with only the records that are both in this RecordCollection and in the other RecordSet.
func (*RecordCollection) InvalidateCache ¶
func (rc *RecordCollection) InvalidateCache()
InvalidateCache clears the cache for this RecordSet data, and immediately reloads the data from the DB.
func (*RecordCollection) IsEmpty ¶
func (rc *RecordCollection) IsEmpty() bool
IsEmpty returns true if rc is an empty RecordCollection
func (*RecordCollection) IsNotEmpty ¶
func (rc *RecordCollection) IsNotEmpty() bool
IsNotEmpty returns true if rc is not an empty RecordCollection
func (*RecordCollection) IsValid ¶
func (rc *RecordCollection) IsValid() bool
IsValid returns true if this RecordSet has been initialized.
func (*RecordCollection) Len ¶
func (rc *RecordCollection) Len() int
Len returns the number of records in this RecordCollection
func (*RecordCollection) Limit ¶
func (rc *RecordCollection) Limit(limit int) *RecordCollection
Limit returns a new RecordSet with only the first 'limit' records.
func (*RecordCollection) Load ¶
func (rc *RecordCollection) Load(fields ...FieldName) *RecordCollection
Load look up fields of the RecordCollection in cache and query the database for missing values which are then stored in cache.
func (*RecordCollection) MethodType ¶
func (rc *RecordCollection) MethodType(methName string) reflect.Type
MethodType returns the type of the method given by methName
func (*RecordCollection) Model ¶
func (rc *RecordCollection) Model() *Model
Model returns the Model instance of this RecordCollection
func (*RecordCollection) ModelName ¶
func (rc *RecordCollection) ModelName() string
ModelName returns the model name of the RecordSet
func (*RecordCollection) Offset ¶
func (rc *RecordCollection) Offset(offset int) *RecordCollection
Offset returns a new RecordSet with only the records starting at offset
func (*RecordCollection) OrderBy ¶
func (rc *RecordCollection) OrderBy(exprs ...string) *RecordCollection
OrderBy returns a new RecordSet ordered by the given ORDER BY expressions
func (*RecordCollection) Records ¶
func (rc *RecordCollection) Records() []*RecordCollection
Records returns the slice of RecordCollection singletons that constitute this RecordCollection.
func (*RecordCollection) SQLFromCondition ¶
func (rc *RecordCollection) SQLFromCondition(c *Condition) (string, SQLParams)
SQLFromCondition returns the WHERE clause sql and arguments corresponding to the given condition.
func (*RecordCollection) Scan ¶
func (rc *RecordCollection) Scan(src interface{}) error
Scan implements sql.Scanner
func (*RecordCollection) Search ¶
func (rc *RecordCollection) Search(cond *Condition) *RecordCollection
Search returns a new RecordSet filtering on the current one with the additional given Condition
func (*RecordCollection) SearchAll ¶
func (rc *RecordCollection) SearchAll() *RecordCollection
SearchAll returns a new RecordSet with all items of the table, regardless of the current RecordSet query. It is mainly meant to be used on an empty RecordSet
func (*RecordCollection) SearchCount ¶
func (rc *RecordCollection) SearchCount() int
SearchCount fetch from the database the number of records that match the RecordSet conditions It panics in case of error
func (*RecordCollection) Set ¶
func (rc *RecordCollection) Set(fieldName FieldName, value interface{})
Set sets field given by fieldName to the given value. If the RecordSet has several Records, all of them will be updated. Each call to Set makes an update query in the database. It panics if it is called on an empty RecordSet.
func (*RecordCollection) Sorted ¶
func (rc *RecordCollection) Sorted(less func(rs1 RecordSet, rs2 RecordSet) bool) *RecordCollection
Sorted returns a new RecordCollection sorted according to the given less function.
The less function should return true if rs1 < rs2
func (*RecordCollection) SortedByField ¶
func (rc *RecordCollection) SortedByField(name FieldName, reverse bool) *RecordCollection
SortedByField returns a new record set with the same records as rc but sorted by the given field. If reverse is true, the sort is done in reversed order
func (*RecordCollection) SortedDefault ¶
func (rc *RecordCollection) SortedDefault() *RecordCollection
SortedDefault returns a new record set with the same records as rc but sorted according to the default order of this model
func (*RecordCollection) String ¶
func (rc *RecordCollection) String() string
String returns the string representation of a RecordSet
func (*RecordCollection) Subtract ¶
func (rc *RecordCollection) Subtract(other RecordSet) *RecordCollection
Subtract returns a RecordSet with the Records that are in this RecordCollection but not in the given 'other' one. The result is guaranteed to be a set of unique records.
func (*RecordCollection) Sudo ¶
func (rc *RecordCollection) Sudo(userId ...int64) *RecordCollection
Sudo returns a new RecordCollection with the given userId or the superuser id if not specified
func (*RecordCollection) Super ¶
func (rc *RecordCollection) Super() *RecordCollection
Super returns a RecordSet with a modified callstack so that call to the current method will execute the next method layer.
This method is meant to be used inside a method layer function to call its parent, such as:
func (rs models.RecordCollection) MyMethod() string { res := rs.Super().MyMethod() res += " ok!" return res }
Calls to a different method than the current method will call its next layer only if the current method has been called from a layer of the other method. Otherwise, it will be the same as calling the other method directly.
func (*RecordCollection) T ¶
func (rc *RecordCollection) T(src string, args ...interface{}) string
T translates the given string to the language specified by the 'lang' key of rc.Env().Context(). If for any reason the string cannot be translated, then src is returned.
You MUST pass a string literal as src to have it extracted automatically ¶
The translated string will be passed to fmt.Sprintf with the optional args before being returned.
func (*RecordCollection) Union ¶
func (rc *RecordCollection) Union(other RecordSet) *RecordCollection
Union returns a new RecordCollection that is the union of this RecordCollection and the given `other` RecordCollection. The result is guaranteed to be a set of unique records. The order of the records is kept.
func (*RecordCollection) WithContext ¶
func (rc *RecordCollection) WithContext(key string, value interface{}) *RecordCollection
WithContext returns a copy of the current RecordCollection with its context extended by the given key and value.
func (*RecordCollection) WithEnv ¶
func (rc *RecordCollection) WithEnv(env Environment) *RecordCollection
WithEnv returns a copy of the current RecordCollection with the given Environment.
func (*RecordCollection) WithNewContext ¶
func (rc *RecordCollection) WithNewContext(context *types.Context) *RecordCollection
WithNewContext returns a copy of the current RecordCollection with its context replaced by the given one.
func (*RecordCollection) Wrap ¶
func (rc *RecordCollection) Wrap(modelName ...string) interface{}
Wrap returns the given RecordCollection embedded into a RecordSet Wrapper type
If modelName is defined, wrap in a modelName Wrapper type instead (use for mixins).
type RecordData ¶
A RecordData can return a ModelData object through its Underlying() method
type RecordRule ¶
type RecordRule struct { Name string Global bool Group *security.Group Condition *Condition Perms security.Permission }
A RecordRule allow to grant a group some permissions on a selection of records. - If Global is true, then the RecordRule applies to all groups - Condition is the filter to apply on the model to retrieve the records on which to allow the Perms permission.
type RecordSet ¶
type RecordSet interface { sql.Scanner fmt.Stringer // ModelName returns the name of the model of this RecordSet ModelName() string // Ids returns the ids in this set of Records Ids() []int64 // Env returns the current Environment of this RecordSet Env() Environment // Len returns the number of records in this RecordSet Len() int // IsValid returns true if this RecordSet has been initialized. IsValid() bool // IsEmpty returns true if this RecordSet has no records IsEmpty() bool // IsNotEmpty returns true if this RecordSet has at least one record IsNotEmpty() bool // Call executes the given method (as string) with the given arguments Call(string, ...interface{}) interface{} // Collection returns the underlying RecordCollection instance Collection() *RecordCollection // Get returns the value of the given fieldName for the first record of this RecordCollection. // It returns the type's zero value if the RecordCollection is empty. Get(FieldName) interface{} // Set sets field given by fieldName to the given value. If the RecordSet has several // Records, all of them will be updated. Each call to Set makes an update query in the // database. It panics if it is called on an empty RecordSet. Set(FieldName, interface{}) // T translates the given string to the language specified by // the 'lang' key of rc.Env().Context(). If for any reason the // string cannot be translated, then src is returned. // // You MUST pass a string literal as src to have it extracted automatically (and not a variable) // // The translated string will be passed to fmt.Sprintf with the optional args // before being returned. T(string, ...interface{}) string // EnsureOne panics if this Recordset is not a singleton EnsureOne() }
RecordSet identifies a type that holds a set of records of a given model.
type SQLParams ¶
type SQLParams []interface{}
An SQLParams is a list of parameters that are passed to the DB server with the query string and that will be used in the placeholders.
type Sequence ¶
type Sequence struct { JSON string Increment int64 Start int64 // contains filtered or unexported fields }
A Sequence holds the metadata of a DB sequence
There are two types of sequences: those created before bootstrap and those created after. The former will be created and updated at bootstrap and cannot be modified afterwards. The latter will be created, updated or dropped immediately.
func CreateSequence ¶
CreateSequence creates a new Sequence in the database and returns a pointer to it
func (*Sequence) Alter ¶
Alter alters this sequence by changing next number and/or increment. Set a parameter to 0 to leave it unchanged.
type WorkerFunction ¶
type WorkerFunction interface { // Run the worker function Run() // LoopPeriod is the time between each run of the worker function LoopPeriod() time.Duration }
A WorkerFunction can be executed in a loop in background every given LoopPeriod.
func NewWorkerFunction ¶
func NewWorkerFunction(fnct func(), period time.Duration) WorkerFunction
NewWorkerFunction returns a WorkerFunction from the given fnct and period
Source Files ¶
- base_model.go
- bootstrap.go
- cache.go
- conditions.go
- data.go
- database_sync.go
- db.go
- db_postgres.go
- environment.go
- fieldmap.go
- fields.go
- fields_defs.go
- init.go
- methods.go
- queries.go
- rc_computed.go
- rc_environment.go
- rc_methods.go
- rc_operations.go
- rc_related.go
- rc_security.go
- recordcollection.go
- registry.go
- security_rr.go
- tablejoins.go
- types.go
- utils.go
- worker.go
- wrapper.go