Documentation
¶
Index ¶
- Constants
- Variables
- func AfterBatchCreate(scope *Scope)
- func AfterCreate(scope *Scope)
- func AfterDelete(scope *Scope)
- func AfterQuery(scope *Scope)
- func AfterUpdate(scope *Scope)
- func AssignUpdateAttributes(scope *Scope)
- func BatchCreate(scope *Scope)
- func BeforeBatchCreate(scope *Scope)
- func BeforeCreate(scope *Scope)
- func BeforeDelete(scope *Scope)
- func BeforeUpdate(scope *Scope)
- func BeginTransaction(scope *Scope)
- func CommitOrRollbackTransaction(scope *Scope)
- func Create(scope *Scope)
- func DBName(table_name string) (string, string)
- func Delete(scope *Scope)
- func Expr(expression string, args ...interface{}) *expr
- func GetSeqInIndex(index_name string) (string, int, bool)
- func ParseTagSetting(tags reflect.StructTag) map[string]string
- func Preload(scope *Scope)
- func Query(scope *Scope)
- func SaveAfterAssociations(scope *Scope)
- func SaveBeforeAssociations(scope *Scope)
- func ToDBName(name string) string
- func Update(scope *Scope)
- func UpdateTimeStampWhenBatchCreate(scope *Scope)
- func UpdateTimeStampWhenCreate(scope *Scope)
- func UpdateTimeStampWhenUpdate(scope *Scope)
- type Association
- func (association *Association) Append(values ...interface{}) *Association
- func (association *Association) Clear() *Association
- func (association *Association) Count() int
- func (association *Association) Delete(values ...interface{}) *Association
- func (association *Association) Find(value interface{}) *Association
- func (association *Association) Replace(values ...interface{}) *Association
- type DB
- func (s *DB) AddForeignKey(field string, dest string, onDelete string, onUpdate string) *DB
- func (s *DB) AddIndex(indexName string, column ...string) *DB
- func (s *DB) AddUniqueIndex(indexName string, column ...string) *DB
- func (s *DB) Assign(attrs ...interface{}) *DB
- func (s *DB) Association(column string) *Association
- func (s *DB) Attrs(attrs ...interface{}) *DB
- func (s *DB) AutoMigrate(values ...interface{}) *DB
- func (s *DB) BatchCreate(value interface{}) *DB
- func (s *DB) BatchCreateIgnore(value interface{}) *DB
- func (s *DB) Begin() *DB
- func (s *DB) Callback() *callback
- func (s *DB) Close() error
- func (s *DB) Commit() *DB
- func (s *DB) CommonDB() sqlCommon
- func (s *DB) Count(value interface{}) *DB
- func (s *DB) Create(value interface{}) *DB
- func (s *DB) CreateIgnore(value interface{}) *DB
- func (s *DB) CreateTable(value interface{}) *DB
- func (s *DB) DB() *sql.DB
- func (s *DB) Debug() *DB
- func (s *DB) Delete(value interface{}, where ...interface{}) *DB
- func (s *DB) DropColumn(column string) *DB
- func (s *DB) DropTable(value interface{}) *DB
- func (s *DB) DropTableIfExists(value interface{}) *DB
- func (s *DB) Exec(sql string, values ...interface{}) *DB
- func (s *DB) Find(out interface{}, where ...interface{}) *DB
- func (s *DB) First(out interface{}, where ...interface{}) *DB
- func (s *DB) FirstOrCreate(out interface{}, where ...interface{}) *DB
- func (s *DB) FirstOrInit(out interface{}, where ...interface{}) *DB
- func (s *DB) Get(name string) (value interface{}, ok bool)
- func (s *DB) Group(query string) *DB
- func (s *DB) HasTable(value interface{}) bool
- func (s *DB) Having(query string, values ...interface{}) *DB
- func (s *DB) InstantSet(name string, value interface{}) *DB
- func (s *DB) Joins(query string) *DB
- func (s *DB) Last(out interface{}, where ...interface{}) *DB
- func (s *DB) Limit(value interface{}) *DB
- func (s *DB) LogMode(enable bool) *DB
- func (s *DB) Model(value interface{}) *DB
- func (s *DB) ModifyColumn(column string, typ string) *DB
- func (s *DB) New() *DB
- func (s *DB) NewRecord(value interface{}) bool
- func (db *DB) NewScope(value interface{}) *Scope
- func (s *DB) Not(query interface{}, args ...interface{}) *DB
- func (s *DB) Offset(value interface{}) *DB
- func (s *DB) Omit(columns ...string) *DB
- func (s *DB) Or(query interface{}, args ...interface{}) *DB
- func (s *DB) Order(value string, reorder ...bool) *DB
- func (s *DB) Pluck(column string, value interface{}) *DB
- func (s *DB) Preload(column string, conditions ...interface{}) *DB
- func (s *DB) Raw(sql string, values ...interface{}) *DB
- func (s *DB) RecordNotFound() bool
- func (s *DB) Related(value interface{}, foreignKeys ...string) *DB
- func (s *DB) RemoveIndex(indexName string) *DB
- func (s *DB) Rollback() *DB
- func (s *DB) Row() *sql.Row
- func (s *DB) Rows() (*sql.Rows, error)
- func (s *DB) Save(value interface{}) *DB
- func (s *DB) Scan(dest interface{}) *DB
- func (s *DB) Scopes(funcs ...func(*DB) *DB) *DB
- func (s *DB) Select(query interface{}, args ...interface{}) *DB
- func (s *DB) Set(name string, value interface{}) *DB
- func (s *DB) SetJoinTableHandler(source interface{}, column string, handler JoinTableHandlerInterface)
- func (s *DB) SetLogger(l logger)
- func (s *DB) SingularTable(enable bool)
- func (s *DB) Table(name string) *DB
- func (s *DB) Unscoped() *DB
- func (s *DB) Update(attrs ...interface{}) *DB
- func (s *DB) UpdateColumn(attrs ...interface{}) *DB
- func (s *DB) UpdateColumns(values interface{}) *DB
- func (s *DB) Updates(values interface{}, ignoreProtectedAttrs ...bool) *DB
- func (s *DB) Where(query interface{}, args ...interface{}) *DB
- type Dialect
- type Field
- type Hstore
- type JoinTableForeignKey
- type JoinTableHandler
- func (s JoinTableHandler) Add(db *DB, source1 interface{}, source2 interface{}) error
- func (s JoinTableHandler) Delete(db *DB, sources ...interface{}) error
- func (s JoinTableHandler) GetSearchMap(db *DB, sources ...interface{}) map[string]interface{}
- func (s JoinTableHandler) JoinWith(db *DB, source interface{}) *DB
- func (s *JoinTableHandler) Setup(relationship *Relationship, tableName string, source reflect.Type, ...)
- func (s JoinTableHandler) Table(*DB) string
- type JoinTableHandlerInterface
- type JoinTableSource
- type Logger
- type Model
- type ModelStruct
- type Relationship
- type Scope
- func (scope *Scope) AddToVars(value interface{}) string
- func (scope *Scope) AutoIncrementField() *Field
- func (scope *Scope) BatchFields() []map[string]*Field
- func (scope *Scope) Begin() *Scope
- func (scope *Scope) CallMethod(name string, checkError bool)
- func (scope *Scope) CallMethodWithErrorCheck(name string)
- func (scope *Scope) Charset() string
- func (scope *Scope) CombinedConditionSql() string
- func (scope *Scope) CommitOrRollback() *Scope
- func (scope *Scope) DB() *DB
- func (scope *Scope) Dialect() Dialect
- func (scope *Scope) Engine() string
- func (scope *Scope) Err(err error) error
- func (scope *Scope) Exec() *Scope
- func (scope *Scope) FieldByName(name string) (field *Field, ok bool)
- func (scope *Scope) Fields() map[string]*Field
- func (scope *Scope) Get(name string) (interface{}, bool)
- func (scope *Scope) GetModelStruct() *ModelStruct
- func (scope *Scope) GetStructFields() (fields []*StructField)
- func (scope *Scope) HasColumn(column string) bool
- func (scope *Scope) HasError() bool
- func (scope *Scope) IndirectValue() reflect.Value
- func (scope *Scope) InstanceGet(name string) (interface{}, bool)
- func (scope *Scope) InstanceId() string
- func (scope *Scope) InstanceSet(name string, value interface{}) *Scope
- func (scope *Scope) Log(v ...interface{})
- func (scope *Scope) NeedPtr() *Scope
- func (scope *Scope) New(value interface{}) *Scope
- func (scope *Scope) NewDB() *DB
- func (scope *Scope) OmitAttrs() []string
- func (scope *Scope) PrimaryField() *Field
- func (scope *Scope) PrimaryKey() string
- func (scope *Scope) PrimaryKeyValue() interface{}
- func (scope *Scope) PrimaryKeyZero() bool
- func (scope *Scope) Quote(str string) string
- func (scope *Scope) QuotedTableName() (name string)
- func (scope *Scope) Raw(sql string) *Scope
- func (scope *Scope) SelectAttrs() []string
- func (scope *Scope) Set(name string, value interface{}) *Scope
- func (scope *Scope) SetColumn(column interface{}, value interface{}) error
- func (scope *Scope) SkipLeft()
- func (scope *Scope) SqlDB() sqlCommon
- func (scope *Scope) TableName() string
- func (scope *Scope) Trace(t time.Time)
- type StructField
Constants ¶
const (
SeqIndexRegexString = "\\[\\d+\\]"
)
Variables ¶
var ( RecordNotFound = errors.New("record not found") InvalidSql = errors.New("invalid sql") NoNewAttrs = errors.New("no new attributes") NoValidTransaction = errors.New("no valid transaction") CantStartTransaction = errors.New("can't start transaction") )
var DefaultCallback = &callback{processors: []*callbackProcessor{}}
var DefaultTableNameHandler = func(db *DB, defaultTableName string) string {
return defaultTableName
}
var NowFunc = func() time.Time { return time.Now() }
NowFunc returns current time, this function is exported in order to be able to give the flexibility to the developer to customize it according to their needs
e.g: return time.Now().UTC()
Functions ¶
func AfterBatchCreate ¶
func AfterBatchCreate(scope *Scope)
func AfterCreate ¶
func AfterCreate(scope *Scope)
func AfterDelete ¶
func AfterDelete(scope *Scope)
func AfterQuery ¶
func AfterQuery(scope *Scope)
func AfterUpdate ¶
func AfterUpdate(scope *Scope)
func AssignUpdateAttributes ¶
func AssignUpdateAttributes(scope *Scope)
func BatchCreate ¶
func BatchCreate(scope *Scope)
func BeforeBatchCreate ¶
func BeforeBatchCreate(scope *Scope)
func BeforeCreate ¶
func BeforeCreate(scope *Scope)
func BeforeDelete ¶
func BeforeDelete(scope *Scope)
func BeforeUpdate ¶
func BeforeUpdate(scope *Scope)
func BeginTransaction ¶
func BeginTransaction(scope *Scope)
func CommitOrRollbackTransaction ¶
func CommitOrRollbackTransaction(scope *Scope)
func SaveAfterAssociations ¶
func SaveAfterAssociations(scope *Scope)
func SaveBeforeAssociations ¶
func SaveBeforeAssociations(scope *Scope)
func UpdateTimeStampWhenBatchCreate ¶
func UpdateTimeStampWhenBatchCreate(scope *Scope)
func UpdateTimeStampWhenCreate ¶
func UpdateTimeStampWhenCreate(scope *Scope)
func UpdateTimeStampWhenUpdate ¶
func UpdateTimeStampWhenUpdate(scope *Scope)
Types ¶
type Association ¶
type Association struct { Scope *Scope PrimaryKey interface{} Column string Error error Field *Field }
func (*Association) Append ¶
func (association *Association) Append(values ...interface{}) *Association
func (*Association) Clear ¶
func (association *Association) Clear() *Association
func (*Association) Count ¶
func (association *Association) Count() int
func (*Association) Delete ¶
func (association *Association) Delete(values ...interface{}) *Association
func (*Association) Find ¶
func (association *Association) Find(value interface{}) *Association
func (*Association) Replace ¶
func (association *Association) Replace(values ...interface{}) *Association
type DB ¶
type DB struct { Value interface{} Error error RowsAffected int64 // contains filtered or unexported fields }
func (*DB) AddForeignKey ¶
Add foreign key to the given scope
Example:
db.Model(&User{}).AddForeignKey("city_id", "cities(id)", "RESTRICT", "RESTRICT")
func (*DB) Association ¶
func (s *DB) Association(column string) *Association
func (*DB) AutoMigrate ¶
func (*DB) BatchCreate ¶
func (*DB) BatchCreateIgnore ¶
func (*DB) CommonDB ¶
func (s *DB) CommonDB() sqlCommon
CommonDB Return the underlying sql.DB or sql.Tx instance. Use of this method is discouraged. It's mainly intended to allow coexistence with legacy non-GORM code.
func (*DB) CreateIgnore ¶
func (*DB) DropColumn ¶
func (*DB) DropTableIfExists ¶
func (*DB) FirstOrCreate ¶
func (*DB) FirstOrInit ¶
func (*DB) InstantSet ¶
func (*DB) RecordNotFound ¶
func (*DB) RemoveIndex ¶
func (*DB) SetJoinTableHandler ¶
func (s *DB) SetJoinTableHandler(source interface{}, column string, handler JoinTableHandlerInterface)
func (*DB) SingularTable ¶
func (*DB) UpdateColumn ¶
func (*DB) UpdateColumns ¶
type Dialect ¶
type Dialect interface { BinVar(i int) string SupportLastInsertId() bool HasTop() bool SqlTag(value reflect.Value, size int, autoIncrease bool) string ReturningStr(tableName, key string) string SelectFromDummyTable() string Quote(key string) string HasTable(scope *Scope, tableName string) bool HasColumn(scope *Scope, tableName string, columnName string) bool HasIndex(scope *Scope, tableName string, indexName string) bool RemoveIndex(scope *Scope, indexName string) IndexColumnMap(scope *Scope, tableName string, isUnique int) map[string][]string Columns(scope *Scope, tableName string) map[string]string }
func NewDialect ¶
type JoinTableForeignKey ¶
type JoinTableHandler ¶
type JoinTableHandler struct { TableName string `sql:"-"` Source JoinTableSource `sql:"-"` Destination JoinTableSource `sql:"-"` }
func (JoinTableHandler) Add ¶
func (s JoinTableHandler) Add(db *DB, source1 interface{}, source2 interface{}) error
func (JoinTableHandler) Delete ¶
func (s JoinTableHandler) Delete(db *DB, sources ...interface{}) error
func (JoinTableHandler) GetSearchMap ¶
func (s JoinTableHandler) GetSearchMap(db *DB, sources ...interface{}) map[string]interface{}
func (JoinTableHandler) JoinWith ¶
func (s JoinTableHandler) JoinWith(db *DB, source interface{}) *DB
func (*JoinTableHandler) Setup ¶
func (s *JoinTableHandler) Setup(relationship *Relationship, tableName string, source reflect.Type, destination reflect.Type)
func (JoinTableHandler) Table ¶
func (s JoinTableHandler) Table(*DB) string
type JoinTableHandlerInterface ¶
type JoinTableHandlerInterface interface { Setup(relationship *Relationship, tableName string, source reflect.Type, destination reflect.Type) Table(db *DB) string Add(db *DB, source interface{}, destination interface{}) error Delete(db *DB, sources ...interface{}) error JoinWith(db *DB, source interface{}) *DB }
type JoinTableSource ¶
type JoinTableSource struct { ModelType reflect.Type ForeignKeys []JoinTableForeignKey }
type ModelStruct ¶
type ModelStruct struct { PrimaryFields []*StructField StructFields []*StructField ModelType reflect.Type // contains filtered or unexported fields }
func (ModelStruct) TableName ¶
func (s ModelStruct) TableName(db *DB) string
type Relationship ¶
type Scope ¶
type Scope struct { Search *search Value interface{} Sql string SqlVars []interface{} // contains filtered or unexported fields }
func (*Scope) AutoIncrementField ¶
func (*Scope) BatchFields ¶
BatchFields get a slice values' sub value's fields
func (*Scope) CallMethod ¶
func (*Scope) CallMethodWithErrorCheck ¶
func (*Scope) CombinedConditionSql ¶
CombinedConditionSql get combined condition sql
func (*Scope) CommitOrRollback ¶
CommitOrRollback commit current transaction if there is no error, otherwise rollback it
func (*Scope) GetModelStruct ¶
func (scope *Scope) GetModelStruct() *ModelStruct
func (*Scope) GetStructFields ¶
func (scope *Scope) GetStructFields() (fields []*StructField)
func (*Scope) IndirectValue ¶
func (*Scope) InstanceGet ¶
func (*Scope) InstanceId ¶
InstanceId get InstanceId for scope
func (*Scope) InstanceSet ¶
func (*Scope) PrimaryField ¶
func (*Scope) PrimaryKey ¶
PrimaryKey get the primary key's column name
func (*Scope) PrimaryKeyValue ¶
func (scope *Scope) PrimaryKeyValue() interface{}
PrimaryKeyValue get the primary key's value
func (*Scope) PrimaryKeyZero ¶
PrimaryKeyZero check the primary key is blank or not
func (*Scope) QuotedTableName ¶
func (*Scope) SelectAttrs ¶
Source Files
¶
- association.go
- callback.go
- callback_batch_create.go
- callback_create.go
- callback_delete.go
- callback_query.go
- callback_shared.go
- callback_update.go
- common_dialect.go
- dialect.go
- errors.go
- field.go
- foundation.go
- interface.go
- join_table_handler.go
- logger.go
- main.go
- main_private.go
- model.go
- model_struct.go
- mssql.go
- mysql.go
- postgres.go
- preload.go
- scope.go
- scope_private.go
- search.go
- sqlite3.go
- utils.go
- utils_private.go