model

package
v0.0.0-...-9ed695e Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2017 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package model defines structures that are shared through out ngorm. They provide the base building blocks for ngorm abstractions.

Index

Constants

View Source
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"
)

All important keys

Variables

This section is empty.

Functions

func ParseTagSetting

func ParseTagSetting(tags reflect.StructTag) map[string]string

ParseTagSetting returns a map[string]string for the tags that are set.

Types

type Expr

type Expr struct {
	Q    string
	Args []interface{}
}

Expr is SQL expression

type Field

type Field struct {
	*StructField
	IsBlank bool
	Field   reflect.Value
}

Field model field definition

func (*Field) Set

func (field *Field) Set(value interface{}) (err error)

Set set a value to the field

type JoinTableForeignKey

type JoinTableForeignKey struct {
	DBName            string
	AssociationDBName string
}

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"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time `sql:"index"`
}

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

func (*SafeStructsMap) Get

func (s *SafeStructsMap) Get(key reflect.Type) *Struct

Get retrieves the value stored with the gived key.

func (*SafeStructsMap) Set

func (s *SafeStructsMap) Set(key reflect.Type, value *Struct)

Set stores value with the given key.

type Scope

type Scope struct {
	Value           interface{}
	SQL             string
	SQLVars         []interface{}
	InstanceID      string
	PrimaryKeyField *Field
	SkipLeft        bool
	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) Get

func (s *Scope) Get(key string) (interface{}, bool)

Get retrieves the value with key from the scope.

func (*Scope) GetAll

func (s *Scope) GetAll() map[string]interface{}

GetAll erturns all values stored in this context.

func (*Scope) Set

func (s *Scope) Set(key string, value interface{})

Set sets a scope specific key value. This is only available in the scope.

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

Jump to

Keyboard shortcuts

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