Sie sind auf Seite 1von 28

28/05/2016

gorm - GoDoc

gorm:(https://github.com/jinzhu/gorm)github.com/jinzhu/gorm

Index|Files|Directories

packagegorm
import"github.com/jinzhu/gorm"

Index
Variables
funcExpr(expressionstring,args...interface{})*expr
funcParseFieldStructForDialect(field*StructField)(fieldValuereflect.Value,sqlTypestring,sizeint,
additionalTypestring)
funcRegisterDialect(namestring,dialectDialect)
funcToDBName(namestring)string
typeAssociation
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(valueinterface{})*Association
func(association*Association)Replace(values...interface{})*Association
typeCallback
func(c*Callback)Create()*CallbackProcessor
func(c*Callback)Delete()*CallbackProcessor
func(c*Callback)Query()*CallbackProcessor
func(c*Callback)RowQuery()*CallbackProcessor
func(c*Callback)Update()*CallbackProcessor
typeCallbackProcessor
func(cp*CallbackProcessor)After(callbackNamestring)*CallbackProcessor
func(cp*CallbackProcessor)Before(callbackNamestring)*CallbackProcessor
func(cp*CallbackProcessor)Get(callbackNamestring)(callbackfunc(scope*Scope))
func(cp*CallbackProcessor)Register(callbackNamestring,callbackfunc(scope*Scope))
func(cp*CallbackProcessor)Remove(callbackNamestring)
func(cp*CallbackProcessor)Replace(callbackNamestring,callbackfunc(scope*Scope))
typeDB
funcOpen(dialectstring,args...interface{})(*DB,error)
func(s*DB)AddError(errerror)error
func(s*DB)AddForeignKey(fieldstring,deststring,onDeletestring,onUpdatestring)*DB
func(s*DB)AddIndex(indexNamestring,columns...string)*DB
func(s*DB)AddUniqueIndex(indexNamestring,columns...string)*DB
func(s*DB)Assign(attrs...interface{})*DB
func(s*DB)Association(columnstring)*Association
func(s*DB)Attrs(attrs...interface{})*DB
func(s*DB)AutoMigrate(values...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(valueinterface{})*DB
func(s*DB)Create(valueinterface{})*DB
func(s*DB)CreateTable(models...interface{})*DB
func(s*DB)DB()*sql.DB
func(s*DB)Debug()*DB
func(s*DB)Delete(valueinterface{},where...interface{})*DB
func(s*DB)DropColumn(columnstring)*DB
func(s*DB)DropTable(values...interface{})*DB
https://godoc.org/github.com/jinzhu/gorm#DB.Close

1/28

28/05/2016

gorm - GoDoc

func(s*DB)DropTable(values...interface{})*DB
func(s*DB)DropTableIfExists(values...interface{})*DB
func(s*DB)Exec(sqlstring,values...interface{})*DB
func(s*DB)Find(outinterface{},where...interface{})*DB
func(s*DB)First(outinterface{},where...interface{})*DB
func(s*DB)FirstOrCreate(outinterface{},where...interface{})*DB
func(s*DB)FirstOrInit(outinterface{},where...interface{})*DB
func(s*DB)Get(namestring)(valueinterface{},okbool)
func(s*DB)GetErrors()(errors[]error)
func(s*DB)Group(querystring)*DB
func(s*DB)HasTable(valueinterface{})bool
func(s*DB)Having(querystring,values...interface{})*DB
func(s*DB)InstantSet(namestring,valueinterface{})*DB
func(s*DB)Joins(querystring,args...interface{})*DB
func(s*DB)Last(outinterface{},where...interface{})*DB
func(s*DB)Limit(limitint)*DB
func(s*DB)LogMode(enablebool)*DB
func(s*DB)Model(valueinterface{})*DB
func(s*DB)ModifyColumn(columnstring,typstring)*DB
func(s*DB)New()*DB
func(s*DB)NewRecord(valueinterface{})bool
func(s*DB)NewScope(valueinterface{})*Scope
func(s*DB)Not(queryinterface{},args...interface{})*DB
func(s*DB)Offset(offsetint)*DB
func(s*DB)Omit(columns...string)*DB
func(s*DB)Or(queryinterface{},args...interface{})*DB
func(s*DB)Order(valuestring,reorder...bool)*DB
func(s*DB)Pluck(columnstring,valueinterface{})*DB
func(s*DB)Preload(columnstring,conditions...interface{})*DB
func(s*DB)Raw(sqlstring,values...interface{})*DB
func(s*DB)RecordNotFound()bool
func(s*DB)Related(valueinterface{},foreignKeys...string)*DB
func(s*DB)RemoveIndex(indexNamestring)*DB
func(s*DB)Rollback()*DB
func(s*DB)Row()*sql.Row
func(s*DB)Rows()(*sql.Rows,error)
func(s*DB)Save(valueinterface{})*DB
func(s*DB)Scan(destinterface{})*DB
func(s*DB)ScanRows(rows*sql.Rows,resultinterface{})error
func(s*DB)Scopes(funcs...func(*DB)*DB)*DB
func(s*DB)Select(queryinterface{},args...interface{})*DB
func(s*DB)Set(namestring,valueinterface{})*DB
func(s*DB)SetJoinTableHandler(sourceinterface{},columnstring,handlerJoinTableHandlerInterface)
func(s*DB)SetLogger(loglogger)
func(s*DB)SingularTable(enablebool)
func(s*DB)Table(namestring)*DB
func(s*DB)Unscoped()*DB
func(s*DB)Update(attrs...interface{})*DB
func(s*DB)UpdateColumn(attrs...interface{})*DB
func(s*DB)UpdateColumns(valuesinterface{})*DB
func(s*DB)Updates(valuesinterface{},ignoreProtectedAttrs...bool)*DB
func(s*DB)Where(queryinterface{},args...interface{})*DB
typeDefaultForeignKeyNamer
func(DefaultForeignKeyNamer)BuildForeignKeyName(tableName,field,deststring)string
typeDialect
typeErrors
func(errs*Errors)Add(errerror)
func(errsErrors)Error()string
func(errsErrors)GetErrors()[]error

https://godoc.org/github.com/jinzhu/gorm#DB.Close

2/28

28/05/2016

gorm - GoDoc

func(errsErrors)GetErrors()[]error
typeField
func(field*Field)Set(valueinterface{})(errerror)
typeJoinTableForeignKey
typeJoinTableHandler
func(sJoinTableHandler)Add(handlerJoinTableHandlerInterface,db*DB,sourceinterface{},destination
interface{})error
func(sJoinTableHandler)Delete(handlerJoinTableHandlerInterface,db*DB,sources...interface{})error
func(s*JoinTableHandler)DestinationForeignKeys()[]JoinTableForeignKey
func(sJoinTableHandler)JoinWith(handlerJoinTableHandlerInterface,db*DB,sourceinterface{})*DB
func(s*JoinTableHandler)Setup(relationship*Relationship,tableNamestring,sourcereflect.Type,
destinationreflect.Type)
func(s*JoinTableHandler)SourceForeignKeys()[]JoinTableForeignKey
func(sJoinTableHandler)Table(db*DB)string
typeJoinTableHandlerInterface
typeJoinTableSource
typeLogWriter
typeLogger
func(loggerLogger)Print(values...interface{})
typeModel
typeModelStruct
func(s*ModelStruct)TableName(db*DB)string
typeRelationship
typeScope
func(scope*Scope)AddToVars(valueinterface{})string
func(scope*Scope)Begin()*Scope
func(scope*Scope)CallMethod(methodNamestring)
func(scope*Scope)CombinedConditionSql()string
func(scope*Scope)CommitOrRollback()*Scope
func(scope*Scope)DB()*DB
func(scope*Scope)Dialect()Dialect
func(scope*Scope)Err(errerror)error
func(scope*Scope)Exec()*Scope
func(scope*Scope)FieldByName(namestring)(field*Field,okbool)
func(scope*Scope)Fields()[]*Field
func(scope*Scope)Get(namestring)(interface{},bool)
func(scope*Scope)GetModelStruct()*ModelStruct
func(scope*Scope)GetStructFields()(fields[]*StructField)
func(scope*Scope)HasColumn(columnstring)bool
func(scope*Scope)HasError()bool
func(scope*Scope)IndirectValue()reflect.Value
func(scope*Scope)InstanceGet(namestring)(interface{},bool)
func(scope*Scope)InstanceID()string
func(scope*Scope)InstanceSet(namestring,valueinterface{})*Scope
func(scope*Scope)Log(v...interface{})
func(scope*Scope)New(valueinterface{})*Scope
func(scope*Scope)NewDB()*DB
func(scope*Scope)OmitAttrs()[]string
func(scope*Scope)PrimaryField()*Field
func(scope*Scope)PrimaryFields()(fields[]*Field)
func(scope*Scope)PrimaryKey()string
func(scope*Scope)PrimaryKeyValue()interface{}
func(scope*Scope)PrimaryKeyZero()bool
func(scope*Scope)Quote(strstring)string
func(scope*Scope)QuotedTableName()(namestring)
func(scope*Scope)Raw(sqlstring)*Scope
func(scope*Scope)SQLDB()sqlCommon
func(scope*Scope)SelectAttrs()[]string
https://godoc.org/github.com/jinzhu/gorm#DB.Close

3/28

28/05/2016

gorm - GoDoc

func(scope*Scope)SelectAttrs()[]string
func(scope*Scope)Set(namestring,valueinterface{})*Scope
func(scope*Scope)SetColumn(columninterface{},valueinterface{})error
func(scope*Scope)SkipLeft()
func(scope*Scope)TableName()string
typeStructField

PackageFiles(https://github.com/jinzhu/gorm)
association.go(https://github.com/jinzhu/gorm/blob/master/association.go)callback.go
(https://github.com/jinzhu/gorm/blob/master/callback.go)callback_create.go
(https://github.com/jinzhu/gorm/blob/master/callback_create.go)callback_delete.go
(https://github.com/jinzhu/gorm/blob/master/callback_delete.go)callback_query.go
(https://github.com/jinzhu/gorm/blob/master/callback_query.go)callback_query_preload.go
(https://github.com/jinzhu/gorm/blob/master/callback_query_preload.go)callback_save.go
(https://github.com/jinzhu/gorm/blob/master/callback_save.go)callback_update.go
(https://github.com/jinzhu/gorm/blob/master/callback_update.go)dialect.go
(https://github.com/jinzhu/gorm/blob/master/dialect.go)dialect_common.go
(https://github.com/jinzhu/gorm/blob/master/dialect_common.go)dialect_mysql.go
(https://github.com/jinzhu/gorm/blob/master/dialect_mysql.go)dialect_postgres.go
(https://github.com/jinzhu/gorm/blob/master/dialect_postgres.go)dialect_sqlite3.go
(https://github.com/jinzhu/gorm/blob/master/dialect_sqlite3.go)errors.go
(https://github.com/jinzhu/gorm/blob/master/errors.go)field.go
(https://github.com/jinzhu/gorm/blob/master/field.go)interface.go
(https://github.com/jinzhu/gorm/blob/master/interface.go)join_table_handler.go
(https://github.com/jinzhu/gorm/blob/master/join_table_handler.go)logger.go
(https://github.com/jinzhu/gorm/blob/master/logger.go)main.go
(https://github.com/jinzhu/gorm/blob/master/main.go)model.go
(https://github.com/jinzhu/gorm/blob/master/model.go)model_struct.go
(https://github.com/jinzhu/gorm/blob/master/model_struct.go)scope.go
(https://github.com/jinzhu/gorm/blob/master/scope.go)search.go
(https://github.com/jinzhu/gorm/blob/master/search.go)utils.go
(https://github.com/jinzhu/gorm/blob/master/utils.go)

Variables

var(
//ErrRecordNotFoundrecordnotfounderror,happenswhenhaven'tfindanymatcheddatawhenlook
ErrRecordNotFound=errors(/errors).New(/errors#New)("recordnotfound")
//ErrInvalidSQLinvalidSQLerror,happenswhenyoupassedinvalidSQL
ErrInvalidSQL=errors(/errors).New(/errors#New)("invalidSQL")
//ErrInvalidTransactioninvalidtransactionwhenyouaretryingto`Commit`or`Rollback`
ErrInvalidTransaction=errors(/errors).New(/errors#New)("novalidtransaction")
//ErrCantStartTransactioncan'tstarttransactionwhenyouaretryingtostartonewith`Begin`
ErrCantStartTransaction=errors(/errors).New(/errors#New)("can'tstarttransaction")
//ErrUnaddressableunaddressablevalue
ErrUnaddressable=errors(/errors).New(/errors#New)("usingunaddressablevalue")
)

varDefaultCallback=&Callback{}

DefaultCallbackdefaultcallbacksdefinedbygorm
varDefaultTableNameHandler=func(db*DB,defaultTableNamestring(/builtin#string))string
returndefaultTableName
}

DefaultTableNameHandlerdefaulttablenamehandler
https://godoc.org/github.com/jinzhu/gorm#DB.Close

4/28

28/05/2016

gorm - GoDoc

varNowFunc=func()time(/time).Time(/time#Time){
returntime(/time).Now(/time#Now)()
}

NowFuncreturnscurrenttime,thisfunctionisexportedinordertobeabletogivetheflexibilitytothedeveloper
tocustomizeitaccordingtotheirneeds,e.g:
gorm.NowFunc=func()time.Time{
returntime.Now().UTC()
}

funcExpr
(https://github.com/jinzhu/gorm/blob/master/utils.go#L121)
funcExpr(expressionstring(/builtin#string),args...interface{})*expr

ExprgeneraterawSQLexpression,forexample:
DB.Model(&product).Update("price",gorm.Expr("price*?+?",2,100))

funcParseFieldStructForDialect
(https://github.com/jinzhu/gorm/blob/master/dialect.go#L69)
funcParseFieldStructForDialect(field*StructField)(fieldValuereflect(/reflect).Val
ue(/reflect#Value),sqlTypestring(/builtin#string),sizeint(/builtin#int),additi
onalTypestring(/builtin#string))

ParseFieldStructForDialectparsefieldstructfordialect

funcRegisterDialect
(https://github.com/jinzhu/gorm/blob/master/dialect.go#L64)
funcRegisterDialect(namestring(/builtin#string),dialectDialect)

RegisterDialectregisternewdialect

funcToDBName
(https://github.com/jinzhu/gorm/blob/master/utils.go#L68)
funcToDBName(namestring(/builtin#string))string(/builtin#string)

ToDBNameconvertstringtodbname

typeAssociation
(https://github.com/jinzhu/gorm/blob/master/association.go#L10)
typeAssociationstruct{
Errorerror(/builtin#error)
//containsfilteredorunexportedfields
}

AssociationModecontainssomehelpermethodstohandlerelationshipthingseasily.

func(*Association)Append
https://godoc.org/github.com/jinzhu/gorm#DB.Close

5/28

28/05/2016

gorm - GoDoc
func(*Association)Append
(https://github.com/jinzhu/gorm/blob/master/association.go#L24)

func(association*Association)Append(values...interface{})*Association

Appendappendnewassociationsformany2many,has_many,replacecurrentassociationforhas_one,
belongs_to

func(*Association)Clear
(https://github.com/jinzhu/gorm/blob/master/association.go#L254)
func(association*Association)Clear()*Association

Clearremoverelationshipbetweensource&currentassociations,won'tdeletethoseassociations

func(*Association)Count
(https://github.com/jinzhu/gorm/blob/master/association.go#L259)
func(association*Association)Count()int(/builtin#int)

Countreturnthecountofcurrentassociations

func(*Association)Delete
(https://github.com/jinzhu/gorm/blob/master/association.go#L128)
func(association*Association)Delete(values...interface{})*Association

Deleteremoverelationshipbetweensource&passedarguments,butwon'tdeletethosearguments

func(*Association)Find
(https://github.com/jinzhu/gorm/blob/master/association.go#L18)
func(association*Association)Find(valueinterface{})*Association

Findfindoutallrelatedassociations

func(*Association)Replace
(https://github.com/jinzhu/gorm/blob/master/association.go#L36)
func(association*Association)Replace(values...interface{})*Association

Replacereplacecurrentassociationswithnewone

typeCallback
(https://github.com/jinzhu/gorm/blob/master/callback.go#L17)
typeCallbackstruct{
//containsfilteredorunexportedfields
}

CallbackisastructthatcontainsallCURDcallbacks

Field`creates`containscallbackswillbecallwhencreatingobject
Field`updates`containscallbackswillbecallwhenupdatingobject
Field`deletes`containscallbackswillbecallwhendeletingobject
Field`queries`containscallbackswillbecallwhenqueryingobjectwithquerymethodslikeFind,Fi
Field`rowQueries`containscallbackswillbecallwhenqueryingobjectwithRow,Rows...
Field`processors`containsallcallbackprocessors,willbeusedtogenerateabovecallbacksinorde

https://godoc.org/github.com/jinzhu/gorm#DB.Close

6/28

28/05/2016

gorm - GoDoc

func(*Callback)Create(https://github.com/jinzhu/gorm/blob/master/callback.go#L57)
func(c*Callback)Create()*CallbackProcessor

Createcouldbeusedtoregistercallbacksforcreatingobject
db.Callback().Create().After("gorm:create").Register("plugin:run_after_create",func(*Scope){
//businesslogic
...
//seterrorifsomethingwronghappened,willrollbackthecreating
scope.Err(errors.New("error"))
})

func(*Callback)Delete(https://github.com/jinzhu/gorm/blob/master/callback.go#L67)
func(c*Callback)Delete()*CallbackProcessor

Deletecouldbeusedtoregistercallbacksfordeletingobject,refer`Create`forusage

func(*Callback)Query(https://github.com/jinzhu/gorm/blob/master/callback.go#L73)
func(c*Callback)Query()*CallbackProcessor

Querycouldbeusedtoregistercallbacksforqueryingobjectswithquerymethodslike`Find`,`First`,`Related`,
`Association`...Refer`Create`forusage

func(*Callback)RowQuery
(https://github.com/jinzhu/gorm/blob/master/callback.go#L78)
func(c*Callback)RowQuery()*CallbackProcessor

RowQuerycouldbeusedtoregistercallbacksforqueryingobjectswith`Row`,`Rows`,refer`Create`forusage

func(*Callback)Update(https://github.com/jinzhu/gorm/blob/master/callback.go#L62)
func(c*Callback)Update()*CallbackProcessor

Updatecouldbeusedtoregistercallbacksforupdatingobject,refer`Create`forusage

typeCallbackProcessor
(https://github.com/jinzhu/gorm/blob/master/callback.go#L27)

typeCallbackProcessorstruct{
//containsfilteredorunexportedfields
}

CallbackProcessorcontainscallbackinformations

func(*CallbackProcessor)After
(https://github.com/jinzhu/gorm/blob/master/callback.go#L83)
func(cp*CallbackProcessor)After(callbackNamestring(/builtin#string))*CallbackPro
cessor
https://godoc.org/github.com/jinzhu/gorm#DB.Close

7/28

28/05/2016

gorm - GoDoc

Afterinsertanewcallbackaftercallback`callbackName`,refer`Callbacks.Create`

func(*CallbackProcessor)Before
(https://github.com/jinzhu/gorm/blob/master/callback.go#L89)
func(cp*CallbackProcessor)Before(callbackNamestring(/builtin#string))*CallbackPr
ocessor

Beforeinsertanewcallbackbeforecallback`callbackName`,refer`Callbacks.Create`

func(*CallbackProcessor)Get
(https://github.com/jinzhu/gorm/blob/master/callback.go#L128)
func(cp*CallbackProcessor)Get(callbackNamestring(/builtin#string))(callbackfunc
(scope*Scope))

Getregisteredcallback
db.Callback().Create().Get("gorm:create")

func(*CallbackProcessor)Register
(https://github.com/jinzhu/gorm/blob/master/callback.go#L95)
func(cp*CallbackProcessor)Register(callbackNamestring(/builtin#string),callback
func(scope*Scope))

Registeranewcallback,refer`Callbacks.Create`

func(*CallbackProcessor)Remove
(https://github.com/jinzhu/gorm/blob/master/callback.go#L104)
func(cp*CallbackProcessor)Remove(callbackNamestring(/builtin#string))

Removearegisteredcallback
db.Callback().Create().Remove("gorm:update_time_stamp_when_create")

func(*CallbackProcessor)Replace
(https://github.com/jinzhu/gorm/blob/master/callback.go#L117)
func(cp*CallbackProcessor)Replace(callbackNamestring(/builtin#string),callbackf
unc(scope*Scope))

Replacearegisteredcallbackwithnewcallback
db.Callback().Create().Replace("gorm:update_time_stamp_when_create",func(*Scope){

scope.SetColumn("Created",now)

scope.SetColumn("Updated",now)
})

typeDB
(https://github.com/jinzhu/gorm/blob/master/main.go#L13)
typeDBstruct{
Valueinterface{}
Errorerror(/builtin#error)
https://godoc.org/github.com/jinzhu/gorm#DB.Close

8/28

28/05/2016

gorm - GoDoc

RowsAffectedint64(/builtin#int64)
//containsfilteredorunexportedfields
}

DBcontainsinformationforcurrentdbconnection

funcOpen(https://github.com/jinzhu/gorm/blob/master/main.go#L41)
funcOpen(dialectstring(/builtin#string),args...interface{})(*DB,error(/builtin
#error))

Openinitializeanewdbconnection,needtoimportdriverfirst,e.g:
import_"github.com/gosqldriver/mysql"
funcmain(){
db,err:=gorm.Open("mysql","user:password@/dbname?charset=utf8&parseTime=True&loc=Local")
}

GORMhaswrappedsomedrivers,foreasiertorememberdriver'simportpath,soyoucouldimportthemysql
driverwith
import_"github.com/jinzhu/gorm/dialects/mysql"
//import_"github.com/jinzhu/gorm/dialects/postgres"
//import_"github.com/jinzhu/gorm/dialects/sqlite"
//import_"github.com/jinzhu/gorm/dialects/mssql"

func(*DB)AddError(https://github.com/jinzhu/gorm/blob/master/main.go#L634)
func(s*DB)AddError(errerror(/builtin#error))error(/builtin#error)

AddErroradderrortothedb

func(*DB)AddForeignKey(https://github.com/jinzhu/gorm/blob/master/main.go#L564)
func(s*DB)AddForeignKey(fieldstring(/builtin#string),deststring(/builtin#strin
g),onDeletestring(/builtin#string),onUpdatestring(/builtin#string))*DB

AddForeignKeyAddforeignkeytothegivenscope,e.g:
db.Model(&User{}).AddForeignKey("city_id","cities(id)","RESTRICT","RESTRICT")

func(*DB)AddIndex(https://github.com/jinzhu/gorm/blob/master/main.go#L542)
func(s*DB)AddIndex(indexNamestring(/builtin#string),columns...string(/builtin#
string))*DB

AddIndexaddindexforcolumnswithgivenname

func(*DB)AddUniqueIndex(https://github.com/jinzhu/gorm/blob/master/main.go#L549)
func(s*DB)AddUniqueIndex(indexNamestring(/builtin#string),columns...string(/bu
iltin#string))*DB

AddUniqueIndexadduniqueindexforcolumnswithgivenname

func(*DB)Assign(https://github.com/jinzhu/gorm/blob/master/main.go#L231)
func(s*DB)Assign(attrs...interface{})*DB

https://godoc.org/github.com/jinzhu/gorm#DB.Close

9/28

28/05/2016

gorm - GoDoc

func(s*DB)Assign(attrs...interface{})*DB

Assignassignresultwithargumentregardlessitisfoundornotwith`FirstOrInit`
https://jinzhu.github.io/gorm/curd.html#firstorinit(https://jinzhu.github.io/gorm/curd.html#firstorinit)or
`FirstOrCreate`https://jinzhu.github.io/gorm/curd.html#firstorcreate
(https://jinzhu.github.io/gorm/curd.html#firstorcreate)

func(*DB)Association(https://github.com/jinzhu/gorm/blob/master/main.go#L571)
func(s*DB)Association(columnstring(/builtin#string))*Association

Associationstart`AssociationMode`tohandlerrelationsthingseasirinthatmode,refer:
https://jinzhu.github.io/gorm/associations.html#associationmode
(https://jinzhu.github.io/gorm/associations.html#associationmode)

func(*DB)Attrs(https://github.com/jinzhu/gorm/blob/master/main.go#L226)
func(s*DB)Attrs(attrs...interface{})*DB

Attrsinitializestructwithargumentifrecordnotfoundwith`FirstOrInit`
https://jinzhu.github.io/gorm/curd.html#firstorinit(https://jinzhu.github.io/gorm/curd.html#firstorinit)or
`FirstOrCreate`https://jinzhu.github.io/gorm/curd.html#firstorcreate
(https://jinzhu.github.io/gorm/curd.html#firstorcreate)

func(*DB)AutoMigrate(https://github.com/jinzhu/gorm/blob/master/main.go#L519)
func(s*DB)AutoMigrate(values...interface{})*DB

AutoMigraterunautomigrationforgivenmodels,willonlyaddmissingfields,won'tdelete/changecurrentdata

func(*DB)Begin(https://github.com/jinzhu/gorm/blob/master/main.go#L420)
func(s*DB)Begin()*DB

Beginbeginatransaction

func(*DB)Callback(https://github.com/jinzhu/gorm/blob/master/main.go#L117)
func(s*DB)Callback()*Callback

Callbackreturn`Callbacks`container,youcouldadd/change/deletecallbackswithit

db.Callback().Create().Register("update_created_at",updateCreated)

Referhttps://jinzhu.github.io/gorm/development.html#callbacks
(https://jinzhu.github.io/gorm/development.html#callbacks)

func(*DB)Close(https://github.com/jinzhu/gorm/blob/master/main.go#L85)
func(s*DB)Close()error(/builtin#error)

Closeclosecurrentdbconnection

func(*DB)Commit(https://github.com/jinzhu/gorm/blob/master/main.go#L433)
func(s*DB)Commit()*DB

Commitcommitatransaction
https://godoc.org/github.com/jinzhu/gorm#DB.Close

10/28

28/05/2016

Commitcommitatransaction

gorm - GoDoc

func(*DB)CommonDB(https://github.com/jinzhu/gorm/blob/master/main.go#L110)
func(s*DB)CommonDB()sqlCommon

CommonDBreturntheunderlying`*sql.DB`or`*sql.Tx`instance,mainlyintendedtoallowcoexistencewith
legacynonGORMcode.

func(*DB)Count(https://github.com/jinzhu/gorm/blob/master/main.go#L294)
func(s*DB)Count(valueinterface{})*DB

Countgethowmanyrecordsforamodel

func(*DB)Create(https://github.com/jinzhu/gorm/blob/master/main.go#L370)
func(s*DB)Create(valueinterface{})*DB

Createinsertthevalueintodatabase

func(*DB)CreateTable(https://github.com/jinzhu/gorm/blob/master/main.go#L468)
func(s*DB)CreateTable(models...interface{})*DB

CreateTablecreatetableformodels

func(*DB)DB(https://github.com/jinzhu/gorm/blob/master/main.go#L90)
func(s*DB)DB()*sql(/database/sql).DB(/database/sql#DB)

DBget`*sql.DB`fromcurrentconnection

func(*DB)Debug(https://github.com/jinzhu/gorm/blob/master/main.go#L415)
func(s*DB)Debug()*DB

Debugstartdebugmode

func(*DB)Delete(https://github.com/jinzhu/gorm/blob/master/main.go#L376)
func(s*DB)Delete(valueinterface{},where...interface{})*DB

Deletedeletevaluematchgivenconditions,ifthevaluehasprimarykey,thenwillincludingtheprimarykeyas
condition

func(*DB)DropColumn(https://github.com/jinzhu/gorm/blob/master/main.go#L535)
func(s*DB)DropColumn(columnstring(/builtin#string))*DB

DropColumndropacolumn

func(*DB)DropTable(https://github.com/jinzhu/gorm/blob/master/main.go#L477)
func(s*DB)DropTable(values...interface{})*DB

DropTabledroptableformodels

func(*DB)DropTableIfExists

https://godoc.org/github.com/jinzhu/gorm#DB.Close

11/28

28/05/2016

gorm - GoDoc

func(*DB)DropTableIfExists
(https://github.com/jinzhu/gorm/blob/master/main.go#L490)
func(s*DB)DropTableIfExists(values...interface{})*DB

DropTableIfExistsdroptableifitisexist

func(*DB)Exec(https://github.com/jinzhu/gorm/blob/master/main.go#L387)
func(s*DB)Exec(sqlstring(/builtin#string),values...interface{})*DB

Execexecuterawsql

func(*DB)Find(https://github.com/jinzhu/gorm/blob/master/main.go#L252)
func(s*DB)Find(outinterface{},where...interface{})*DB

Findfindrecordsthatmatchgivenconditions

func(*DB)First(https://github.com/jinzhu/gorm/blob/master/main.go#L236)
func(s*DB)First(outinterface{},where...interface{})*DB

Firstfindfirstrecordthatmatchgivenconditions,orderbyprimarykey

func(*DB)FirstOrCreate(https://github.com/jinzhu/gorm/blob/master/main.go#L320)
func(s*DB)FirstOrCreate(outinterface{},where...interface{})*DB

FirstOrCreatefindfirstmatchedrecordorcreateanewonewithgivenconditions(onlyworkswithstruct,map
conditions)https://jinzhu.github.io/gorm/curd.html#firstorcreate
(https://jinzhu.github.io/gorm/curd.html#firstorcreate)

func(*DB)FirstOrInit(https://github.com/jinzhu/gorm/blob/master/main.go#L305)
func(s*DB)FirstOrInit(outinterface{},where...interface{})*DB

FirstOrInitfindfirstmatchedrecordorinitializeanewonewithgivenconditions(onlyworkswithstruct,map
conditions)https://jinzhu.github.io/gorm/curd.html#firstorinit(https://jinzhu.github.io/gorm/curd.html#firstorinit)

func(*DB)Get(https://github.com/jinzhu/gorm/blob/master/main.go#L610)
func(s*DB)Get(namestring(/builtin#string))(valueinterface{},okbool(/builtin#
bool))

Getgetsettingbyname

func(*DB)GetErrors(https://github.com/jinzhu/gorm/blob/master/main.go#L656)
func(s*DB)GetErrors()(errors[]error(/builtin#error))

GetErrorsgethappenederrorsfromthedb

func(*DB)Group(https://github.com/jinzhu/gorm/blob/master/main.go#L185)
func(s*DB)Group(querystring(/builtin#string))*DB

Groupspecifythegroupmethodonthefind

func(*DB)HasTable(https://github.com/jinzhu/gorm/blob/master/main.go#L501)
https://godoc.org/github.com/jinzhu/gorm#DB.Close

12/28

28/05/2016

gorm - GoDoc

func(*DB)HasTable(https://github.com/jinzhu/gorm/blob/master/main.go#L501)
func(s*DB)HasTable(valueinterface{})bool(/builtin#bool)

HasTablecheckhastableornot

func(*DB)Having(https://github.com/jinzhu/gorm/blob/master/main.go#L190)
func(s*DB)Having(querystring(/builtin#string),values...interface{})*DB

HavingspecifyHAVINGconditionsforGROUPBY

func(*DB)InstantSet(https://github.com/jinzhu/gorm/blob/master/main.go#L604)
func(s*DB)InstantSet(namestring(/builtin#string),valueinterface{})*DB

InstantSetinstantsetsetting,willaffectcurrentdb

func(*DB)Joins(https://github.com/jinzhu/gorm/blob/master/main.go#L196)
func(s*DB)Joins(querystring(/builtin#string),args...interface{})*DB

JoinsspecifyJoinsconditions

db.Joins("JOINemailsONemails.user_id=users.idANDemails.email=?","jinzhu@example.org").Find(

func(*DB)Last(https://github.com/jinzhu/gorm/blob/master/main.go#L244)
func(s*DB)Last(outinterface{},where...interface{})*DB

Lastfindlastrecordthatmatchgivenconditions,orderbyprimarykey

func(*DB)Limit(https://github.com/jinzhu/gorm/blob/master/main.go#L159)
func(s*DB)Limit(limitint(/builtin#int))*DB

Limitspecifythenumberofrecordstoberetrieved

func(*DB)LogMode(https://github.com/jinzhu/gorm/blob/master/main.go#L128)
func(s*DB)LogMode(enablebool(/builtin#bool))*DB

LogModesetlogmode,`true`fordetailedlogs,`false`fornolog,default,willonlyprinterrorlogs

func(*DB)Model(https://github.com/jinzhu/gorm/blob/master/main.go#L400)
func(s*DB)Model(valueinterface{})*DB

Modelspecifythemodelyouwouldliketorundboperations

//updateallusers'snameto`hello`
db.Model(&User{}).Update("name","hello")
//ifuser'sprimarykeyisnonblank,willuseitascondition,thenwillonlyupdatetheuser'snam
db.Model(&user).Update("name","hello")

func(*DB)ModifyColumn(https://github.com/jinzhu/gorm/blob/master/main.go#L528)
https://godoc.org/github.com/jinzhu/gorm#DB.Close

13/28

28/05/2016

gorm - GoDoc

func(s*DB)ModifyColumn(columnstring(/builtin#string),typstring(/builtin#strin
g))*DB

ModifyColumnmodifycolumntotype

func(*DB)New(https://github.com/jinzhu/gorm/blob/master/main.go#L95)
func(s*DB)New()*DB

Newcloneanewdbconnectionwithoutsearchconditions

func(*DB)NewRecord(https://github.com/jinzhu/gorm/blob/master/main.go#L453)
func(s*DB)NewRecord(valueinterface{})bool(/builtin#bool)

NewRecordcheckifvalue'sprimarykeyisblank

func(*DB)NewScope(https://github.com/jinzhu/gorm/blob/master/main.go#L103)
func(s*DB)NewScope(valueinterface{})*Scope

NewScopecreateascopeforcurrentoperation

func(*DB)Not(https://github.com/jinzhu/gorm/blob/master/main.go#L154)
func(s*DB)Not(queryinterface{},args...interface{})*DB

Notfilterrecordsthatdon'tmatchcurrentconditions,similarto`Where`

func(*DB)Offset(https://github.com/jinzhu/gorm/blob/master/main.go#L164)
func(s*DB)Offset(offsetint(/builtin#int))*DB

Offsetspecifythenumberofrecordstoskipbeforestartingtoreturntherecords

func(*DB)Omit(https://github.com/jinzhu/gorm/blob/master/main.go#L180)
func(s*DB)Omit(columns...string(/builtin#string))*DB

Omitspecifyfieldsthatyouwanttoignorewhensavingtodatabaseforcreating,updating

func(*DB)Or(https://github.com/jinzhu/gorm/blob/master/main.go#L149)
func(s*DB)Or(queryinterface{},args...interface{})*DB

Orfilterrecordsthatmatchbeforeconditionsorthisone,similarto`Where`

func(*DB)Order(https://github.com/jinzhu/gorm/blob/master/main.go#L169)
func(s*DB)Order(valuestring(/builtin#string),reorder...bool(/builtin#bool))*D
B

Orderspecifyorderwhenretrieverecordsfromdatabase,setreorderto`true`tooverwritedefinedconditions

func(*DB)Pluck(https://github.com/jinzhu/gorm/blob/master/main.go#L289)
func(s*DB)Pluck(columnstring(/builtin#string),valueinterface{})*DB
https://godoc.org/github.com/jinzhu/gorm#DB.Close

14/28

28/05/2016

gorm - GoDoc

Pluckusedtoquerysinglecolumnfromamodelasamap
varages[]int64
db.Find(&users).Pluck("age",&ages)

func(*DB)Preload(https://github.com/jinzhu/gorm/blob/master/main.go#L594)
func(s*DB)Preload(columnstring(/builtin#string),conditions...interface{})*DB

Preloadpreloadassociationswithgivenconditions
db.Preload("Orders","stateNOTIN(?)","cancelled").Find(&users)

func(*DB)Raw(https://github.com/jinzhu/gorm/blob/master/main.go#L382)
func(s*DB)Raw(sqlstring(/builtin#string),values...interface{})*DB

Rawuserawsqlasconditions,won'trunitunlessinvokedbyothermethods
db.Raw("SELECTname,ageFROMusersWHEREname=?",3).Scan(&result)

func(*DB)RecordNotFound
(https://github.com/jinzhu/gorm/blob/master/main.go#L458)
func(s*DB)RecordNotFound()bool(/builtin#bool)

RecordNotFoundcheckifreturningErrRecordNotFounderror

func(*DB)Related(https://github.com/jinzhu/gorm/blob/master/main.go#L299)
func(s*DB)Related(valueinterface{},foreignKeys...string(/builtin#string))*DB

Relatedgetrelatedassociations

func(*DB)RemoveIndex(https://github.com/jinzhu/gorm/blob/master/main.go#L556)
func(s*DB)RemoveIndex(indexNamestring(/builtin#string))*DB

RemoveIndexremoveindexwithname

func(*DB)Rollback(https://github.com/jinzhu/gorm/blob/master/main.go#L443)
func(s*DB)Rollback()*DB

Rollbackrollbackatransaction

func(*DB)Row(https://github.com/jinzhu/gorm/blob/master/main.go#L262)
func(s*DB)Row()*sql(/database/sql).Row(/database/sql#Row)

Rowreturn`*sql.Row`withgivenconditions

func(*DB)Rows(https://github.com/jinzhu/gorm/blob/master/main.go#L267)
func(s*DB)Rows()(*sql(/database/sql).Rows(/database/sql#Rows),error(/builtin#e
rror))
https://godoc.org/github.com/jinzhu/gorm#DB.Close

15/28

28/05/2016

gorm - GoDoc

Rowsreturn`*sql.Rows`withgivenconditions

func(*DB)Save(https://github.com/jinzhu/gorm/blob/master/main.go#L361)
func(s*DB)Save(valueinterface{})*DB

Saveupdatevalueindatabase,ifthevaluedoesn'thaveprimarykey,willinsertit

func(*DB)Scan(https://github.com/jinzhu/gorm/blob/master/main.go#L257)
func(s*DB)Scan(destinterface{})*DB

Scanscanvaluetoastruct

func(*DB)ScanRows(https://github.com/jinzhu/gorm/blob/master/main.go#L272)
func(s*DB)ScanRows(rows*sql(/database/sql).Rows(/database/sql#Rows),resultinte
rface{})error(/builtin#error)

ScanRowsscan`*sql.Rows`togivestruct

func(*DB)Scopes(https://github.com/jinzhu/gorm/blob/master/main.go#L213)
func(s*DB)Scopes(funcs...func(*DB)*DB)*DB

Scopespasscurrentdatabaseconnectiontoarguments`func(*DB)*DB`,whichcouldbeusedtoaddconditions
dynamically

funcAmountGreaterThan1000(db*gorm.DB)*gorm.DB{
returndb.Where("amount>?",1000)
}
funcOrderStatus(status[]string)func(db*gorm.DB)*gorm.DB{
returnfunc(db*gorm.DB)*gorm.DB{
returndb.Scopes(AmountGreaterThan1000).Where("statusin(?)",status)
}
}
db.Scopes(AmountGreaterThan1000,OrderStatus([]string{"paid","shipped"})).Find(&orders)

Referhttps://jinzhu.github.io/gorm/curd.html#scopes(https://jinzhu.github.io/gorm/curd.html#scopes)

func(*DB)Select(https://github.com/jinzhu/gorm/blob/master/main.go#L175)
func(s*DB)Select(queryinterface{},args...interface{})*DB

Selectspecifyfieldsthatyouwanttoretrievefromdatabasewhenquerying,bydefault,willselectallfields
Whencreating/updating,specifyfieldsthatyouwanttosavetodatabase

func(*DB)Set(https://github.com/jinzhu/gorm/blob/master/main.go#L599)
func(s*DB)Set(namestring(/builtin#string),valueinterface{})*DB

Setsetsettingbyname,whichcouldbeusedincallbacks,willcloneanewdb,andupdateitssetting
https://godoc.org/github.com/jinzhu/gorm#DB.Close

16/28

28/05/2016

gorm - GoDoc

Setsetsettingbyname,whichcouldbeusedincallbacks,willcloneanewdb,andupdateitssetting

func(*DB)SetJoinTableHandler
(https://github.com/jinzhu/gorm/blob/master/main.go#L616)
func(s*DB)SetJoinTableHandler(sourceinterface{},columnstring(/builtin#string),
handlerJoinTableHandlerInterface)

SetJoinTableHandlersetamodel'sjointablehandlerforarelation

func(*DB)SetLogger(https://github.com/jinzhu/gorm/blob/master/main.go#L123)
func(s*DB)SetLogger(loglogger)

SetLoggerreplacedefaultlogger

func(*DB)SingularTable(https://github.com/jinzhu/gorm/blob/master/main.go#L138)
func(s*DB)SingularTable(enablebool(/builtin#bool))

SingularTableusesingulartablebydefault

func(*DB)Table(https://github.com/jinzhu/gorm/blob/master/main.go#L407)
func(s*DB)Table(namestring(/builtin#string))*DB

Tablespecifythetableyouwouldliketorundboperations

func(*DB)Unscoped(https://github.com/jinzhu/gorm/blob/master/main.go#L221)
func(s*DB)Unscoped()*DB

Unscopedreturnallrecordincludingdeletedrecord,referSoftDelete
https://jinzhu.github.io/gorm/curd.html#softdelete(https://jinzhu.github.io/gorm/curd.html#softdelete)

func(*DB)Update(https://github.com/jinzhu/gorm/blob/master/main.go#L334)
func(s*DB)Update(attrs...interface{})*DB

Updateupdateattributeswithcallbacks,refer:https://jinzhu.github.io/gorm/curd.html#update
(https://jinzhu.github.io/gorm/curd.html#update)

func(*DB)UpdateColumn(https://github.com/jinzhu/gorm/blob/master/main.go#L347)
func(s*DB)UpdateColumn(attrs...interface{})*DB

UpdateColumnupdateattributeswithoutcallbacks,refer:https://jinzhu.github.io/gorm/curd.html#update
(https://jinzhu.github.io/gorm/curd.html#update)

func(*DB)UpdateColumns(https://github.com/jinzhu/gorm/blob/master/main.go#L352)
func(s*DB)UpdateColumns(valuesinterface{})*DB

UpdateColumnsupdateattributeswithoutcallbacks,refer:https://jinzhu.github.io/gorm/curd.html#update
(https://jinzhu.github.io/gorm/curd.html#update)

func(*DB)Updates(https://github.com/jinzhu/gorm/blob/master/main.go#L339)
func(s*DB)Updates(valuesinterface{},ignoreProtectedAttrs...bool(/builtin#bool))
*DB
https://godoc.org/github.com/jinzhu/gorm#DB.Close

17/28

28/05/2016

*DB

gorm - GoDoc

Updatesupdateattributeswithcallbacks,refer:https://jinzhu.github.io/gorm/curd.html#update
(https://jinzhu.github.io/gorm/curd.html#update)

func(*DB)Where(https://github.com/jinzhu/gorm/blob/master/main.go#L144)
func(s*DB)Where(queryinterface{},args...interface{})*DB

Wherereturnanewrelation,filterrecordswithgivenconditions,accepts`map`,`struct`or`string`asconditions,
referhttp://jinzhu.github.io/gorm/curd.html#query(http://jinzhu.github.io/gorm/curd.html#query)

typeDefaultForeignKeyNamer
(https://github.com/jinzhu/gorm/blob/master/dialect_common.go#L13)
typeDefaultForeignKeyNamerstruct{
}

DefaultForeignKeyNamercontainsthedefaultforeignkeynamegeneratormethod

func(DefaultForeignKeyNamer)BuildForeignKeyName
(https://github.com/jinzhu/gorm/blob/master/dialect_common.go#L145)
func(DefaultForeignKeyNamer)BuildForeignKeyName(tableName,field,deststring(/buil
tin#string))string(/builtin#string)

typeDialect
(https://github.com/jinzhu/gorm/blob/master/dialect.go#L12)
typeDialectinterface{
//GetNamegetdialect'sname
GetName()string(/builtin#string)
//SetDBsetdbfordialect
SetDB(db*sql(/database/sql).DB(/database/sql#DB))

//BindVarreturntheplaceholderforactualvaluesinSQLstatements,inmanydbsitis"?",Pos
BindVar(iint(/builtin#int))string(/builtin#string)
//QuotequotesfieldnametoavoidSQLparsingexceptionsbyusingareservedwordasafieldna
Quote(keystring(/builtin#string))string(/builtin#string)
//DataTypeOfreturndata'ssqltype
DataTypeOf(field*StructField)string(/builtin#string)
//HasIndexcheckhasindexornot
HasIndex(tableNamestring(/builtin#string),indexNamestring(/builtin#string))bool
//HasForeignKeycheckhasforeignkeyornot
HasForeignKey(tableNamestring(/builtin#string),foreignKeyNamestring(/builtin#string)
//RemoveIndexremoveindex
RemoveIndex(tableNamestring(/builtin#string),indexNamestring(/builtin#string))error
//HasTablecheckhastableornot
HasTable(tableNamestring(/builtin#string))bool(/builtin#bool)
//HasColumncheckhascolumnornot
HasColumn(tableNamestring(/builtin#string),columnNamestring(/builtin#string))bool

//LimitAndOffsetSQLreturngeneratedSQLwithLimitandOffset,asmssqlhasspecialcase
LimitAndOffsetSQL(limit,offsetint(/builtin#int))string(/builtin#string)
//SelectFromDummyTablereturnselectvalues,formostdbs,`SELECTvalues`justworks,mysqlnee
SelectFromDummyTable()string(/builtin#string)
//LastInsertIdReturningSuffixmostdbssupportLastInsertId,butpostgresneedstouse`RETURNIN
LastInsertIDReturningSuffix(tableName,columnNamestring(/builtin#string))string(/builtin#stri
https://godoc.org/github.com/jinzhu/gorm#DB.Close

18/28

28/05/2016

gorm - GoDoc

//BuildForeignKeyNamereturnsaforeignkeynameforthegiventable,fieldandreference
BuildForeignKeyName(tableName,field,deststring(/builtin#string))string(/builtin#string)
}

DialectinterfacecontainsbehaviorsthatdifferacrossSQLdatabase

typeErrors
(https://github.com/jinzhu/gorm/blob/master/errors.go#L26)
typeErrorsstruct{
//containsfilteredorunexportedfields
}

Errorscontainsallhappenederrors

func(*Errors)Add(https://github.com/jinzhu/gorm/blob/master/errors.go#L36)
func(errs*Errors)Add(errerror(/builtin#error))

Addaddanerror

func(Errors)Error(https://github.com/jinzhu/gorm/blob/master/errors.go#L52)
func(errsErrors)Error()string(/builtin#string)

Errorformathappenederrors

func(Errors)GetErrors(https://github.com/jinzhu/gorm/blob/master/errors.go#L31)
func(errsErrors)GetErrors()[]error(/builtin#error)

GetErrorsgetallhappenederrors

typeField
(https://github.com/jinzhu/gorm/blob/master/field.go#L11)
typeFieldstruct{
*StructField
IsBlankbool(/builtin#bool)
Fieldreflect(/reflect).Value(/reflect#Value)
}

Fieldmodelfielddefinition

func(*Field)Set(https://github.com/jinzhu/gorm/blob/master/field.go#L18)
func(field*Field)Set(valueinterface{})(errerror(/builtin#error))

Setsetavaluetothefield

typeJoinTableForeignKey
(https://github.com/jinzhu/gorm/blob/master/join_table_handler.go#L29)
typeJoinTableForeignKeystruct{
DBNamestring(/builtin#string)
AssociationDBNamestring(/builtin#string)
}
https://godoc.org/github.com/jinzhu/gorm#DB.Close

19/28

28/05/2016

gorm - GoDoc

JoinTableForeignKeyjointableforeignkeystruct

typeJoinTableHandler
(https://github.com/jinzhu/gorm/blob/master/join_table_handler.go#L41)
typeJoinTableHandlerstruct{
TableNamestring(/builtin#string)`sql:""`
SourceJoinTableSource`sql:""`
DestinationJoinTableSource`sql:""`
}

JoinTableHandlerdefaultjointablehandler

func(JoinTableHandler)Add
(https://github.com/jinzhu/gorm/blob/master/join_table_handler.go#L108)
func(sJoinTableHandler)Add(handlerJoinTableHandlerInterface,db*DB,sourceinterf
ace{},destinationinterface{})error(/builtin#error)

Addcreaterelationshipinjointableforsourceanddestination

func(JoinTableHandler)Delete
(https://github.com/jinzhu/gorm/blob/master/join_table_handler.go#L140)

func(sJoinTableHandler)Delete(handlerJoinTableHandlerInterface,db*DB,sources
...interface{})error(/builtin#error)

Deletedeleterelationshipinjointableforsources

func(*JoinTableHandler)DestinationForeignKeys
(https://github.com/jinzhu/gorm/blob/master/join_table_handler.go#L53)
func(s*JoinTableHandler)DestinationForeignKeys()[]JoinTableForeignKey

DestinationForeignKeysreturndestinationforeignkeys

func(JoinTableHandler)JoinWith
(https://github.com/jinzhu/gorm/blob/master/join_table_handler.go#L156)
func(sJoinTableHandler)JoinWith(handlerJoinTableHandlerInterface,db*DB,sourcei
nterface{})*DB

JoinWithquerywith`Join`conditions

func(*JoinTableHandler)Setup
(https://github.com/jinzhu/gorm/blob/master/join_table_handler.go#L58)
func(s*JoinTableHandler)Setup(relationship*Relationship,tableNamestring(/builti
n#string),sourcereflect(/reflect).Type(/reflect#Type),destinationreflect(/refle
ct).Type(/reflect#Type))

Setupinitializeadefaultjointablehandler

func(*JoinTableHandler)SourceForeignKeys
(https://github.com/jinzhu/gorm/blob/master/join_table_handler.go#L48)
func(s*JoinTableHandler)SourceForeignKeys()[]JoinTableForeignKey
https://godoc.org/github.com/jinzhu/gorm#DB.Close

20/28

28/05/2016

gorm - GoDoc

func(s*JoinTableHandler)SourceForeignKeys()[]JoinTableForeignKey

SourceForeignKeysreturnsourceforeignkeys

func(JoinTableHandler)Table
(https://github.com/jinzhu/gorm/blob/master/join_table_handler.go#L79)
func(sJoinTableHandler)Table(db*DB)string(/builtin#string)

Tablereturnjointable'stablename

typeJoinTableHandlerInterface
(https://github.com/jinzhu/gorm/blob/master/join_table_handler.go#L11)

typeJoinTableHandlerInterfaceinterface{
//initializejointablehandler
Setup(relationship*Relationship,tableNamestring(/builtin#string),sourcereflect(/reflect)
//Tablereturnjointable'stablename
Table(db*DB)string(/builtin#string)
//Addcreaterelationshipinjointableforsourceanddestination
Add(handlerJoinTableHandlerInterface,db*DB,sourceinterface{},destinationinterface{})
//Deletedeleterelationshipinjointableforsources
Delete(handlerJoinTableHandlerInterface,db*DB,sources...interface{})error(/builtin#error)
//JoinWithquerywith`Join`conditions
JoinWith(handlerJoinTableHandlerInterface,db*DB,sourceinterface{})*DB
//SourceForeignKeysreturnsourceforeignkeys
SourceForeignKeys()[]JoinTableForeignKey
//DestinationForeignKeysreturndestinationforeignkeys
DestinationForeignKeys()[]JoinTableForeignKey
}

JoinTableHandlerInterfaceisaninterfaceforhowtohandlemany2manyrelations

typeJoinTableSource
(https://github.com/jinzhu/gorm/blob/master/join_table_handler.go#L35)
typeJoinTableSourcestruct{
ModelTypereflect(/reflect).Type(/reflect#Type)
ForeignKeys[]JoinTableForeignKey
}

JoinTableSourceisastructthatcontainsmodeltypeandforeignkeys

typeLogWriter
(https://github.com/jinzhu/gorm/blob/master/logger.go#L24)
typeLogWriterinterface{
Println(v...interface{})

https://godoc.org/github.com/jinzhu/gorm#DB.Close

21/28

28/05/2016

gorm - GoDoc

Println(v...interface{})
}

LogWriterlogwriterinterface

typeLogger
(https://github.com/jinzhu/gorm/blob/master/logger.go#L29)
typeLoggerstruct{
LogWriter
}

Loggerdefaultlogger

func(Logger)Print(https://github.com/jinzhu/gorm/blob/master/logger.go#L34)
func(loggerLogger)Print(values...interface{})

Printformat&printlog

typeModel
(https://github.com/jinzhu/gorm/blob/master/model.go#L9)
typeModelstruct{
IDuint(/builtin#uint)`gorm:"primary_key"`
CreatedAttime(/time).Time(/time#Time)
UpdatedAttime(/time).Time(/time#Time)
DeletedAt*time(/time).Time(/time#Time)`sql:"index"`
}

Modelbasemodeldefinition,includingfields`ID`,`CreatedAt`,`UpdatedAt`,`DeletedAt`,whichcouldbe
embeddedinyourmodels
typeUserstruct{
gorm.Model
}

typeModelStruct
(https://github.com/jinzhu/gorm/blob/master/model_struct.go#L44)
typeModelStructstruct{
PrimaryFields[]*StructField
StructFields[]*StructField
ModelTypereflect(/reflect).Type(/reflect#Type)
//containsfilteredorunexportedfields
}

ModelStructmodeldefinition

func(*ModelStruct)TableName
(https://github.com/jinzhu/gorm/blob/master/model_struct.go#L52)
func(s*ModelStruct)TableName(db*DB)string(/builtin#string)

TableNamegetmodel'stablename
https://godoc.org/github.com/jinzhu/gorm#DB.Close

22/28

28/05/2016

gorm - GoDoc

typeRelationship
(https://github.com/jinzhu/gorm/blob/master/model_struct.go#L98)
typeRelationshipstruct{
Kindstring(/builtin#string)
PolymorphicTypestring(/builtin#string)
PolymorphicDBNamestring(/builtin#string)
ForeignFieldNames[]string(/builtin#string)
ForeignDBNames[]string(/builtin#string)
AssociationForeignFieldNames[]string(/builtin#string)
AssociationForeignDBNames[]string(/builtin#string)
JoinTableHandlerJoinTableHandlerInterface
}

Relationshipdescribedtherelationshipbetweenmodels

typeScope
(https://github.com/jinzhu/gorm/blob/master/scope.go#L17)
typeScopestruct{
Search*search
Valueinterface{}
SQLstring(/builtin#string)
SQLVars[]interface{}
//containsfilteredorunexportedfields
}

Scopecontaincurrentoperation'sinformationwhenyouperformanyoperationonthedatabase

func(*Scope)AddToVars(https://github.com/jinzhu/gorm/blob/master/scope.go#L255)
func(scope*Scope)AddToVars(valueinterface{})string(/builtin#string)

AddToVarsaddvalueassql'svars,usedtopreventSQLinjection

func(*Scope)Begin(https://github.com/jinzhu/gorm/blob/master/scope.go#L386)
func(scope*Scope)Begin()*Scope

Beginstartatransaction

func(*Scope)CallMethod(https://github.com/jinzhu/gorm/blob/master/scope.go#L240)
func(scope*Scope)CallMethod(methodNamestring(/builtin#string))

CallMethodcallscopevalue'smethod,ifitisaslice,willcallitselement'smethodonebyone

func(*Scope)CombinedConditionSql
(https://github.com/jinzhu/gorm/blob/master/scope.go#L331)
func(scope*Scope)CombinedConditionSql()string(/builtin#string)

CombinedConditionSqlreturncombinedconditionsql

func(*Scope)CommitOrRollback
(https://github.com/jinzhu/gorm/blob/master/scope.go#L397)
https://godoc.org/github.com/jinzhu/gorm#DB.Close

23/28

28/05/2016

gorm - GoDoc

func(scope*Scope)CommitOrRollback()*Scope

CommitOrRollbackcommitcurrenttransactionifnoerrorhappened,otherwisewillrollbackit

func(*Scope)DB(https://github.com/jinzhu/gorm/blob/master/scope.go#L45)
func(scope*Scope)DB()*DB

DBreturnscope'sDBconnection

func(*Scope)Dialect(https://github.com/jinzhu/gorm/blob/master/scope.go#L66)
func(scope*Scope)Dialect()Dialect

Dialectgetdialect

func(*Scope)Err(https://github.com/jinzhu/gorm/blob/master/scope.go#L84)

func(scope*Scope)Err(errerror(/builtin#error))error(/builtin#error)

ErradderrortoScope

func(*Scope)Exec(https://github.com/jinzhu/gorm/blob/master/scope.go#L343)
func(scope*Scope)Exec()*Scope

ExecperformgeneratedSQL

func(*Scope)FieldByName
(https://github.com/jinzhu/gorm/blob/master/scope.go#L133)
func(scope*Scope)FieldByName(namestring(/builtin#string))(field*Field,okbool
(/builtin#bool))

FieldByNamefind`gorm.Field`withfieldnameordbname

func(*Scope)Fields(https://github.com/jinzhu/gorm/blob/master/scope.go#L107)
func(scope*Scope)Fields()[]*Field

Fieldsgetvalue'sfields

func(*Scope)Get(https://github.com/jinzhu/gorm/blob/master/scope.go#L363)
func(scope*Scope)Get(namestring(/builtin#string))(interface{},bool(/builtin#bo
ol))

Getgetsettingbyname

func(*Scope)GetModelStruct
(https://github.com/jinzhu/gorm/blob/master/model_struct.go#L119)
func(scope*Scope)GetModelStruct()*ModelStruct

GetModelStructgetvalue'smodelstruct,relationshipsbasedonstructandtagdefinition

func(*Scope)GetStructFields
https://godoc.org/github.com/jinzhu/gorm#DB.Close

24/28

28/05/2016

gorm - GoDoc

func(*Scope)GetStructFields
(https://github.com/jinzhu/gorm/blob/master/model_struct.go#L529)
func(scope*Scope)GetStructFields()(fields[]*StructField)

GetStructFieldsgetmodel'sfieldstructs

func(*Scope)HasColumn(https://github.com/jinzhu/gorm/blob/master/scope.go#L196)
func(scope*Scope)HasColumn(columnstring(/builtin#string))bool(/builtin#bool)

HasColumntocheckifhascolumn

func(*Scope)HasError(https://github.com/jinzhu/gorm/blob/master/scope.go#L92)
func(scope*Scope)HasError()bool(/builtin#bool)

HasErrorcheckifthereareanyerror

func(*Scope)IndirectValue(https://github.com/jinzhu/gorm/blob/master/scope.go#L31)
func(scope*Scope)IndirectValue()reflect(/reflect).Value(/reflect#Value)

IndirectValuereturnscope'sreflectvalue'sindirectvalue

func(*Scope)InstanceGet(https://github.com/jinzhu/gorm/blob/master/scope.go#L381)
func(scope*Scope)InstanceGet(namestring(/builtin#string))(interface{},bool(/bu
iltin#bool))

InstanceGetgetinstancesettingfromcurrentoperation

func(*Scope)InstanceID(https://github.com/jinzhu/gorm/blob/master/scope.go#L368)
func(scope*Scope)InstanceID()string(/builtin#string)

InstanceIDgetInstanceIDforscope

func(*Scope)InstanceSet(https://github.com/jinzhu/gorm/blob/master/scope.go#L376)
func(scope*Scope)InstanceSet(namestring(/builtin#string),valueinterface{})*Sco
pe

InstanceSetsetinstancesettingforcurrentoperation,butnotforoperationsincallbacks,likesaving
associationscallback

func(*Scope)Log(https://github.com/jinzhu/gorm/blob/master/scope.go#L97)
func(scope*Scope)Log(v...interface{})

Logprintlogmessage

func(*Scope)New(https://github.com/jinzhu/gorm/blob/master/scope.go#L36)
func(scope*Scope)New(valueinterface{})*Scope

NewcreateanewScopewithoutsearchinformation

func(*Scope)NewDB(https://github.com/jinzhu/gorm/blob/master/scope.go#L50)
https://godoc.org/github.com/jinzhu/gorm#DB.Close

25/28

28/05/2016

gorm - GoDoc

func(scope*Scope)NewDB()*DB

NewDBcreateanewDBwithoutsearchinformation

func(*Scope)OmitAttrs(https://github.com/jinzhu/gorm/blob/master/scope.go#L289)
func(scope*Scope)OmitAttrs()[]string(/builtin#string)

OmitAttrsreturnomittedattributes

func(*Scope)PrimaryField
(https://github.com/jinzhu/gorm/blob/master/scope.go#L161)
func(scope*Scope)PrimaryField()*Field

PrimaryFieldreturnscope'smainprimaryfield,ifdefinedmorethatoneprimaryfields,willreturntheonehaving
columnname`id`orthefirstone

func(*Scope)PrimaryFields
(https://github.com/jinzhu/gorm/blob/master/scope.go#L151)
func(scope*Scope)PrimaryFields()(fields[]*Field)

PrimaryFieldsreturnscope'sprimaryfields

func(*Scope)PrimaryKey(https://github.com/jinzhu/gorm/blob/master/scope.go#L174)
func(scope*Scope)PrimaryKey()string(/builtin#string)

PrimaryKeygetmainprimaryfield'sdbname

func(*Scope)PrimaryKeyValue
(https://github.com/jinzhu/gorm/blob/master/scope.go#L188)
func(scope*Scope)PrimaryKeyValue()interface{}

PrimaryKeyValuegettheprimarykey'svalue

func(*Scope)PrimaryKeyZero
(https://github.com/jinzhu/gorm/blob/master/scope.go#L182)
func(scope*Scope)PrimaryKeyZero()bool(/builtin#bool)

PrimaryKeyZerocheckmainprimaryfield'svalueisblankornot

func(*Scope)Quote(https://github.com/jinzhu/gorm/blob/master/scope.go#L71)
func(scope*Scope)Quote(strstring(/builtin#string))string(/builtin#string)

Quoteusedtoquotestringtoescapethemfordatabase

func(*Scope)QuotedTableName
(https://github.com/jinzhu/gorm/blob/master/scope.go#L319)
func(scope*Scope)QuotedTableName()(namestring(/builtin#string))

QuotedTableNamereturnquotedtablename
https://godoc.org/github.com/jinzhu/gorm#DB.Close

26/28

28/05/2016

gorm - GoDoc

func(*Scope)Raw(https://github.com/jinzhu/gorm/blob/master/scope.go#L337)
func(scope*Scope)Raw(sqlstring(/builtin#string))*Scope

Rawsetrawsql

func(*Scope)SQLDB(https://github.com/jinzhu/gorm/blob/master/scope.go#L61)
func(scope*Scope)SQLDB()sqlCommon

SQLDBreturn*sql.DB

func(*Scope)SelectAttrs(https://github.com/jinzhu/gorm/blob/master/scope.go#L269)
func(scope*Scope)SelectAttrs()[]string(/builtin#string)

SelectAttrsreturnselectedattributes

func(*Scope)Set(https://github.com/jinzhu/gorm/blob/master/scope.go#L357)
func(scope*Scope)Set(namestring(/builtin#string),valueinterface{})*Scope

Setsetvaluebyname

func(*Scope)SetColumn(https://github.com/jinzhu/gorm/blob/master/scope.go#L206)
func(scope*Scope)SetColumn(columninterface{},valueinterface{})error(/builtin#e
rror)

SetColumntosetthecolumn'svalue,columncouldbefieldorfield'sname/dbname

func(*Scope)SkipLeft(https://github.com/jinzhu/gorm/blob/master/scope.go#L102)
func(scope*Scope)SkipLeft()

SkipLeftskipremainingcallbacks

func(*Scope)TableName(https://github.com/jinzhu/gorm/blob/master/scope.go#L302)
func(scope*Scope)TableName()string(/builtin#string)

TableNamereturntablename

typeStructField
(https://github.com/jinzhu/gorm/blob/master/model_struct.go#L57)
typeStructFieldstruct{
DBNamestring(/builtin#string)
Namestring(/builtin#string)
Names[]string(/builtin#string)
IsPrimaryKeybool(/builtin#bool)
IsNormalbool(/builtin#bool)
IsIgnoredbool(/builtin#bool)
IsScannerbool(/builtin#bool)
HasDefaultValuebool(/builtin#bool)
Tagreflect(/reflect).StructTag(/reflect#StructTag)
TagSettingsmap[string(/builtin#string)]string(/builtin#string)
Structreflect(/reflect).StructField(/reflect#StructField)
https://godoc.org/github.com/jinzhu/gorm#DB.Close

27/28

28/05/2016

gorm - GoDoc

Structreflect(/reflect).StructField(/reflect#StructField)
IsForeignKeybool(/builtin#bool)
Relationship*Relationship
}

StructFieldmodelfield'sstructdefinition

Directories
Path

Synopsis

dialects/mssql(/github.com/jinzhu/gorm/dialects/mssql)
dialects/mysql(/github.com/jinzhu/gorm/dialects/mysql)
dialects/postgres(/github.com/jinzhu/gorm/dialects/postgres)
dialects/sqlite(/github.com/jinzhu/gorm/dialects/sqlite)

Packagegormimports19packages(?imports)(graph(?importgraph))andisimportedby413packages(?
importers).Updated7daysago.Refreshnow.Tools(?tools)forpackageowners.

WebsiteIssues(https://github.com/golang/gddo/issues)|GoLanguage(http://golang.org/)

https://godoc.org/github.com/jinzhu/gorm#DB.Close

Backtotop

28/28

Das könnte Ihnen auch gefallen