models

package
v0.0.0-...-fad53ba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2018 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const DBSerializationMaxRetries uint8 = 5

DBSerializationMaxRetries defines the number of time a transaction that failed due to serialization error should be retried.

View Source
const (
	ExprSep = "."
)

ExprSep define the expression separation

Variables

View Source
var Registry *modelCollection

Registry is the registry of all Model instances.

View Source
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 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 LoadCSVDataFile

func LoadCSVDataFile(fileName string)

LoadCSVDataFile loads the data of the given file into the database.

func MapToStruct

func MapToStruct(rc *RecordCollection, structPtr interface{}, fMap FieldMap)

MapToStruct populates the given structPtr with the values in fMap.

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 BinaryField

type BinaryField struct {
	JSON       string
	String     string
	Help       string
	Stored     bool
	Required   bool
	ReadOnly   bool
	Unique     bool
	Index      bool
	Compute    Methoder
	Depends    []string
	Related    string
	NoCopy     bool
	GoType     interface{}
	Translate  bool
	OnChange   Methoder
	Constraint Methoder
	Inverse    Methoder
	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
	Unique        bool
	Index         bool
	Compute       Methoder
	Depends       []string
	Related       string
	GroupOperator string
	NoCopy        bool
	GoType        interface{}
	Translate     bool
	OnChange      Methoder
	Constraint    Methoder
	Inverse       Methoder
	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
	Unique        bool
	Index         bool
	Compute       Methoder
	Depends       []string
	Related       string
	GroupOperator string
	NoCopy        bool
	Size          int
	GoType        interface{}
	Translate     bool
	OnChange      Methoder
	Constraint    Methoder
	Inverse       Methoder
	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

func (c Condition) AndCond(cond *Condition) *Condition

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

func (c Condition) AndNotCond(cond *Condition) *Condition

AndNotCond completes the current condition with an AND NOT clause between brackets : c.AndNot(cond) => (c) AND NOT (cond)

func (Condition) HasField

func (c Condition) HasField(f *Field) bool

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) IsEmpty

func (c *Condition) IsEmpty() bool

IsEmpty check the condition arguments are empty or not.

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

func (c Condition) OrCond(cond *Condition) *Condition

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

func (c Condition) OrNotCond(cond *Condition) *Condition

OrNotCond completes the current condition both with an OR NOT clause between brackets : c.OrNot(cond) => (c) OR NOT (cond)

func (Condition) Serialize

func (c Condition) Serialize() []interface{}

Serialize returns the condition as a list which mimics Odoo domains.

func (Condition) String

func (c Condition) String() string

String method for the Condition. Recursively print all predicates.

func (Condition) Underlying

func (c Condition) Underlying() *Condition

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

func (c *Cursor) Execute(query string, args ...interface{}) sql.Result

Execute a query without returning any rows. It panics in case of error. The args are for any placeholder parameters in the query.

func (*Cursor) Get

func (c *Cursor) Get(dest interface{}, query string, args ...interface{})

Get queries a row into the database and maps the result into dest. The query must return only one row. Get panics on errors

func (*Cursor) Select

func (c *Cursor) Select(dest interface{}, query string, args ...interface{})

Select queries multiple rows and map the result into dest which must be a slice. Select panics on errors.

type DateField

type DateField struct {
	JSON          string
	String        string
	Help          string
	Stored        bool
	Required      bool
	ReadOnly      bool
	Unique        bool
	Index         bool
	Compute       Methoder
	Depends       []string
	Related       string
	GroupOperator string
	NoCopy        bool
	GoType        interface{}
	Translate     bool
	OnChange      Methoder
	Constraint    Methoder
	Inverse       Methoder
	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
	Unique        bool
	Index         bool
	Compute       Methoder
	Depends       []string
	Related       string
	GroupOperator string
	NoCopy        bool
	GoType        interface{}
	Translate     bool
	OnChange      Methoder
	Constraint    Methoder
	Inverse       Methoder
	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) 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

func (f *Field) GrantAccess(group *security.Group, perm security.Permission) *Field

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

func (f *Field) RevokeAccess(group *security.Group, perm security.Permission) *Field

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

func (f *Field) SetCompute(value Methoder) *Field

SetCompute overrides the value of the Compute parameter of this Field

func (*Field) SetConstraint

func (f *Field) SetConstraint(value Methoder) *Field

SetConstraint overrides the value of the Constraint 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

func (f *Field) SetDepends(value []string) *Field

SetDepends overrides the value of the Depends parameter of this Field

func (*Field) SetDigits

func (f *Field) SetDigits(value nbutils.Digits) *Field

SetDigits overrides the value of the Digits parameter of this Field

func (*Field) SetEmbed

func (f *Field) SetEmbed(value bool) *Field

SetEmbed overrides the value of the Embed parameter of this Field

func (*Field) SetFilter

func (f *Field) SetFilter(value Conditioner) *Field

SetFilter overrides the value of the Filter parameter of this Field

func (*Field) SetGroupOperator

func (f *Field) SetGroupOperator(value string) *Field

SetGroupOperator overrides the value of the GroupOperator parameter of this Field

func (*Field) SetHelp

func (f *Field) SetHelp(value string) *Field

SetHelp overrides the value of the Help parameter of this Field

func (*Field) SetIndex

func (f *Field) SetIndex(value bool) *Field

SetIndex overrides the value of the Index parameter of this Field

func (*Field) SetInverse

func (f *Field) SetInverse(value Methoder) *Field

SetInverse overrides the value of the Inverse parameter of this Field

func (*Field) SetNoCopy

func (f *Field) SetNoCopy(value bool) *Field

SetNoCopy overrides the value of the NoCopy 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

func (f *Field) SetOnchange(value Methoder) *Field

SetOnchange overrides the value of the Onchange parameter of this Field

func (*Field) SetReadOnly

func (f *Field) SetReadOnly(value bool) *Field

SetReadOnly overrides the value of the ReadOnly parameter of this Field

func (*Field) SetRelated

func (f *Field) SetRelated(value string) *Field

SetRelated overrides the value of the Related parameter of this Field

func (*Field) SetRequired

func (f *Field) SetRequired(value bool) *Field

SetRequired overrides the value of the Required parameter of this Field

func (*Field) SetSelection

func (f *Field) SetSelection(value types.Selection) *Field

SetSelection overrides the value of the Selection parameter of this Field

func (*Field) SetSize

func (f *Field) SetSize(value int) *Field

SetSize overrides the value of the Size parameter of this Field

func (*Field) SetStored

func (f *Field) SetStored(value bool) *Field

SetStored overrides the value of the Stored parameter of this Field

func (*Field) SetString

func (f *Field) SetString(value string) *Field

SetString overrides the value of the String parameter of this Field

func (*Field) SetTranslate

func (f *Field) SetTranslate(value bool) *Field

SetTranslate overrides the value of the Translate parameter of this Field

func (*Field) SetUnique

func (f *Field) SetUnique(value bool) *Field

SetUnique overrides the value of the Unique parameter of this Field

func (*Field) UpdateSelection

func (f *Field) UpdateSelection(value types.Selection) *Field

UpdateSelection updates the value of the Selection parameter of this Field with the given value. Existing keys are overridden.

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:"-"`
}

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) Copy

func (fm FieldMap) Copy() FieldMap

Copy returns a shallow copy of this FieldMap

func (*FieldMap) Delete

func (fm *FieldMap) Delete(field string, model *Model)

Delete removes the given field from this FieldMap. Calling Del on a non existent field is a no op.

func (FieldMap) FieldMap

func (fm FieldMap) FieldMap(fields ...FieldNamer) FieldMap

FieldMap returns the object converted to a FieldMap i.e. itself

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

func (fm FieldMap) Get(field string, model *Model) (interface{}, bool)

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

func (fm *FieldMap) JSONized(model *Model) FieldMap

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) Keys

func (fm FieldMap) Keys() (res []string)

Keys returns the FieldMap keys as a slice of strings

func (*FieldMap) MergeWith

func (fm *FieldMap) MergeWith(other FieldMap, model *Model)

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

func (fm FieldMap) MustGet(field string, model *Model) interface{}

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) 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

func (fm *FieldMap) Set(field string, value interface{}, model *Model)

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) SubstituteKeys

func (fm *FieldMap) SubstituteKeys(substs []KeySubstitution)

SubstituteKeys changes the column names of the given field map with the given substitutions.

func (FieldMap) Values

func (fm FieldMap) Values() (res []interface{})

Values returns the FieldMap values as a slice of interface{}

type FieldMapper

type FieldMapper interface {
	// FieldMap returns the object converted to a FieldMap.
	//
	// If this is a struct, only non zero fields will be added to the result.
	// To put additional fields with zero value in the map, specify them in fields.
	//
	// If this is already a FieldMap, then fields are ignored and the map is
	// returned as is.
	FieldMap(fields ...FieldNamer) 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.

func (FieldName) FieldName

func (fn FieldName) FieldName() FieldName

FieldName makes a FieldName instance a FieldNamer

func (FieldName) String

func (fn FieldName) String() string

String function for FieldName

type FieldNamer

type FieldNamer interface {
	fmt.Stringer
	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

type FieldsCollection struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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
	Unique        bool
	Index         bool
	Compute       Methoder
	Depends       []string
	Related       string
	GroupOperator string
	NoCopy        bool
	Digits        nbutils.Digits
	GoType        interface{}
	Translate     bool
	OnChange      Methoder
	Constraint    Methoder
	Inverse       Methoder
	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

type GroupAggregateRow struct {
	Values    FieldMap
	Count     int
	Condition *Condition
}

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
	Unique        bool
	Index         bool
	Compute       Methoder
	Depends       []string
	Related       string
	GroupOperator string
	NoCopy        bool
	Size          int
	GoType        interface{}
	Translate     bool
	OnChange      Methoder
	Constraint    Methoder
	Inverse       Methoder
	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
	Unique        bool
	Index         bool
	Compute       Methoder
	Depends       []string
	Related       string
	GroupOperator string
	NoCopy        bool
	GoType        interface{}
	Translate     bool
	OnChange      Methoder
	Constraint    Methoder
	Inverse       Methoder
	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 KeySubstitution

type KeySubstitution struct {
	Orig string
	New  string
	Keep bool
}

KeySubstitution defines a key substitution in a FieldMap

type Many2ManyField

type Many2ManyField struct {
	JSON             string
	String           string
	Help             string
	Stored           bool
	Required         bool
	ReadOnly         bool
	Index            bool
	Compute          Methoder
	Depends          []string
	Related          string
	NoCopy           bool
	RelationModel    Modeler
	M2MLinkModelName string
	M2MOurField      string
	M2MTheirField    string
	Translate        bool
	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
	Index         bool
	Compute       Methoder
	Depends       []string
	Related       string
	NoCopy        bool
	RelationModel Modeler
	Embed         bool
	Translate     bool
	OnDelete      OnDeleteAction
	OnChange      Methoder
	Constraint    Methoder
	Filter        Conditioner
	Inverse       Methoder
	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

type Method struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

A Method is a definition of a model's method

func (*Method) AllowGroup

func (m *Method) AllowGroup(group *security.Group, callers ...Methoder) *Method

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

func (m *Method) DeclareMethod(doc string, fnct interface{}) *Method

DeclareMethod overrides the given Method by : - setting documentation string to doc - setting fnct as the first layer

func (*Method) Extend

func (m *Method) Extend(doc string, fnct interface{}) *Method

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) RevokeGroup

func (m *Method) RevokeGroup(group *security.Group) *Method

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

func (m *Method) Underlying() *Method

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 methods of this collection This method must be called before bootstrap, or will have no effect.

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 methods given by AllowAllToGroup It simply removes the group from the groups allowed on every method, but does not change any specific permission granted on a per method basis. This method must be called before bootstrap, or will have no effect.

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

func NewManualModel(name string) *Model

NewManualModel creates a model whose table is not automatically generated in the database. This is particularly useful for SQL view models.

func NewMixinModel

func NewMixinModel(name string) *Model

NewMixinModel creates a new mixin model with the given name and extends it with the given struct pointer.

func NewModel

func NewModel(name string) *Model

NewModel creates a new model with the given name and extends it with the given struct pointer.

func NewTransientModel

func NewTransientModel(name string) *Model

NewTransientModel creates a new mixin model with the given name and extends it with the given struct pointers.

func (*Model) AddEmptyMethod

func (m *Model) AddEmptyMethod(methodName string) *Method

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

func (m *Model) AddMethod(methodName, doc string, fnct interface{}) *Method

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

func (m *Model) AddSQLConstraint(name, sql, errorString string)

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) 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

func (m *Model) 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

func (*Model) InheritModel

func (m *Model) InheritModel(mixInModel Modeler)

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

func (m *Model) JSONizeFieldName(fieldName string) string

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

func (m *Model) RemoveRecordRule(name string)

RemoveRecordRule removes the Record Rule with the given name from the rule registry of the given model.

func (*Model) RemoveSQLConstraint

func (m *Model) RemoveSQLConstraint(name string)

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

func (m *Model) SetDefaultOrder(orders ...string)

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

func (m *Model) Underlying() *Model

Underlying returns the underlying Model data object, i.e. itself

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   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 OnchangeResult

type OnchangeResult struct {
	Value FieldMapper `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
	Index         bool
	Compute       Methoder
	Depends       []string
	Related       string
	NoCopy        bool
	RelationModel Modeler
	ReverseFK     string
	Translate     bool
	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
	Index         bool
	Compute       Methoder
	Depends       []string
	Related       string
	NoCopy        bool
	RelationModel Modeler
	Embed         bool
	Translate     bool
	OnDelete      OnDeleteAction
	OnChange      Methoder
	Constraint    Methoder
	Filter        Conditioner
	Inverse       Methoder
	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
	// 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 Doxa 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) 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) 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(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) 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) 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 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. 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) 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 given src 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.

type RecordRef

type RecordRef struct {
	ModelName string
	ID        int64
}

A RecordRef uniquely identifies a Record by giving its model and ID.

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
	// Collection returns the underlying RecordCollection instance
	Collection() *RecordCollection
}

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
	Index         bool
	Compute       Methoder
	Depends       []string
	Related       string
	NoCopy        bool
	RelationModel Modeler
	ReverseFK     string
	Translate     bool
	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.

func (SQLParams) Extend

func (p SQLParams) Extend(p2 SQLParams) SQLParams

Extend returns a new SQLParams with both params of this SQLParams and of p2 SQLParams.

type SelectionField

type SelectionField struct {
	JSON       string
	String     string
	Help       string
	Stored     bool
	Required   bool
	ReadOnly   bool
	Unique     bool
	Index      bool
	Compute    Methoder
	Depends    []string
	Related    string
	NoCopy     bool
	Selection  types.Selection
	Translate  bool
	OnChange   Methoder
	Constraint Methoder
	Inverse    Methoder
	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
}

A Sequence holds the metadata of a DB sequence

func NewSequence

func NewSequence(name string) *Sequence

NewSequence creates a new Sequence and returns a pointer to it

func (*Sequence) NextValue

func (s *Sequence) NextValue() int64

NextValue returns the next value of this Sequence

type TextField

type TextField struct {
	JSON          string
	String        string
	Help          string
	Stored        bool
	Required      bool
	ReadOnly      bool
	Unique        bool
	Index         bool
	Compute       Methoder
	Depends       []string
	Related       string
	GroupOperator string
	NoCopy        bool
	Size          int
	GoType        interface{}
	Translate     bool
	OnChange      Methoder
	Constraint    Methoder
	Inverse       Methoder
	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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL