Documentation ¶
Overview ¶
Package model defines structures that are shared through out ngorm. They provide the base building blocks for ngorm abstractions.
Index ¶
- Constants
- func ParseFieldStructForDialect(field *StructField) (fieldValue reflect.Value, sqlType string, size int, additionalType string)
- func ParseTagSetting(tags reflect.StructTag) map[string]string
- type Expr
- type Field
- type JoinTableForeignKey
- type JoinTableHandler
- type JoinTableSource
- type Model
- type Relationship
- type SQLCommon
- type SQLCommonWrapper
- type SafeStructsMap
- type Scope
- type Search
- type SearchPreload
- type Struct
- type StructField
Constants ¶
const ( OrderByPK = "ngorm:order_by_primary_key" QueryDestination = "ngorm:query_destination" QueryOption = "ngorm:query_option" Query = "ngorm:query" HookAfterQuery = "ngorm:query_after" HookQuerySQL = "ngorm:query_sql_hook" HookQueryExec = "ngorm:query_sql_exec" HookAfterFindQuery = "ngorm:query_after_find" HookBeforeCreate = "ngorm:before_create_hook" HookBeforeSave = "ngorm:before_save_hook" Create = "ngorm:create" HookCreateExec = "ngorm:create_exec" BeforeCreate = "ngorm:before_create" AfterCreate = "ngorm:after_create" HookAfterCreate = "ngorm:after_create" HookAfterSave = "ngorm:after_save_hook" UpdateAttrs = "ngorm:update_attrs" TableOptions = "ngorm:table_options" HookSaveBeforeAss = "ngorm:save_before_associations" HookUpdateTimestamp = "ngorm:update_time_stamp" BlankColWithValue = "ngorm:blank_columns_with_default_value" InsertOptions = "ngorm:insert_option" UpdateColumn = "ngorm:update_column" HookBeforeUpdate = "ngorm:before_update_hook" HookAfterUpdate = "ngorm:after_update_hook" UpdateInterface = "ngorm:update_interface" BeforeUpdate = "ngorm:before_update" AfterUpdate = "ngorm:after_update" HookAssignUpdatingAttrs = "ngorm:assign_updating_attrs_hook" HookCreateSQL = "ngorm:create_sql" UpdateOptions = "ngorm:update_option" Update = "ngorm:update" HookUpdateSQL = "ngorm:update_sql_hook" HookUpdateExec = "ngorm:update_exec_hook" IgnoreProtectedAttrs = "ngorm:ignore_protected_attrs" DeleteOption = "ngorm:delete_options" BeforeDelete = "ngorm:before_delete" HookBeforeDelete = "ngorm:before_delete_hook" AfterDelete = "ngorm:after_delete" HookAfterDelete = "ngorm:after_delete_hook" Delete = "ngorm:delete" DeleteSQL = "ngorm:delete_sql" SaveAssociations = "ngorm:save_associations" Preload = "ngorm:preload" HookSaveAfterAss = "ngorm:save_after_association" AssociationSource = "ngorm:association:source" )
All important keys
Variables ¶
This section is empty.
Functions ¶
func ParseFieldStructForDialect ¶
func ParseFieldStructForDialect(field *StructField) (fieldValue reflect.Value, sqlType string, size int, additionalType string)
ParseFieldStructForDialect pases metadatab enough to be used by dialects. The values returned are useful for implementing the DataOf method of the Dialect interface.
The fieldValue returned is the value of the field. The sqlType value returned is the value specified in the tags for by TYPE key, size is the value of the SIZE tag key it defaults to 255 when not set.
Types ¶
type Field ¶
type Field struct { *StructField IsBlank bool Field reflect.Value }
Field model field definition
type JoinTableForeignKey ¶
JoinTableForeignKey info that point to a key to use in join table.
type JoinTableHandler ¶
type JoinTableHandler struct { TableName string `sql:"-"` Source JoinTableSource `sql:"-"` Destination JoinTableSource `sql:"-"` }
JoinTableHandler default join table handler
type JoinTableSource ¶
type JoinTableSource struct { ModelType reflect.Type ForeignKeys []JoinTableForeignKey }
JoinTableSource is a struct that contains model type and foreign keys
type Model ¶
type Model struct { ID int64 `gorm:"primary_key" json:"id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt *time.Time `sql:"index" json:"deleted_at"` }
Model defines common fields that are used for defining SQL Tables. This is a helper that you can embed in your own struct definition.
By embedding this, there is no need to define the supplied fields. For example.
type User struct { Model Name string }
Is the same as this
type User struct { ID uint `gorm:"primary_key"` CreatedAt time.Time UpdatedAt time.Time DeletedAt *time.Time `sql:"index"` Name string }
type Relationship ¶
type Relationship struct { Kind string PolymorphicType string PolymorphicDBName string PolymorphicValue string ForeignFieldNames []string ForeignDBNames []string AssociationForeignFieldNames []string AssociationForeignDBNames []string JoinTableHandler *JoinTableHandler }
Relationship described the relationship between models
type SQLCommon ¶
type SQLCommon interface { Exec(query string, args ...interface{}) (sql.Result, error) Prepare(query string) (*sql.Stmt, error) Query(query string, args ...interface{}) (*sql.Rows, error) QueryRow(query string, args ...interface{}) *sql.Row Begin() (*sql.Tx, error) Close() error }
SQLCommon is the interface for SQL database interactions.
type SQLCommonWrapper ¶
type SQLCommonWrapper struct { SQLCommon // contains filtered or unexported fields }
func (*SQLCommonWrapper) Exec ¶
func (s *SQLCommonWrapper) Exec(query string, args ...interface{}) (sql.Result, error)
func (*SQLCommonWrapper) Query ¶
func (s *SQLCommonWrapper) Query(query string, args ...interface{}) (*sql.Rows, error)
func (*SQLCommonWrapper) QueryRow ¶
func (s *SQLCommonWrapper) QueryRow(query string, args ...interface{}) *sql.Row
func (*SQLCommonWrapper) Verbose ¶
func (s *SQLCommonWrapper) Verbose(b bool)
type SafeStructsMap ¶
type SafeStructsMap struct {
// contains filtered or unexported fields
}
SafeStructsMap provide safe storage and accessing of *Struct.
func NewStructsMap ¶
func NewStructsMap() *SafeStructsMap
NewStructsMap returns a safe map for storing *Struct objects.
type Scope ¶
type Scope struct { Value interface{} TableName string SQL string SQLVars []interface{} SelectAttrs []string MultiExpr bool Exprs []*Expr // contains filtered or unexported fields }
Scope is the scope level of SQL building.
func NewScope ¶
func NewScope() *Scope
NewScope return an empty scope. The scope is initialized to allow Set, and Get methods to work.
func (*Scope) ContextValue ¶
func (s *Scope) ContextValue(v interface{})
type Search ¶
type Search struct { WhereConditions []map[string]interface{} OrConditions []map[string]interface{} NotConditions []map[string]interface{} HavingConditions []map[string]interface{} JoinConditions []map[string]interface{} InitAttrs []interface{} AssignAttrs []interface{} Selects map[string]interface{} Omits []string Orders []interface{} Preload []SearchPreload Offset interface{} Limit interface{} Group string TableName string TableNames []string Raw bool Unscoped bool IgnoreOrderQuery bool }
Search is the search level of SQL building
type SearchPreload ¶
type SearchPreload struct { Schema string Conditions []interface{} }
SearchPreload is the preload search condition.
type Struct ¶
type Struct struct { PrimaryFields []*StructField StructFields []*StructField ModelType reflect.Type DefaultTableName string }
Struct model definition
type StructField ¶
type StructField struct { // DBName is the name of the field as it is seen in the database, for // instance a field ID can be represented in the database as id. DBName string Name string Names []string IsPrimaryKey bool IsNormal bool IsIgnored bool IsScanner bool HasDefaultValue bool Tag reflect.StructTag TagSettings map[string]string Struct reflect.StructField IsForeignKey bool Relationship *Relationship }
StructField model field's struct definition
func (*StructField) Clone ¶
func (s *StructField) Clone() *StructField
Clone retruns a deep copy of the StructField