Documentation ¶
Index ¶
- Constants
- Variables
- func BootStrap()
- func ConvertLimitToInt(limit interface{}) int
- func DBClose()
- func DBConnect(driver, connData string)
- func ExecuteInNewEnvironment(uid int64, fnct func(Environment)) (rError error)
- func LoadCSVDataFile(fileName string)
- func SimulateInNewEnvironment(uid int64, fnct func(Environment)) (rError error)
- func SyncDatabase()
- 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) 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) Serialize() []interface{}
- type ConditionField
- func (c ConditionField) AddOperator(op operator.Operator, data interface{}) *Condition
- func (c ConditionField) ChildOf(data interface{}) *Condition
- func (c ConditionField) Equals(data interface{}) *Condition
- func (c ConditionField) FieldName() FieldName
- func (c ConditionField) Greater(data interface{}) *Condition
- func (c ConditionField) GreaterOrEqual(data interface{}) *Condition
- func (c ConditionField) ILike(data interface{}) *Condition
- func (c ConditionField) ILikePattern(data interface{}) *Condition
- func (c ConditionField) In(data interface{}) *Condition
- func (c ConditionField) Like(data interface{}) *Condition
- func (c ConditionField) LikePattern(data interface{}) *Condition
- func (c ConditionField) Lower(data interface{}) *Condition
- func (c ConditionField) LowerOrEqual(data interface{}) *Condition
- func (c ConditionField) NotEquals(data interface{}) *Condition
- func (c ConditionField) NotILike(data interface{}) *Condition
- func (c ConditionField) NotIn(data interface{}) *Condition
- func (c ConditionField) NotLike(data interface{}) *Condition
- type ConditionStart
- type Cursor
- type Environment
- type Field
- func (f *Field) GrantAccess(group *security.Group, perm security.Permission) *Field
- func (f *Field) RevokeAccess(group *security.Group, perm security.Permission) *Field
- func (f *Field) SetCompute(value string) *Field
- func (f *Field) SetDefault(value func(Environment, FieldMap) interface{}) *Field
- func (f *Field) SetDepends(value []string) *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) SetNoCopy(value bool) *Field
- func (f *Field) SetRelated(value string) *Field
- func (f *Field) SetRequired(value bool) *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
- type FieldInfo
- type FieldMap
- type FieldMapper
- type FieldName
- type FieldNamer
- type FieldsCollection
- type FieldsGetArgs
- type FloatFieldParams
- type ForeignKeyFieldParams
- type GroupAggregateRow
- type KeySubstitution
- type Many2ManyFieldParams
- type Method
- type MethodsCollection
- type Model
- func (m *Model) AddBinaryField(name string, params SimpleFieldParams) *Field
- func (m *Model) AddBooleanField(name string, params SimpleFieldParams) *Field
- func (m *Model) AddCharField(name string, params StringFieldParams) *Field
- func (m *Model) AddDateField(name string, params SimpleFieldParams) *Field
- func (m *Model) AddDateTimeField(name string, params SimpleFieldParams) *Field
- func (m *Model) AddFloatField(name string, params FloatFieldParams) *Field
- func (m *Model) AddHTMLField(name string, params StringFieldParams) *Field
- func (m *Model) AddIntegerField(name string, params SimpleFieldParams) *Field
- func (m *Model) AddMany2ManyField(name string, params Many2ManyFieldParams) *Field
- func (m *Model) AddMany2OneField(name string, params ForeignKeyFieldParams) *Field
- func (m *Model) AddMethod(methodName, doc string, fnct interface{}) *Method
- func (m *Model) AddOne2ManyField(name string, params ReverseFieldParams) *Field
- func (m *Model) AddOne2OneField(name string, params ForeignKeyFieldParams) *Field
- func (m *Model) AddRecordRule(rule *RecordRule)
- func (m *Model) AddRev2OneField(name string, params ReverseFieldParams) *Field
- func (m *Model) AddSelectionField(name string, params SelectionFieldParams) *Field
- func (m *Model) AddTextField(name string, params StringFieldParams) *Field
- func (m *Model) Create(env Environment, data interface{}) RecordCollection
- func (m *Model) Field(name string) *ConditionField
- func (m *Model) Fields() *FieldsCollection
- func (m *Model) FilteredOn(field string, condition *Condition) *Condition
- func (m *Model) InheritModel(mixInModel *Model)
- func (m *Model) JSONizeFieldName(fieldName string) string
- func (m *Model) Methods() *MethodsCollection
- func (m *Model) RemoveRecordRule(name string)
- func (m *Model) Search(env Environment, cond *Condition) RecordCollection
- type OnDeleteAction
- type OnchangeParams
- type Option
- type Query
- type RecordCollection
- func (rc RecordCollection) Aggregates(fieldNames ...FieldNamer) []GroupAggregateRow
- func (rc RecordCollection) All(structSlicePtr interface{})
- func (rc RecordCollection) Call(methName string, args ...interface{}) interface{}
- func (rc RecordCollection) CallMulti(methName string, args ...interface{}) []interface{}
- func (rc RecordCollection) Collection() RecordCollection
- func (rc RecordCollection) EnsureOne()
- func (rc RecordCollection) Env() Environment
- func (rc RecordCollection) Fetch() RecordCollection
- func (rc RecordCollection) FetchAll() RecordCollection
- func (rc RecordCollection) First(structPtr interface{})
- func (rc RecordCollection) Get(fieldName string) interface{}
- func (rc RecordCollection) GroupBy(fields ...FieldNamer) RecordCollection
- func (rc RecordCollection) Ids() []int64
- func (rc RecordCollection) IsEmpty() bool
- func (rc RecordCollection) Len() int
- func (rc RecordCollection) Limit(limit int) RecordCollection
- func (rc RecordCollection) Load(fields ...string) 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) Search(cond *Condition) RecordCollection
- func (rc RecordCollection) SearchCount() int
- func (rc RecordCollection) Set(fieldName string, value interface{})
- func (rc RecordCollection) String() string
- func (rc RecordCollection) Sudo(userId ...int64) RecordCollection
- func (rc RecordCollection) Super() RecordCollection
- func (rc RecordCollection) Union(other RecordCollection) 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
- type RecordRef
- type RecordRule
- type RecordSet
- type ReverseFieldParams
- type SQLParams
- type SelectionFieldParams
- type Sequence
- type SimpleFieldParams
- type StringFieldParams
Constants ¶
const DBSerializationMaxRetries uint8 = 5
DBSerializationMaxRetries defines the number of time a transaction that failed due to serialization error should be retried.
const (
ExprSep = "."
)
ExprSep define the expression separation
Variables ¶
var Registry *modelCollection
Registry is the registry of all Model instances.
var ( // Testing is true if we are testing the framework Testing bool )
Functions ¶
func BootStrap ¶
func BootStrap()
BootStrap freezes model, fields and method caches and syncs the database structure with the declared data.
func ConvertLimitToInt ¶
func ConvertLimitToInt(limit interface{}) int
ConvertLimitToInt converts the given limit as interface{} to an int
func DBClose ¶
func DBClose()
DBClose is a wrapper around sqlx.Close It closes the connection to the database
func DBConnect ¶
func DBConnect(driver, connData string)
DBConnect is a wrapper around sqlx.MustConnect It connects to a database using the given driver and connection data.
func ExecuteInNewEnvironment ¶
func ExecuteInNewEnvironment(uid int64, fnct func(Environment)) (rError 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 LoadCSVDataFile ¶
func LoadCSVDataFile(fileName string)
LoadCSVDataFile loads the data of the given file into the database.
func SimulateInNewEnvironment ¶
func SimulateInNewEnvironment(uid int64, fnct func(Environment)) (rError 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 SyncDatabase ¶
func SyncDatabase()
SyncDatabase creates or updates database tables with the data in the model registry
Types ¶
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
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
func (Condition) AndNotCond ¶
AndNotCond completes the current condition with an AND NOT clause between brackets : c.AndNot(cond) => c AND NOT (cond)
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
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
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) Equals ¶
func (c ConditionField) Equals(data interface{}) *Condition
Equals appends the '=' operator to the current Condition
func (ConditionField) FieldName ¶
func (c ConditionField) FieldName() FieldName
FieldName returns the field name of this ConditionField
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) ILike ¶
func (c ConditionField) ILike(data interface{}) *Condition
ILike appends the 'ILIKE %%' operator to the current Condition
func (ConditionField) ILikePattern ¶
func (c ConditionField) ILikePattern(data interface{}) *Condition
ILikePattern 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) Like ¶
func (c ConditionField) Like(data interface{}) *Condition
Like appends the 'LIKE %%' operator to the current Condition
func (ConditionField) LikePattern ¶
func (c ConditionField) LikePattern(data interface{}) *Condition
LikePattern 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) NotEquals ¶
func (c ConditionField) NotEquals(data interface{}) *Condition
NotEquals appends the '!=' operator to the current Condition
func (ConditionField) NotILike ¶
func (c ConditionField) NotILike(data interface{}) *Condition
NotILike 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
func (ConditionField) NotLike ¶
func (c ConditionField) NotLike(data interface{}) *Condition
NotLike appends the 'NOT LIKE %%' 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 string) *ConditionField
Field adds a field path (dot separated) to this condition
func (ConditionStart) FilteredOn ¶
func (cs ConditionStart) FilteredOn(field string, condition *Condition) *Condition
FilteredOn adds a condition with a table join on the given field and filters the result with the given condition
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 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) 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 (*Field) GrantAccess ¶
GrantAccess grants the given perm to the given group on the given field of model. Only security.Read and security.Write permissions are taken into account by this function, others are discarded.
func (*Field) RevokeAccess ¶
RevokeAccess denies the given perm to the given group on the given field of model. Only security.Read and security.Write permissions are taken into account by this function, others are discarded.
func (*Field) SetCompute ¶
SetCompute overrides the value of the Compute parameter of this Field
func (*Field) SetDefault ¶
func (f *Field) SetDefault(value func(Environment, FieldMap) 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) SetGroupOperator ¶
SetGroupOperator overrides the value of the GroupOperator parameter of this Field
func (*Field) SetRelated ¶
SetRelated overrides the value of the Related parameter of this Field
func (*Field) SetRequired ¶
SetRequired overrides the value of the Required parameter of this Field
func (*Field) SetTranslate ¶
SetTranslate overrides the value of the Translate parameter of this Field
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"` Domain *Condition `json:"domain"` Relation string `json:"relation"` }
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) 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) SubstituteKeys ¶
func (fm *FieldMap) SubstituteKeys(substs []KeySubstitution)
SubstituteKeys changes the column names of the given field map with the given substitutions.
type FieldMapper ¶
type FieldMapper interface { // FieldMap returns the object converted to a FieldMap FieldMap() FieldMap }
A FieldMapper is an object that can convert itself into a FieldMap
type FieldNamer ¶
type FieldNamer interface {
FieldName() FieldName
}
A FieldNamer is a type that can yield a FieldName through its FieldName() method
func ConvertToFieldNameSlice ¶
func ConvertToFieldNameSlice(fields []string) []FieldNamer
ConvertToFieldNameSlice converts the given string fields slice into a slice of FieldNames
type FieldsCollection ¶
FieldsCollection is a collection of Field instances in a 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 { // list of fields to document, all if empty or not provided Fields []FieldName `json:"allfields"` }
FieldsGetArgs is the args struct for the FieldsGet method
type FloatFieldParams ¶
type FloatFieldParams struct { JSON string String string Help string Stored bool Required bool Unique bool Index bool Compute string Depends []string Related string GroupOperator string NoCopy bool Digits types.Digits GoType interface{} Translate bool Default func(Environment, FieldMap) interface{} }
A FloatFieldParams holds all the possible options for a float field
type ForeignKeyFieldParams ¶
type ForeignKeyFieldParams struct { JSON string String string Help string Stored bool Required bool Index bool Compute string Depends []string Related string NoCopy bool RelationModel string Embed bool Translate bool OnDelete OnDeleteAction Default func(Environment, FieldMap) interface{} }
A ForeignKeyFieldParams holds all the possible options for a many2one or one2one field
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 KeySubstitution ¶
KeySubstitution defines a key substitution in a FieldMap
type Many2ManyFieldParams ¶
type Many2ManyFieldParams struct { JSON string String string Help string Stored bool Required bool Index bool Compute string Depends []string Related string NoCopy bool RelationModel string M2MLinkModelName string M2MOurField string M2MTheirField string Translate bool Default func(Environment, FieldMap) interface{} }
A Many2ManyFieldParams holds all the possible options for a many2many field
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.
type MethodsCollection ¶
type MethodsCollection struct {
// contains filtered or unexported fields
}
MethodsCollection is the Method collection
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.
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 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 and extends it with the given struct pointer.
func NewModel ¶
NewModel creates a new model with the given name and extends it with the given struct pointer.
func NewTransientModel ¶
NewTransientModel creates a new mixin model with the given name and extends it with the given struct pointers.
func (*Model) AddBinaryField ¶
func (m *Model) AddBinaryField(name string, params SimpleFieldParams) *Field
AddBinaryField adds a database stored binary field with the given name to this Model. Binary fields are mapped to string type in go.
func (*Model) AddBooleanField ¶
func (m *Model) AddBooleanField(name string, params SimpleFieldParams) *Field
AddBooleanField adds a boolean field with the given name to this Model.
func (*Model) AddCharField ¶
func (m *Model) AddCharField(name string, params StringFieldParams) *Field
AddCharField adds a single line text field with the given name to this Model. Char fields are mapped to strings in go. There is no limitation in the size of the string, unless specified in the parameters.
func (*Model) AddDateField ¶
func (m *Model) AddDateField(name string, params SimpleFieldParams) *Field
AddDateField adds a date field with the given name to this Model. Date fields are mapped to Date type.
func (*Model) AddDateTimeField ¶
func (m *Model) AddDateTimeField(name string, params SimpleFieldParams) *Field
AddDateTimeField adds a datetime field with the given name to this Model. DateTime fields are mapped to DateTime type.
func (*Model) AddFloatField ¶
func (m *Model) AddFloatField(name string, params FloatFieldParams) *Field
AddFloatField adds a float field with the given name to this Model. Float fields are mapped to go float64 type and stored as numeric in database.
func (*Model) AddHTMLField ¶
func (m *Model) AddHTMLField(name string, params StringFieldParams) *Field
AddHTMLField adds an html field with the given name to this Model. HTML fields are mapped to string type in go.
func (*Model) AddIntegerField ¶
func (m *Model) AddIntegerField(name string, params SimpleFieldParams) *Field
AddIntegerField adds an integer field with the given name to this Model. Integer fields are mapped to int64 type in go.
func (*Model) AddMany2ManyField ¶
func (m *Model) AddMany2ManyField(name string, params Many2ManyFieldParams) *Field
AddMany2ManyField adds a many2many field with the given name to this Model.
func (*Model) AddMany2OneField ¶
func (m *Model) AddMany2OneField(name string, params ForeignKeyFieldParams) *Field
AddMany2OneField adds a many2one field with the given name to this Model.
func (*Model) AddMethod ¶
AddMethod creates a new method on given model name and adds the given fnct as first layer for this method. Given fnct function must have a RecordSet as first argument. It returns a pointer to the newly created Method instance.
func (*Model) AddOne2ManyField ¶
func (m *Model) AddOne2ManyField(name string, params ReverseFieldParams) *Field
AddOne2ManyField adds a one2many field with the given name to this Model.
func (*Model) AddOne2OneField ¶
func (m *Model) AddOne2OneField(name string, params ForeignKeyFieldParams) *Field
AddOne2OneField adds a one2one field with the given name to this 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) AddRev2OneField ¶
func (m *Model) AddRev2OneField(name string, params ReverseFieldParams) *Field
AddRev2OneField adds a rev2one field with the given name to this Model.
func (*Model) AddSelectionField ¶
func (m *Model) AddSelectionField(name string, params SelectionFieldParams) *Field
AddSelectionField adds a selection field with the given name to this Model.
func (*Model) AddTextField ¶
func (m *Model) AddTextField(name string, params StringFieldParams) *Field
AddTextField adds a multi line text field with the given name to this Model. Text fields are mapped to strings in go. There is no limitation in the size of the string, unless specified in the parameters.
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 string) *ConditionField
Field starts a condition on this model
func (*Model) Fields ¶
func (m *Model) Fields() *FieldsCollection
Fields returns the fields collection of this model
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) 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) Search ¶
func (m *Model) Search(env Environment, cond *Condition) RecordCollection
Search searches the database and returns records matching the given condition.
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 FieldMap `json:"values"` Fields []string `json:"field_name"` Onchange map[string]string `json:"field_onchange"` }
OnchangeParams is the args struct 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 // 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 YEP 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 (RecordCollection) Aggregates ¶
func (rc RecordCollection) Aggregates(fieldNames ...FieldNamer) []GroupAggregateRow
Aggregates returns the result of this RecordCollection query, which must by a grouped query.
func (RecordCollection) All ¶
func (rc RecordCollection) All(structSlicePtr interface{})
All fetches a copy of all records of the RecordCollection and populates structSlicePtr.
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) Collection ¶
func (rc RecordCollection) Collection() RecordCollection
Collection returns the underlying RecordCollection instance i.e. itself
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) 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) FetchAll ¶
func (rc RecordCollection) FetchAll() RecordCollection
FetchAll returns a 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) First ¶
func (rc RecordCollection) First(structPtr interface{})
First populates structPtr with a copy of the first Record of the RecordCollection. structPtr must a pointer to a struct.
func (RecordCollection) Get ¶
func (rc RecordCollection) Get(fieldName string) 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) GroupBy ¶
func (rc RecordCollection) GroupBy(fields ...FieldNamer) 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) IsEmpty ¶
func (rc RecordCollection) IsEmpty() bool
IsEmpty returns true if rc is an empty RecordCollection
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 ...string) RecordCollection
Load query all data of the RecordCollection and store in cache. fields are the fields to retrieve in the expression 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. Non-DB fields must be explicitly given in fields to be retrieved.
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) 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) 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 string, 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) String ¶
func (rc RecordCollection) String() string
String returns the string representation of a RecordSet
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) Union ¶
func (rc RecordCollection) Union(other RecordCollection) 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.
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.
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 { // 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 // Collection returns the underlying RecordCollection instance Collection() RecordCollection }
RecordSet identifies a type that holds a set of records of a given model.
type ReverseFieldParams ¶
type ReverseFieldParams struct { JSON string String string Help string Stored bool Required bool Index bool Compute string Depends []string Related string NoCopy bool RelationModel string ReverseFK string Translate bool Default func(Environment, FieldMap) interface{} }
A ReverseFieldParams holds all the possible options for a one2many or rev2one field
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 SelectionFieldParams ¶
type SelectionFieldParams struct { JSON string String string Help string Stored bool Required bool Unique bool Index bool Compute string Depends []string Related string NoCopy bool Selection types.Selection Translate bool Default func(Environment, FieldMap) interface{} }
A SelectionFieldParams holds all the possible options for a selection field
type Sequence ¶
A Sequence holds the metadata of a DB sequence
func NewSequence ¶
NewSequence creates a new Sequence and returns a pointer to it
type SimpleFieldParams ¶
type SimpleFieldParams struct { JSON string String string Help string Stored bool Required bool Unique bool Index bool Compute string Depends []string Related string GroupOperator string NoCopy bool GoType interface{} Translate bool Default func(Environment, FieldMap) interface{} }
A SimpleFieldParams holds all the possible options for a simple (not relational) field
type StringFieldParams ¶
type StringFieldParams struct { JSON string String string Help string Stored bool Required bool Unique bool Index bool Compute string Depends []string Related string GroupOperator string NoCopy bool Size int GoType interface{} Translate bool Default func(Environment, FieldMap) interface{} }
A StringFieldParams holds all the possible options for a string field
Source Files ¶
- base_model.go
- bootstrap.go
- cache.go
- conditions.go
- data.go
- db.go
- db_postgres.go
- environment.go
- fields.go
- fields_defs.go
- init.go
- methods.go
- queries.go
- rc_computed.go
- rc_environment.go
- rc_methods.go
- rc_related.go
- rc_security.go
- recordcollection.go
- registry.go
- security_acl.go
- security_rr.go
- tablejoins.go
- types.go
- utils.go