Documentation ¶
Index ¶
- Constants
- Variables
- func BootStrap()
- func BootStrapped() bool
- func ConvertLimitToInt(limit interface{}) int
- func DBClose()
- func DBConnect(driver string, params ConnectionParams)
- func DefaultValue(value interface{}) func(env Environment) interface{}
- func ExecuteInNewEnvironment(uid int64, fnct func(Environment)) (rError error)
- func FreeTransientModels()
- func LoadCSVDataFile(fileName string)
- func RegisterModelDataWrapper(modelName string, obj interface{})
- func RegisterRecordSetWrapper(modelName string, obj interface{})
- func SimulateInNewEnvironment(uid int64, fnct func(Environment)) (rError error)
- func SimulateWithDummyRecord(uid int64, data *ModelData, fnct func(RecordSet)) (rError error)
- func SyncDatabase()
- type BinaryField
- type BooleanField
- type CharField
- 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) FieldName() FieldName
- 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) Like(data interface{}) *Condition
- func (c ConditionField) Lower(data interface{}) *Condition
- func (c ConditionField) LowerOrEqual(data interface{}) *Condition
- 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
- func (c ConditionField) String() string
- type ConditionStart
- type Conditioner
- type ConnectionParams
- type Cursor
- type DateField
- type DateTimeField
- type DummyField
- type Environment
- type Field
- func (f *Field) AddContexts(value FieldContexts) *Field
- func (f *Field) FieldName() FieldName
- 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) SetNoCopy(value bool) *Field
- func (f *Field) SetOnDelete(value OnDeleteAction) *Field
- func (f *Field) SetOnchange(value Methoder) *Field
- 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) SetRequired(value bool) *Field
- func (f *Field) SetRequiredFunc(value func(Environment) (bool, Conditioner)) *Field
- func (f *Field) SetSelection(value 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) String() string
- 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 string, model *Model)
- func (fm FieldMap) FieldNames() (res []FieldNamer)
- func (fm FieldMap) Get(field string, model *Model) (interface{}, bool)
- func (fm *FieldMap) JSONized(model *Model) FieldMap
- func (fm FieldMap) Keys() (res []string)
- func (fm *FieldMap) MergeWith(other FieldMap, model *Model)
- func (fm FieldMap) MustGet(field string, model *Model) interface{}
- func (fm FieldMap) OrderedKeys() []string
- func (fm *FieldMap) RemovePK()
- func (fm *FieldMap) RemovePKIfZero()
- func (fm *FieldMap) Set(field string, value interface{}, model *Model)
- func (fm FieldMap) Underlying() FieldMap
- func (fm FieldMap) Values() (res []interface{})
- type FieldMapper
- type FieldName
- type FieldNamer
- type FieldsCollection
- type FieldsGetArgs
- type FloatField
- type GroupAggregateRow
- type HTMLField
- type IntegerField
- type Many2ManyField
- type Many2OneField
- 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) DeclareMethod(doc string, fnct interface{}) *Method
- func (m *Method) Extend(doc string, 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) AddMethod(methodName, doc string, fnct interface{}) *Method
- 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 string) *ConditionField
- func (m *Model) Fields() *FieldsCollection
- func (m *Model) FieldsGet(fields ...FieldNamer) map[string]*FieldInfo
- func (m *Model) FilteredOn(field string, condition *Condition) *Condition
- func (m *Model) InheritModel(mixInModel Modeler)
- func (m *Model) JSONizeFieldName(fieldName string) string
- func (m *Model) Methods() *MethodsCollection
- 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) Underlying() *Model
- type ModelData
- func (md *ModelData) Copy() *ModelData
- func (md *ModelData) Create(field string, related *ModelData) *ModelData
- func (md *ModelData) Get(field string) interface{}
- func (md *ModelData) Has(field string) bool
- func (md *ModelData) MarshalJSON() ([]byte, error)
- func (md *ModelData) Set(field string, value interface{}) *ModelData
- func (md *ModelData) Underlying() *ModelData
- func (md *ModelData) Unset(field string) *ModelData
- func (md ModelData) Wrap() interface{}
- type Modeler
- type OnDeleteAction
- type OnchangeParams
- type OnchangeResult
- type One2ManyField
- type One2OneField
- type Option
- type Query
- type RecordCollection
- func (rc *RecordCollection) Aggregates(fieldNames ...FieldNamer) []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()
- 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 ...string) *RecordCollection
- func (rc *RecordCollection) Get(fieldName string) interface{}
- func (rc *RecordCollection) GetRecord(externalID string) *RecordCollection
- func (rc *RecordCollection) GroupBy(fields ...FieldNamer) *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 ...string) *RecordCollection
- func (rc *RecordCollection) MethodType(methName string) reflect.Type
- func (rc *RecordCollection) Model() *Model
- func (rc *RecordCollection) ModelName() string
- func (rc *RecordCollection) NoDistinct() *RecordCollection
- 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) SearchAll() *RecordCollection
- func (rc *RecordCollection) SearchCount() int
- func (rc *RecordCollection) Set(fieldName string, value interface{})
- func (rc *RecordCollection) Sorted(less func(rs1 RecordSet, rs2 RecordSet) bool) *RecordCollection
- func (rc *RecordCollection) SortedByField(namer FieldNamer, 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 Rev2OneField
- type SQLParams
- type SelectionField
- type Sequence
- type TextField
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 Registry *modelCollection
Registry is the registry of all Model instances.
var ( // Testing is true if we are testing the framework Testing bool )
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 DBClose ¶
func DBClose()
DBClose is a wrapper around sqlx.Close It closes the connection to the database
func DBConnect ¶
func DBConnect(driver string, 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)) (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 FreeTransientModels ¶ added in v0.0.6
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 ¶ added in v0.0.6
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 ¶ added in v0.0.6
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 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 SimulateWithDummyRecord ¶ added in v0.0.6
SimulateWithDummyRecord executes the given fnct on a temporary Recordset created from the given data and rolls bac all changes afterwards.
If data contains an ID field, then the record with this ID is retrieved from the database instead of being created, and is updated with the data.
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 BinaryField ¶
type BinaryField struct { JSON string String string Help string Stored bool Required bool ReadOnly bool RequiredFunc func(Environment) (bool, Conditioner) ReadOnlyFunc func(Environment) (bool, Conditioner) InvisibleFunc func(Environment) (bool, Conditioner) Unique bool Index bool Compute Methoder Depends []string Related string NoCopy bool GoType interface{} OnChange Methoder Constraint Methoder Inverse Methoder Contexts FieldContexts Default func(Environment) interface{} }
A BinaryField is a field for storing binary data, such as images.
Clients are expected to handle binary fields as file uploads.
Binary fields are stored in the database. Consider other disk based alternatives if you have a large amount of data to store.
func (BinaryField) DeclareField ¶
func (bf BinaryField) DeclareField(fc *FieldsCollection, name string) *Field
DeclareField creates a binary field for the given FieldsCollection with the given name.
type BooleanField ¶
type BooleanField struct { JSON string String string Help string Stored bool Required bool ReadOnly bool RequiredFunc func(Environment) (bool, Conditioner) ReadOnlyFunc func(Environment) (bool, Conditioner) InvisibleFunc func(Environment) (bool, Conditioner) Unique bool Index bool Compute Methoder Depends []string Related string NoCopy bool GoType interface{} OnChange Methoder Constraint Methoder Inverse Methoder Contexts FieldContexts Default func(Environment) interface{} }
A BooleanField is a field for storing true/false values.
Clients are expected to handle boolean fields as checkboxes.
func (BooleanField) DeclareField ¶
func (bf BooleanField) DeclareField(fc *FieldsCollection, name string) *Field
DeclareField creates a boolean field for the given FieldsCollection with the given name.
type CharField ¶
type CharField struct { JSON string String string Help string Stored bool Required bool ReadOnly bool RequiredFunc func(Environment) (bool, Conditioner) ReadOnlyFunc func(Environment) (bool, Conditioner) InvisibleFunc func(Environment) (bool, Conditioner) Unique bool Index bool Compute Methoder Depends []string Related string NoCopy bool Size int GoType interface{} Translate bool OnChange Methoder Constraint Methoder Inverse Methoder Contexts FieldContexts Default func(Environment) interface{} }
A CharField is a field for storing short text. There is no default max size, but it can be forced by setting the Size value.
Clients are expected to handle Char fields as single line inputs.
func (CharField) DeclareField ¶
func (cf CharField) DeclareField(fc *FieldsCollection, name string) *Field
DeclareField creates a char field for the given FieldsCollection with the given name.
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) 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) 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) 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
func (ConditionField) String ¶
func (c ConditionField) String() string
String method for ConditionField
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 Conditioner ¶
type Conditioner interface {
Underlying() *Condition
}
A Conditioner can return a Condition object through its Underlying() method
type ConnectionParams ¶
type ConnectionParams struct { 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
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 DateField ¶
type DateField struct { JSON string String string Help string Stored bool Required bool ReadOnly bool RequiredFunc func(Environment) (bool, Conditioner) ReadOnlyFunc func(Environment) (bool, Conditioner) InvisibleFunc func(Environment) (bool, Conditioner) Unique bool Index bool Compute Methoder Depends []string Related string GroupOperator string NoCopy bool GoType interface{} OnChange Methoder Constraint Methoder Inverse Methoder Contexts FieldContexts Default func(Environment) interface{} }
A DateField is a field for storing dates without time.
Clients are expected to handle Date fields with a date picker.
func (DateField) DeclareField ¶
func (df DateField) DeclareField(fc *FieldsCollection, name string) *Field
DeclareField creates a date field for the given FieldsCollection with the given name.
type DateTimeField ¶
type DateTimeField struct { JSON string String string Help string Stored bool Required bool ReadOnly bool RequiredFunc func(Environment) (bool, Conditioner) ReadOnlyFunc func(Environment) (bool, Conditioner) InvisibleFunc func(Environment) (bool, Conditioner) Unique bool Index bool Compute Methoder Depends []string Related string GroupOperator string NoCopy bool GoType interface{} OnChange Methoder Constraint Methoder Inverse Methoder Contexts FieldContexts Default func(Environment) interface{} }
A DateTimeField is a field for storing dates with time.
Clients are expected to handle DateTime fields with a date and time picker.
func (DateTimeField) DeclareField ¶
func (df DateTimeField) DeclareField(fc *FieldsCollection, name string) *Field
DeclareField creates a datetime field for the given FieldsCollection with the given name.
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 ¶ added in v0.0.6
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 (*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 ¶ added in v0.0.12
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) 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) 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) 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) SetSelection ¶
SetSelection overrides the value of the Selection parameter 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:"-"` }
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() (res []FieldNamer)
FieldNames returns the FieldMap keys as a slice of FieldNamer. As within a FieldMap, the result can be field names or JSON names or a mix of both.
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) JSONized ¶
JSONized returns a new field map identical to this one but with all its keys switched to the JSON name of the fields
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 ¶
type FieldName string
A FieldName is a type representing field names in models.
type FieldNamer ¶
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) 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) 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 []FieldName `json:"allfields"` }
FieldsGetArgs is the args struct for the FieldsGet method
type FloatField ¶
type FloatField struct { JSON string String string Help string Stored bool Required bool ReadOnly bool RequiredFunc func(Environment) (bool, Conditioner) ReadOnlyFunc func(Environment) (bool, Conditioner) InvisibleFunc func(Environment) (bool, Conditioner) Unique bool Index bool Compute Methoder Depends []string Related string GroupOperator string NoCopy bool Digits nbutils.Digits GoType interface{} OnChange Methoder Constraint Methoder Inverse Methoder Contexts FieldContexts Default func(Environment) interface{} }
A FloatField is a field for storing decimal numbers.
func (FloatField) DeclareField ¶
func (ff FloatField) DeclareField(fc *FieldsCollection, name string) *Field
DeclareField adds this datetime field for the given FieldsCollection with the given name.
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 HTMLField ¶
type HTMLField struct { JSON string String string Help string Stored bool Required bool ReadOnly bool RequiredFunc func(Environment) (bool, Conditioner) ReadOnlyFunc func(Environment) (bool, Conditioner) InvisibleFunc func(Environment) (bool, Conditioner) Unique bool Index bool Compute Methoder Depends []string Related string NoCopy bool Size int GoType interface{} Translate bool OnChange Methoder Constraint Methoder Inverse Methoder Contexts FieldContexts Default func(Environment) interface{} }
An HTMLField is a field for storing HTML formatted strings.
Clients are expected to handle HTML fields with multi-line HTML editors.
func (HTMLField) DeclareField ¶
func (tf HTMLField) DeclareField(fc *FieldsCollection, name string) *Field
DeclareField creates a html field for the given FieldsCollection with the given name.
type IntegerField ¶
type IntegerField struct { JSON string String string Help string Stored bool Required bool ReadOnly bool RequiredFunc func(Environment) (bool, Conditioner) ReadOnlyFunc func(Environment) (bool, Conditioner) InvisibleFunc func(Environment) (bool, Conditioner) Unique bool Index bool Compute Methoder Depends []string Related string GroupOperator string NoCopy bool GoType interface{} OnChange Methoder Constraint Methoder Inverse Methoder Contexts FieldContexts Default func(Environment) interface{} }
An IntegerField is a field for storing non decimal numbers.
func (IntegerField) DeclareField ¶
func (i IntegerField) DeclareField(fc *FieldsCollection, name string) *Field
DeclareField creates a datetime field for the given FieldsCollection with the given name.
type Many2ManyField ¶
type Many2ManyField struct { JSON string String string Help string Stored bool Required bool ReadOnly bool RequiredFunc func(Environment) (bool, Conditioner) ReadOnlyFunc func(Environment) (bool, Conditioner) InvisibleFunc func(Environment) (bool, Conditioner) Index bool Compute Methoder Depends []string Related string NoCopy bool RelationModel Modeler M2MLinkModelName string M2MOurField string M2MTheirField string OnChange Methoder Constraint Methoder Filter Conditioner Inverse Methoder Default func(Environment) interface{} }
A Many2ManyField is a field for storing many-to-many relations.
Clients are expected to handle many2many fields with a table or with tags.
func (Many2ManyField) DeclareField ¶
func (mf Many2ManyField) DeclareField(fc *FieldsCollection, name string) *Field
DeclareField creates a many2many field for the given FieldsCollection with the given name.
type Many2OneField ¶
type Many2OneField struct { JSON string String string Help string Stored bool Required bool ReadOnly bool RequiredFunc func(Environment) (bool, Conditioner) ReadOnlyFunc func(Environment) (bool, Conditioner) InvisibleFunc func(Environment) (bool, Conditioner) Index bool Compute Methoder Depends []string Related string NoCopy bool RelationModel Modeler Embed bool OnDelete OnDeleteAction OnChange Methoder Constraint Methoder Filter Conditioner Inverse Methoder Contexts FieldContexts Default func(Environment) interface{} }
A Many2OneField is a field for storing many-to-one relations, i.e. the FK to another model.
Clients are expected to handle many2one fields with a combo-box.
func (Many2OneField) DeclareField ¶
func (mf Many2OneField) DeclareField(fc *FieldsCollection, name string) *Field
DeclareField creates a many2one field for the given FieldsCollection with the given name.
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) DeclareMethod ¶
DeclareMethod overrides the given Method by : - setting documentation string to doc - setting fnct as the first layer
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.
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 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) AddEmptyMethod ¶
AddEmptyMethod creates a new method withoud function layer The resulting method cannot be called until DeclareMethod is called
func (*Model) AddFields ¶
func (m *Model) AddFields(fields map[string]FieldDefinition)
AddFields adds the given fields to the 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) 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 ¶ added in v0.0.4
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 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) FieldsGet ¶
func (m *Model) FieldsGet(fields ...FieldNamer) map[string]*FieldInfo
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) 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 ¶ added in v0.0.12
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 ¶ added in v0.0.12
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) Get ¶
Get returns the value of the given field.
The field can be either its name or is JSON name.
func (*ModelData) Has ¶ added in v0.0.14
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 ¶ added in v0.0.13
MarshalJSON function for ModelData. Returns the FieldMap.
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 ¶ added in v0.0.12
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 []string `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"`
}
OnchangeResult is the result struct type of the Onchange function
type One2ManyField ¶
type One2ManyField struct { JSON string String string Help string Stored bool Required bool ReadOnly bool RequiredFunc func(Environment) (bool, Conditioner) ReadOnlyFunc func(Environment) (bool, Conditioner) InvisibleFunc func(Environment) (bool, Conditioner) Index bool Compute Methoder Depends []string Related string Copy bool RelationModel Modeler ReverseFK string OnChange Methoder Constraint Methoder Filter Conditioner Inverse Methoder Default func(Environment) interface{} }
A One2ManyField is a field for storing one-to-many relations.
Clients are expected to handle one2many fields with a table.
func (One2ManyField) DeclareField ¶
func (of One2ManyField) DeclareField(fc *FieldsCollection, name string) *Field
DeclareField creates a one2many field for the given FieldsCollection with the given name.
type One2OneField ¶
type One2OneField struct { JSON string String string Help string Stored bool Required bool ReadOnly bool RequiredFunc func(Environment) (bool, Conditioner) ReadOnlyFunc func(Environment) (bool, Conditioner) InvisibleFunc func(Environment) (bool, Conditioner) Index bool Compute Methoder Depends []string Related string NoCopy bool RelationModel Modeler Embed bool OnDelete OnDeleteAction OnChange Methoder Constraint Methoder Filter Conditioner Inverse Methoder Contexts FieldContexts Default func(Environment) interface{} }
A One2OneField is a field for storing one-to-one relations, i.e. the FK to another model with a unique constraint.
Clients are expected to handle one2one fields with a combo-box.
func (One2OneField) DeclareField ¶
func (of One2OneField) DeclareField(fc *FieldsCollection, name string) *Field
DeclareField creates a one2one field for the given FieldsCollection with the given name.
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 ¶ added in v0.0.2
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 ...FieldNamer) []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()
CheckConstraints executes the constraint method for each field defined in the given fMap with the corresponding value. 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 ...string) *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 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) 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 ...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) 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 ¶ added in v0.0.4
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 ...string) *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) NoDistinct ¶
func (rc *RecordCollection) NoDistinct() *RecordCollection
NoDistinct removes the DISTINCT keyword from this RecordSet query. By default, all queries are distinct.
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) 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 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) 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(namer FieldNamer, 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 ¶ added in v0.0.6
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 ¶ added in v0.0.12
type RecordData interface {
Underlying() *ModelData
}
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 { // 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 // 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(string) 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(string, 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 Rev2OneField ¶
type Rev2OneField struct { JSON string String string Help string Stored bool Required bool ReadOnly bool RequiredFunc func(Environment) (bool, Conditioner) ReadOnlyFunc func(Environment) (bool, Conditioner) InvisibleFunc func(Environment) (bool, Conditioner) Index bool Compute Methoder Depends []string Related string Copy bool RelationModel Modeler ReverseFK string OnChange Methoder Constraint Methoder Filter Conditioner Inverse Methoder Default func(Environment) interface{} }
A Rev2OneField is a field for storing reverse one-to-one relations, i.e. the relation on the model without FK.
Clients are expected to handle rev2one fields with a combo-box.
func (Rev2OneField) DeclareField ¶
func (rf Rev2OneField) DeclareField(fc *FieldsCollection, name string) *Field
DeclareField creates a rev2one field for the given FieldsCollection with the given name.
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 SelectionField ¶
type SelectionField struct { JSON string String string Help string Stored bool Required bool ReadOnly bool RequiredFunc func(Environment) (bool, Conditioner) ReadOnlyFunc func(Environment) (bool, Conditioner) InvisibleFunc func(Environment) (bool, Conditioner) Unique bool Index bool Compute Methoder Depends []string Related string NoCopy bool Selection types.Selection SelectionFunc func() types.Selection OnChange Methoder Constraint Methoder Inverse Methoder Contexts FieldContexts Default func(Environment) interface{} }
A SelectionField is a field for storing a value from a preset list.
Clients are expected to handle selection fields with a combo-box or radio buttons.
func (SelectionField) DeclareField ¶
func (sf SelectionField) DeclareField(fc *FieldsCollection, name string) *Field
DeclareField creates a selection field for the given FieldsCollection with the given name.
type Sequence ¶
type Sequence struct { Name string 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 TextField ¶
type TextField struct { JSON string String string Help string Stored bool Required bool ReadOnly bool RequiredFunc func(Environment) (bool, Conditioner) ReadOnlyFunc func(Environment) (bool, Conditioner) InvisibleFunc func(Environment) (bool, Conditioner) Unique bool Index bool Compute Methoder Depends []string Related string NoCopy bool Size int GoType interface{} Translate bool OnChange Methoder Constraint Methoder Inverse Methoder Contexts FieldContexts Default func(Environment) interface{} }
A TextField is a field for storing long text. There is no default max size, but it can be forced by setting the Size value.
Clients are expected to handle text fields as multi-line inputs.
func (TextField) DeclareField ¶
func (tf TextField) DeclareField(fc *FieldsCollection, name string) *Field
DeclareField creates a text field for the given FieldsCollection with the given name.
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
- wrapper.go