id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
126,500 | jinzhu/gorm | scope.go | IndirectValue | func (scope *Scope) IndirectValue() reflect.Value {
return indirect(reflect.ValueOf(scope.Value))
} | go | func (scope *Scope) IndirectValue() reflect.Value {
return indirect(reflect.ValueOf(scope.Value))
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"IndirectValue",
"(",
")",
"reflect",
".",
"Value",
"{",
"return",
"indirect",
"(",
"reflect",
".",
"ValueOf",
"(",
"scope",
".",
"Value",
")",
")",
"\n",
"}"
] | // IndirectValue return scope's reflect value's indirect value | [
"IndirectValue",
"return",
"scope",
"s",
"reflect",
"value",
"s",
"indirect",
"value"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L30-L32 |
126,501 | jinzhu/gorm | scope.go | New | func (scope *Scope) New(value interface{}) *Scope {
return &Scope{db: scope.NewDB(), Search: &search{}, Value: value}
} | go | func (scope *Scope) New(value interface{}) *Scope {
return &Scope{db: scope.NewDB(), Search: &search{}, Value: value}
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"New",
"(",
"value",
"interface",
"{",
"}",
")",
"*",
"Scope",
"{",
"return",
"&",
"Scope",
"{",
"db",
":",
"scope",
".",
"NewDB",
"(",
")",
",",
"Search",
":",
"&",
"search",
"{",
"}",
",",
"Value",
":"... | // New create a new Scope without search information | [
"New",
"create",
"a",
"new",
"Scope",
"without",
"search",
"information"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L35-L37 |
126,502 | jinzhu/gorm | scope.go | NewDB | func (scope *Scope) NewDB() *DB {
if scope.db != nil {
db := scope.db.clone()
db.search = nil
db.Value = nil
return db
}
return nil
} | go | func (scope *Scope) NewDB() *DB {
if scope.db != nil {
db := scope.db.clone()
db.search = nil
db.Value = nil
return db
}
return nil
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"NewDB",
"(",
")",
"*",
"DB",
"{",
"if",
"scope",
".",
"db",
"!=",
"nil",
"{",
"db",
":=",
"scope",
".",
"db",
".",
"clone",
"(",
")",
"\n",
"db",
".",
"search",
"=",
"nil",
"\n",
"db",
".",
"Value",
... | // NewDB create a new DB without search information | [
"NewDB",
"create",
"a",
"new",
"DB",
"without",
"search",
"information"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L49-L57 |
126,503 | jinzhu/gorm | scope.go | Quote | func (scope *Scope) Quote(str string) string {
if strings.Contains(str, ".") {
newStrs := []string{}
for _, str := range strings.Split(str, ".") {
newStrs = append(newStrs, scope.Dialect().Quote(str))
}
return strings.Join(newStrs, ".")
}
return scope.Dialect().Quote(str)
} | go | func (scope *Scope) Quote(str string) string {
if strings.Contains(str, ".") {
newStrs := []string{}
for _, str := range strings.Split(str, ".") {
newStrs = append(newStrs, scope.Dialect().Quote(str))
}
return strings.Join(newStrs, ".")
}
return scope.Dialect().Quote(str)
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"Quote",
"(",
"str",
"string",
")",
"string",
"{",
"if",
"strings",
".",
"Contains",
"(",
"str",
",",
"\"",
"\"",
")",
"{",
"newStrs",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"str",
":... | // Quote used to quote string to escape them for database | [
"Quote",
"used",
"to",
"quote",
"string",
"to",
"escape",
"them",
"for",
"database"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L70-L80 |
126,504 | jinzhu/gorm | scope.go | Err | func (scope *Scope) Err(err error) error {
if err != nil {
scope.db.AddError(err)
}
return err
} | go | func (scope *Scope) Err(err error) error {
if err != nil {
scope.db.AddError(err)
}
return err
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"Err",
"(",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"!=",
"nil",
"{",
"scope",
".",
"db",
".",
"AddError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // Err add error to Scope | [
"Err",
"add",
"error",
"to",
"Scope"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L83-L88 |
126,505 | jinzhu/gorm | scope.go | Fields | func (scope *Scope) Fields() []*Field {
if scope.fields == nil {
var (
fields []*Field
indirectScopeValue = scope.IndirectValue()
isStruct = indirectScopeValue.Kind() == reflect.Struct
)
for _, structField := range scope.GetModelStruct().StructFields {
if isStruct {
fieldVa... | go | func (scope *Scope) Fields() []*Field {
if scope.fields == nil {
var (
fields []*Field
indirectScopeValue = scope.IndirectValue()
isStruct = indirectScopeValue.Kind() == reflect.Struct
)
for _, structField := range scope.GetModelStruct().StructFields {
if isStruct {
fieldVa... | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"Fields",
"(",
")",
"[",
"]",
"*",
"Field",
"{",
"if",
"scope",
".",
"fields",
"==",
"nil",
"{",
"var",
"(",
"fields",
"[",
"]",
"*",
"Field",
"\n",
"indirectScopeValue",
"=",
"scope",
".",
"IndirectValue",
... | // Fields get value's fields | [
"Fields",
"get",
"value",
"s",
"fields"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L106-L132 |
126,506 | jinzhu/gorm | scope.go | FieldByName | func (scope *Scope) FieldByName(name string) (field *Field, ok bool) {
var (
dbName = ToColumnName(name)
mostMatchedField *Field
)
for _, field := range scope.Fields() {
if field.Name == name || field.DBName == name {
return field, true
}
if field.DBName == dbName {
mostMatchedField = fiel... | go | func (scope *Scope) FieldByName(name string) (field *Field, ok bool) {
var (
dbName = ToColumnName(name)
mostMatchedField *Field
)
for _, field := range scope.Fields() {
if field.Name == name || field.DBName == name {
return field, true
}
if field.DBName == dbName {
mostMatchedField = fiel... | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"FieldByName",
"(",
"name",
"string",
")",
"(",
"field",
"*",
"Field",
",",
"ok",
"bool",
")",
"{",
"var",
"(",
"dbName",
"=",
"ToColumnName",
"(",
"name",
")",
"\n",
"mostMatchedField",
"*",
"Field",
"\n",
")... | // FieldByName find `gorm.Field` with field name or db name | [
"FieldByName",
"find",
"gorm",
".",
"Field",
"with",
"field",
"name",
"or",
"db",
"name"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L135-L150 |
126,507 | jinzhu/gorm | scope.go | PrimaryFields | func (scope *Scope) PrimaryFields() (fields []*Field) {
for _, field := range scope.Fields() {
if field.IsPrimaryKey {
fields = append(fields, field)
}
}
return fields
} | go | func (scope *Scope) PrimaryFields() (fields []*Field) {
for _, field := range scope.Fields() {
if field.IsPrimaryKey {
fields = append(fields, field)
}
}
return fields
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"PrimaryFields",
"(",
")",
"(",
"fields",
"[",
"]",
"*",
"Field",
")",
"{",
"for",
"_",
",",
"field",
":=",
"range",
"scope",
".",
"Fields",
"(",
")",
"{",
"if",
"field",
".",
"IsPrimaryKey",
"{",
"fields",
... | // PrimaryFields return scope's primary fields | [
"PrimaryFields",
"return",
"scope",
"s",
"primary",
"fields"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L153-L160 |
126,508 | jinzhu/gorm | scope.go | PrimaryField | func (scope *Scope) PrimaryField() *Field {
if primaryFields := scope.GetModelStruct().PrimaryFields; len(primaryFields) > 0 {
if len(primaryFields) > 1 {
if field, ok := scope.FieldByName("id"); ok {
return field
}
}
return scope.PrimaryFields()[0]
}
return nil
} | go | func (scope *Scope) PrimaryField() *Field {
if primaryFields := scope.GetModelStruct().PrimaryFields; len(primaryFields) > 0 {
if len(primaryFields) > 1 {
if field, ok := scope.FieldByName("id"); ok {
return field
}
}
return scope.PrimaryFields()[0]
}
return nil
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"PrimaryField",
"(",
")",
"*",
"Field",
"{",
"if",
"primaryFields",
":=",
"scope",
".",
"GetModelStruct",
"(",
")",
".",
"PrimaryFields",
";",
"len",
"(",
"primaryFields",
")",
">",
"0",
"{",
"if",
"len",
"(",
... | // PrimaryField return scope's main primary field, if defined more that one primary fields, will return the one having column name `id` or the first one | [
"PrimaryField",
"return",
"scope",
"s",
"main",
"primary",
"field",
"if",
"defined",
"more",
"that",
"one",
"primary",
"fields",
"will",
"return",
"the",
"one",
"having",
"column",
"name",
"id",
"or",
"the",
"first",
"one"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L163-L173 |
126,509 | jinzhu/gorm | scope.go | PrimaryKey | func (scope *Scope) PrimaryKey() string {
if field := scope.PrimaryField(); field != nil {
return field.DBName
}
return ""
} | go | func (scope *Scope) PrimaryKey() string {
if field := scope.PrimaryField(); field != nil {
return field.DBName
}
return ""
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"PrimaryKey",
"(",
")",
"string",
"{",
"if",
"field",
":=",
"scope",
".",
"PrimaryField",
"(",
")",
";",
"field",
"!=",
"nil",
"{",
"return",
"field",
".",
"DBName",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\... | // PrimaryKey get main primary field's db name | [
"PrimaryKey",
"get",
"main",
"primary",
"field",
"s",
"db",
"name"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L176-L181 |
126,510 | jinzhu/gorm | scope.go | PrimaryKeyZero | func (scope *Scope) PrimaryKeyZero() bool {
field := scope.PrimaryField()
return field == nil || field.IsBlank
} | go | func (scope *Scope) PrimaryKeyZero() bool {
field := scope.PrimaryField()
return field == nil || field.IsBlank
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"PrimaryKeyZero",
"(",
")",
"bool",
"{",
"field",
":=",
"scope",
".",
"PrimaryField",
"(",
")",
"\n",
"return",
"field",
"==",
"nil",
"||",
"field",
".",
"IsBlank",
"\n",
"}"
] | // PrimaryKeyZero check main primary field's value is blank or not | [
"PrimaryKeyZero",
"check",
"main",
"primary",
"field",
"s",
"value",
"is",
"blank",
"or",
"not"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L184-L187 |
126,511 | jinzhu/gorm | scope.go | PrimaryKeyValue | func (scope *Scope) PrimaryKeyValue() interface{} {
if field := scope.PrimaryField(); field != nil && field.Field.IsValid() {
return field.Field.Interface()
}
return 0
} | go | func (scope *Scope) PrimaryKeyValue() interface{} {
if field := scope.PrimaryField(); field != nil && field.Field.IsValid() {
return field.Field.Interface()
}
return 0
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"PrimaryKeyValue",
"(",
")",
"interface",
"{",
"}",
"{",
"if",
"field",
":=",
"scope",
".",
"PrimaryField",
"(",
")",
";",
"field",
"!=",
"nil",
"&&",
"field",
".",
"Field",
".",
"IsValid",
"(",
")",
"{",
"r... | // PrimaryKeyValue get the primary key's value | [
"PrimaryKeyValue",
"get",
"the",
"primary",
"key",
"s",
"value"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L190-L195 |
126,512 | jinzhu/gorm | scope.go | HasColumn | func (scope *Scope) HasColumn(column string) bool {
for _, field := range scope.GetStructFields() {
if field.IsNormal && (field.Name == column || field.DBName == column) {
return true
}
}
return false
} | go | func (scope *Scope) HasColumn(column string) bool {
for _, field := range scope.GetStructFields() {
if field.IsNormal && (field.Name == column || field.DBName == column) {
return true
}
}
return false
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"HasColumn",
"(",
"column",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"field",
":=",
"range",
"scope",
".",
"GetStructFields",
"(",
")",
"{",
"if",
"field",
".",
"IsNormal",
"&&",
"(",
"field",
".",
"Name",... | // HasColumn to check if has column | [
"HasColumn",
"to",
"check",
"if",
"has",
"column"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L198-L205 |
126,513 | jinzhu/gorm | scope.go | CallMethod | func (scope *Scope) CallMethod(methodName string) {
if scope.Value == nil {
return
}
if indirectScopeValue := scope.IndirectValue(); indirectScopeValue.Kind() == reflect.Slice {
for i := 0; i < indirectScopeValue.Len(); i++ {
scope.callMethod(methodName, indirectScopeValue.Index(i))
}
} else {
scope.cal... | go | func (scope *Scope) CallMethod(methodName string) {
if scope.Value == nil {
return
}
if indirectScopeValue := scope.IndirectValue(); indirectScopeValue.Kind() == reflect.Slice {
for i := 0; i < indirectScopeValue.Len(); i++ {
scope.callMethod(methodName, indirectScopeValue.Index(i))
}
} else {
scope.cal... | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"CallMethod",
"(",
"methodName",
"string",
")",
"{",
"if",
"scope",
".",
"Value",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"indirectScopeValue",
":=",
"scope",
".",
"IndirectValue",
"(",
")",
";",
"i... | // CallMethod call scope value's method, if it is a slice, will call its element's method one by one | [
"CallMethod",
"call",
"scope",
"value",
"s",
"method",
"if",
"it",
"is",
"a",
"slice",
"will",
"call",
"its",
"element",
"s",
"method",
"one",
"by",
"one"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L242-L254 |
126,514 | jinzhu/gorm | scope.go | AddToVars | func (scope *Scope) AddToVars(value interface{}) string {
_, skipBindVar := scope.InstanceGet("skip_bindvar")
if expr, ok := value.(*expr); ok {
exp := expr.expr
for _, arg := range expr.args {
if skipBindVar {
scope.AddToVars(arg)
} else {
exp = strings.Replace(exp, "?", scope.AddToVars(arg), 1)
... | go | func (scope *Scope) AddToVars(value interface{}) string {
_, skipBindVar := scope.InstanceGet("skip_bindvar")
if expr, ok := value.(*expr); ok {
exp := expr.expr
for _, arg := range expr.args {
if skipBindVar {
scope.AddToVars(arg)
} else {
exp = strings.Replace(exp, "?", scope.AddToVars(arg), 1)
... | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"AddToVars",
"(",
"value",
"interface",
"{",
"}",
")",
"string",
"{",
"_",
",",
"skipBindVar",
":=",
"scope",
".",
"InstanceGet",
"(",
"\"",
"\"",
")",
"\n\n",
"if",
"expr",
",",
"ok",
":=",
"value",
".",
"(... | // AddToVars add value as sql's vars, used to prevent SQL injection | [
"AddToVars",
"add",
"value",
"as",
"sql",
"s",
"vars",
"used",
"to",
"prevent",
"SQL",
"injection"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L257-L278 |
126,515 | jinzhu/gorm | scope.go | SelectAttrs | func (scope *Scope) SelectAttrs() []string {
if scope.selectAttrs == nil {
attrs := []string{}
for _, value := range scope.Search.selects {
if str, ok := value.(string); ok {
attrs = append(attrs, str)
} else if strs, ok := value.([]string); ok {
attrs = append(attrs, strs...)
} else if strs, ok :... | go | func (scope *Scope) SelectAttrs() []string {
if scope.selectAttrs == nil {
attrs := []string{}
for _, value := range scope.Search.selects {
if str, ok := value.(string); ok {
attrs = append(attrs, str)
} else if strs, ok := value.([]string); ok {
attrs = append(attrs, strs...)
} else if strs, ok :... | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"SelectAttrs",
"(",
")",
"[",
"]",
"string",
"{",
"if",
"scope",
".",
"selectAttrs",
"==",
"nil",
"{",
"attrs",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"value",
":=",
"range",
"scope",
"... | // SelectAttrs return selected attributes | [
"SelectAttrs",
"return",
"selected",
"attributes"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L281-L298 |
126,516 | jinzhu/gorm | scope.go | TableName | func (scope *Scope) TableName() string {
if scope.Search != nil && len(scope.Search.tableName) > 0 {
return scope.Search.tableName
}
if tabler, ok := scope.Value.(tabler); ok {
return tabler.TableName()
}
if tabler, ok := scope.Value.(dbTabler); ok {
return tabler.TableName(scope.db)
}
return scope.GetM... | go | func (scope *Scope) TableName() string {
if scope.Search != nil && len(scope.Search.tableName) > 0 {
return scope.Search.tableName
}
if tabler, ok := scope.Value.(tabler); ok {
return tabler.TableName()
}
if tabler, ok := scope.Value.(dbTabler); ok {
return tabler.TableName(scope.db)
}
return scope.GetM... | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"TableName",
"(",
")",
"string",
"{",
"if",
"scope",
".",
"Search",
"!=",
"nil",
"&&",
"len",
"(",
"scope",
".",
"Search",
".",
"tableName",
")",
">",
"0",
"{",
"return",
"scope",
".",
"Search",
".",
"tableN... | // TableName return table name | [
"TableName",
"return",
"table",
"name"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L314-L328 |
126,517 | jinzhu/gorm | scope.go | QuotedTableName | func (scope *Scope) QuotedTableName() (name string) {
if scope.Search != nil && len(scope.Search.tableName) > 0 {
if strings.Contains(scope.Search.tableName, " ") {
return scope.Search.tableName
}
return scope.Quote(scope.Search.tableName)
}
return scope.Quote(scope.TableName())
} | go | func (scope *Scope) QuotedTableName() (name string) {
if scope.Search != nil && len(scope.Search.tableName) > 0 {
if strings.Contains(scope.Search.tableName, " ") {
return scope.Search.tableName
}
return scope.Quote(scope.Search.tableName)
}
return scope.Quote(scope.TableName())
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"QuotedTableName",
"(",
")",
"(",
"name",
"string",
")",
"{",
"if",
"scope",
".",
"Search",
"!=",
"nil",
"&&",
"len",
"(",
"scope",
".",
"Search",
".",
"tableName",
")",
">",
"0",
"{",
"if",
"strings",
".",
... | // QuotedTableName return quoted table name | [
"QuotedTableName",
"return",
"quoted",
"table",
"name"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L331-L340 |
126,518 | jinzhu/gorm | scope.go | CombinedConditionSql | func (scope *Scope) CombinedConditionSql() string {
joinSQL := scope.joinsSQL()
whereSQL := scope.whereSQL()
if scope.Search.raw {
whereSQL = strings.TrimSuffix(strings.TrimPrefix(whereSQL, "WHERE ("), ")")
}
return joinSQL + whereSQL + scope.groupSQL() +
scope.havingSQL() + scope.orderSQL() + scope.limitAndOf... | go | func (scope *Scope) CombinedConditionSql() string {
joinSQL := scope.joinsSQL()
whereSQL := scope.whereSQL()
if scope.Search.raw {
whereSQL = strings.TrimSuffix(strings.TrimPrefix(whereSQL, "WHERE ("), ")")
}
return joinSQL + whereSQL + scope.groupSQL() +
scope.havingSQL() + scope.orderSQL() + scope.limitAndOf... | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"CombinedConditionSql",
"(",
")",
"string",
"{",
"joinSQL",
":=",
"scope",
".",
"joinsSQL",
"(",
")",
"\n",
"whereSQL",
":=",
"scope",
".",
"whereSQL",
"(",
")",
"\n",
"if",
"scope",
".",
"Search",
".",
"raw",
... | // CombinedConditionSql return combined condition sql | [
"CombinedConditionSql",
"return",
"combined",
"condition",
"sql"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L343-L351 |
126,519 | jinzhu/gorm | scope.go | Raw | func (scope *Scope) Raw(sql string) *Scope {
scope.SQL = strings.Replace(sql, "$$$", "?", -1)
return scope
} | go | func (scope *Scope) Raw(sql string) *Scope {
scope.SQL = strings.Replace(sql, "$$$", "?", -1)
return scope
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"Raw",
"(",
"sql",
"string",
")",
"*",
"Scope",
"{",
"scope",
".",
"SQL",
"=",
"strings",
".",
"Replace",
"(",
"sql",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"return",
"scope",
"\n",
... | // Raw set raw sql | [
"Raw",
"set",
"raw",
"sql"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L354-L357 |
126,520 | jinzhu/gorm | scope.go | Exec | func (scope *Scope) Exec() *Scope {
defer scope.trace(NowFunc())
if !scope.HasError() {
if result, err := scope.SQLDB().Exec(scope.SQL, scope.SQLVars...); scope.Err(err) == nil {
if count, err := result.RowsAffected(); scope.Err(err) == nil {
scope.db.RowsAffected = count
}
}
}
return scope
} | go | func (scope *Scope) Exec() *Scope {
defer scope.trace(NowFunc())
if !scope.HasError() {
if result, err := scope.SQLDB().Exec(scope.SQL, scope.SQLVars...); scope.Err(err) == nil {
if count, err := result.RowsAffected(); scope.Err(err) == nil {
scope.db.RowsAffected = count
}
}
}
return scope
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"Exec",
"(",
")",
"*",
"Scope",
"{",
"defer",
"scope",
".",
"trace",
"(",
"NowFunc",
"(",
")",
")",
"\n\n",
"if",
"!",
"scope",
".",
"HasError",
"(",
")",
"{",
"if",
"result",
",",
"err",
":=",
"scope",
... | // Exec perform generated SQL | [
"Exec",
"perform",
"generated",
"SQL"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L360-L371 |
126,521 | jinzhu/gorm | scope.go | Set | func (scope *Scope) Set(name string, value interface{}) *Scope {
scope.db.InstantSet(name, value)
return scope
} | go | func (scope *Scope) Set(name string, value interface{}) *Scope {
scope.db.InstantSet(name, value)
return scope
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"Set",
"(",
"name",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"*",
"Scope",
"{",
"scope",
".",
"db",
".",
"InstantSet",
"(",
"name",
",",
"value",
")",
"\n",
"return",
"scope",
"\n",
"}"
] | // Set set value by name | [
"Set",
"set",
"value",
"by",
"name"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L374-L377 |
126,522 | jinzhu/gorm | scope.go | InstanceID | func (scope *Scope) InstanceID() string {
if scope.instanceID == "" {
scope.instanceID = fmt.Sprintf("%v%v", &scope, &scope.db)
}
return scope.instanceID
} | go | func (scope *Scope) InstanceID() string {
if scope.instanceID == "" {
scope.instanceID = fmt.Sprintf("%v%v", &scope, &scope.db)
}
return scope.instanceID
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"InstanceID",
"(",
")",
"string",
"{",
"if",
"scope",
".",
"instanceID",
"==",
"\"",
"\"",
"{",
"scope",
".",
"instanceID",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"&",
"scope",
",",
"&",
"scope",
... | // InstanceID get InstanceID for scope | [
"InstanceID",
"get",
"InstanceID",
"for",
"scope"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L385-L390 |
126,523 | jinzhu/gorm | scope.go | InstanceSet | func (scope *Scope) InstanceSet(name string, value interface{}) *Scope {
return scope.Set(name+scope.InstanceID(), value)
} | go | func (scope *Scope) InstanceSet(name string, value interface{}) *Scope {
return scope.Set(name+scope.InstanceID(), value)
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"InstanceSet",
"(",
"name",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"*",
"Scope",
"{",
"return",
"scope",
".",
"Set",
"(",
"name",
"+",
"scope",
".",
"InstanceID",
"(",
")",
",",
"value",
")",
"\... | // InstanceSet set instance setting for current operation, but not for operations in callbacks, like saving associations callback | [
"InstanceSet",
"set",
"instance",
"setting",
"for",
"current",
"operation",
"but",
"not",
"for",
"operations",
"in",
"callbacks",
"like",
"saving",
"associations",
"callback"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L393-L395 |
126,524 | jinzhu/gorm | scope.go | InstanceGet | func (scope *Scope) InstanceGet(name string) (interface{}, bool) {
return scope.Get(name + scope.InstanceID())
} | go | func (scope *Scope) InstanceGet(name string) (interface{}, bool) {
return scope.Get(name + scope.InstanceID())
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"InstanceGet",
"(",
"name",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"return",
"scope",
".",
"Get",
"(",
"name",
"+",
"scope",
".",
"InstanceID",
"(",
")",
")",
"\n",
"}"
] | // InstanceGet get instance setting from current operation | [
"InstanceGet",
"get",
"instance",
"setting",
"from",
"current",
"operation"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L398-L400 |
126,525 | jinzhu/gorm | scope.go | Begin | func (scope *Scope) Begin() *Scope {
if db, ok := scope.SQLDB().(sqlDb); ok {
if tx, err := db.Begin(); err == nil {
scope.db.db = interface{}(tx).(SQLCommon)
scope.InstanceSet("gorm:started_transaction", true)
}
}
return scope
} | go | func (scope *Scope) Begin() *Scope {
if db, ok := scope.SQLDB().(sqlDb); ok {
if tx, err := db.Begin(); err == nil {
scope.db.db = interface{}(tx).(SQLCommon)
scope.InstanceSet("gorm:started_transaction", true)
}
}
return scope
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"Begin",
"(",
")",
"*",
"Scope",
"{",
"if",
"db",
",",
"ok",
":=",
"scope",
".",
"SQLDB",
"(",
")",
".",
"(",
"sqlDb",
")",
";",
"ok",
"{",
"if",
"tx",
",",
"err",
":=",
"db",
".",
"Begin",
"(",
")",... | // Begin start a transaction | [
"Begin",
"start",
"a",
"transaction"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L403-L411 |
126,526 | jinzhu/gorm | scope.go | CommitOrRollback | func (scope *Scope) CommitOrRollback() *Scope {
if _, ok := scope.InstanceGet("gorm:started_transaction"); ok {
if db, ok := scope.db.db.(sqlTx); ok {
if scope.HasError() {
db.Rollback()
} else {
scope.Err(db.Commit())
}
scope.db.db = scope.db.parent.db
}
}
return scope
} | go | func (scope *Scope) CommitOrRollback() *Scope {
if _, ok := scope.InstanceGet("gorm:started_transaction"); ok {
if db, ok := scope.db.db.(sqlTx); ok {
if scope.HasError() {
db.Rollback()
} else {
scope.Err(db.Commit())
}
scope.db.db = scope.db.parent.db
}
}
return scope
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"CommitOrRollback",
"(",
")",
"*",
"Scope",
"{",
"if",
"_",
",",
"ok",
":=",
"scope",
".",
"InstanceGet",
"(",
"\"",
"\"",
")",
";",
"ok",
"{",
"if",
"db",
",",
"ok",
":=",
"scope",
".",
"db",
".",
"db",... | // CommitOrRollback commit current transaction if no error happened, otherwise will rollback it | [
"CommitOrRollback",
"commit",
"current",
"transaction",
"if",
"no",
"error",
"happened",
"otherwise",
"will",
"rollback",
"it"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L414-L426 |
126,527 | jinzhu/gorm | scope.go | trace | func (scope *Scope) trace(t time.Time) {
if len(scope.SQL) > 0 {
scope.db.slog(scope.SQL, t, scope.SQLVars...)
}
} | go | func (scope *Scope) trace(t time.Time) {
if len(scope.SQL) > 0 {
scope.db.slog(scope.SQL, t, scope.SQLVars...)
}
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"trace",
"(",
"t",
"time",
".",
"Time",
")",
"{",
"if",
"len",
"(",
"scope",
".",
"SQL",
")",
">",
"0",
"{",
"scope",
".",
"db",
".",
"slog",
"(",
"scope",
".",
"SQL",
",",
"t",
",",
"scope",
".",
"S... | // trace print sql log | [
"trace",
"print",
"sql",
"log"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L1039-L1043 |
126,528 | jinzhu/gorm | scope.go | getTableOptions | func (scope *Scope) getTableOptions() string {
tableOptions, ok := scope.Get("gorm:table_options")
if !ok {
return ""
}
return " " + tableOptions.(string)
} | go | func (scope *Scope) getTableOptions() string {
tableOptions, ok := scope.Get("gorm:table_options")
if !ok {
return ""
}
return " " + tableOptions.(string)
} | [
"func",
"(",
"scope",
"*",
"Scope",
")",
"getTableOptions",
"(",
")",
"string",
"{",
"tableOptions",
",",
"ok",
":=",
"scope",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"\"",
"\... | // getTableOptions return the table options string or an empty string if the table options does not exist | [
"getTableOptions",
"return",
"the",
"table",
"options",
"string",
"or",
"an",
"empty",
"string",
"if",
"the",
"table",
"options",
"does",
"not",
"exist"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/scope.go#L1113-L1119 |
126,529 | jinzhu/gorm | join_table_handler.go | Setup | func (s *JoinTableHandler) Setup(relationship *Relationship, tableName string, source reflect.Type, destination reflect.Type) {
s.TableName = tableName
s.Source = JoinTableSource{ModelType: source}
s.Source.ForeignKeys = []JoinTableForeignKey{}
for idx, dbName := range relationship.ForeignFieldNames {
s.Source.F... | go | func (s *JoinTableHandler) Setup(relationship *Relationship, tableName string, source reflect.Type, destination reflect.Type) {
s.TableName = tableName
s.Source = JoinTableSource{ModelType: source}
s.Source.ForeignKeys = []JoinTableForeignKey{}
for idx, dbName := range relationship.ForeignFieldNames {
s.Source.F... | [
"func",
"(",
"s",
"*",
"JoinTableHandler",
")",
"Setup",
"(",
"relationship",
"*",
"Relationship",
",",
"tableName",
"string",
",",
"source",
"reflect",
".",
"Type",
",",
"destination",
"reflect",
".",
"Type",
")",
"{",
"s",
".",
"TableName",
"=",
"tableNa... | // Setup initialize a default join table handler | [
"Setup",
"initialize",
"a",
"default",
"join",
"table",
"handler"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/join_table_handler.go#L58-L78 |
126,530 | jinzhu/gorm | join_table_handler.go | Table | func (s JoinTableHandler) Table(db *DB) string {
return DefaultTableNameHandler(db, s.TableName)
} | go | func (s JoinTableHandler) Table(db *DB) string {
return DefaultTableNameHandler(db, s.TableName)
} | [
"func",
"(",
"s",
"JoinTableHandler",
")",
"Table",
"(",
"db",
"*",
"DB",
")",
"string",
"{",
"return",
"DefaultTableNameHandler",
"(",
"db",
",",
"s",
".",
"TableName",
")",
"\n",
"}"
] | // Table return join table's table name | [
"Table",
"return",
"join",
"table",
"s",
"table",
"name"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/join_table_handler.go#L81-L83 |
126,531 | jinzhu/gorm | join_table_handler.go | Add | func (s JoinTableHandler) Add(handler JoinTableHandlerInterface, db *DB, source interface{}, destination interface{}) error {
var (
scope = db.NewScope("")
conditionMap = map[string]interface{}{}
)
// Update condition map for source
s.updateConditionMap(conditionMap, db, []JoinTableSource{s.Source}, sou... | go | func (s JoinTableHandler) Add(handler JoinTableHandlerInterface, db *DB, source interface{}, destination interface{}) error {
var (
scope = db.NewScope("")
conditionMap = map[string]interface{}{}
)
// Update condition map for source
s.updateConditionMap(conditionMap, db, []JoinTableSource{s.Source}, sou... | [
"func",
"(",
"s",
"JoinTableHandler",
")",
"Add",
"(",
"handler",
"JoinTableHandlerInterface",
",",
"db",
"*",
"DB",
",",
"source",
"interface",
"{",
"}",
",",
"destination",
"interface",
"{",
"}",
")",
"error",
"{",
"var",
"(",
"scope",
"=",
"db",
".",
... | // Add create relationship in join table for source and destination | [
"Add",
"create",
"relationship",
"in",
"join",
"table",
"for",
"source",
"and",
"destination"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/join_table_handler.go#L104-L141 |
126,532 | jinzhu/gorm | join_table_handler.go | Delete | func (s JoinTableHandler) Delete(handler JoinTableHandlerInterface, db *DB, sources ...interface{}) error {
var (
scope = db.NewScope(nil)
conditions []string
values []interface{}
conditionMap = map[string]interface{}{}
)
s.updateConditionMap(conditionMap, db, []JoinTableSource{s.Source, s.De... | go | func (s JoinTableHandler) Delete(handler JoinTableHandlerInterface, db *DB, sources ...interface{}) error {
var (
scope = db.NewScope(nil)
conditions []string
values []interface{}
conditionMap = map[string]interface{}{}
)
s.updateConditionMap(conditionMap, db, []JoinTableSource{s.Source, s.De... | [
"func",
"(",
"s",
"JoinTableHandler",
")",
"Delete",
"(",
"handler",
"JoinTableHandlerInterface",
",",
"db",
"*",
"DB",
",",
"sources",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"var",
"(",
"scope",
"=",
"db",
".",
"NewScope",
"(",
"nil",
")",
"... | // Delete delete relationship in join table for sources | [
"Delete",
"delete",
"relationship",
"in",
"join",
"table",
"for",
"sources"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/join_table_handler.go#L144-L160 |
126,533 | jinzhu/gorm | join_table_handler.go | JoinWith | func (s JoinTableHandler) JoinWith(handler JoinTableHandlerInterface, db *DB, source interface{}) *DB {
var (
scope = db.NewScope(source)
tableName = handler.Table(db)
quotedTableName = scope.Quote(tableName)
joinConditions []string
values []interface{}
)
if s.Source.ModelType ==... | go | func (s JoinTableHandler) JoinWith(handler JoinTableHandlerInterface, db *DB, source interface{}) *DB {
var (
scope = db.NewScope(source)
tableName = handler.Table(db)
quotedTableName = scope.Quote(tableName)
joinConditions []string
values []interface{}
)
if s.Source.ModelType ==... | [
"func",
"(",
"s",
"JoinTableHandler",
")",
"JoinWith",
"(",
"handler",
"JoinTableHandlerInterface",
",",
"db",
"*",
"DB",
",",
"source",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"var",
"(",
"scope",
"=",
"db",
".",
"NewScope",
"(",
"source",
")",
"\... | // JoinWith query with `Join` conditions | [
"JoinWith",
"query",
"with",
"Join",
"conditions"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/join_table_handler.go#L163-L211 |
126,534 | jinzhu/gorm | utils.go | getValueFromFields | func getValueFromFields(value reflect.Value, fieldNames []string) (results []interface{}) {
// If value is a nil pointer, Indirect returns a zero Value!
// Therefor we need to check for a zero value,
// as FieldByName could panic
if indirectValue := reflect.Indirect(value); indirectValue.IsValid() {
for _, fieldN... | go | func getValueFromFields(value reflect.Value, fieldNames []string) (results []interface{}) {
// If value is a nil pointer, Indirect returns a zero Value!
// Therefor we need to check for a zero value,
// as FieldByName could panic
if indirectValue := reflect.Indirect(value); indirectValue.IsValid() {
for _, fieldN... | [
"func",
"getValueFromFields",
"(",
"value",
"reflect",
".",
"Value",
",",
"fieldNames",
"[",
"]",
"string",
")",
"(",
"results",
"[",
"]",
"interface",
"{",
"}",
")",
"{",
"// If value is a nil pointer, Indirect returns a zero Value!",
"// Therefor we need to check for ... | // getValueFromFields return given fields's value | [
"getValueFromFields",
"return",
"given",
"fields",
"s",
"value"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/utils.go#L203-L219 |
126,535 | jinzhu/gorm | main.go | New | func (s *DB) New() *DB {
clone := s.clone()
clone.search = nil
clone.Value = nil
return clone
} | go | func (s *DB) New() *DB {
clone := s.clone()
clone.search = nil
clone.Value = nil
return clone
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"New",
"(",
")",
"*",
"DB",
"{",
"clone",
":=",
"s",
".",
"clone",
"(",
")",
"\n",
"clone",
".",
"search",
"=",
"nil",
"\n",
"clone",
".",
"Value",
"=",
"nil",
"\n",
"return",
"clone",
"\n",
"}"
] | // New clone a new db connection without search conditions | [
"New",
"clone",
"a",
"new",
"db",
"connection",
"without",
"search",
"conditions"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L101-L106 |
126,536 | jinzhu/gorm | main.go | Close | func (s *DB) Close() error {
if db, ok := s.parent.db.(closer); ok {
return db.Close()
}
return errors.New("can't close current db")
} | go | func (s *DB) Close() error {
if db, ok := s.parent.db.(closer); ok {
return db.Close()
}
return errors.New("can't close current db")
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"db",
",",
"ok",
":=",
"s",
".",
"parent",
".",
"db",
".",
"(",
"closer",
")",
";",
"ok",
"{",
"return",
"db",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"return",
"erro... | // Close close current db connection. If database connection is not an io.Closer, returns an error. | [
"Close",
"close",
"current",
"db",
"connection",
".",
"If",
"database",
"connection",
"is",
"not",
"an",
"io",
".",
"Closer",
"returns",
"an",
"error",
"."
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L113-L118 |
126,537 | jinzhu/gorm | main.go | LogMode | func (s *DB) LogMode(enable bool) *DB {
if enable {
s.logMode = detailedLogMode
} else {
s.logMode = noLogMode
}
return s
} | go | func (s *DB) LogMode(enable bool) *DB {
if enable {
s.logMode = detailedLogMode
} else {
s.logMode = noLogMode
}
return s
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"LogMode",
"(",
"enable",
"bool",
")",
"*",
"DB",
"{",
"if",
"enable",
"{",
"s",
".",
"logMode",
"=",
"detailedLogMode",
"\n",
"}",
"else",
"{",
"s",
".",
"logMode",
"=",
"noLogMode",
"\n",
"}",
"\n",
"return",
"... | // LogMode set log mode, `true` for detailed logs, `false` for no log, default, will only print error logs | [
"LogMode",
"set",
"log",
"mode",
"true",
"for",
"detailed",
"logs",
"false",
"for",
"no",
"log",
"default",
"will",
"only",
"print",
"error",
"logs"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L151-L158 |
126,538 | jinzhu/gorm | main.go | SingularTable | func (s *DB) SingularTable(enable bool) {
s.parent.Lock()
defer s.parent.Unlock()
s.parent.singularTable = enable
} | go | func (s *DB) SingularTable(enable bool) {
s.parent.Lock()
defer s.parent.Unlock()
s.parent.singularTable = enable
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"SingularTable",
"(",
"enable",
"bool",
")",
"{",
"s",
".",
"parent",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"parent",
".",
"Unlock",
"(",
")",
"\n",
"s",
".",
"parent",
".",
"singularTable",
"=",
"enabl... | // SingularTable use singular table by default | [
"SingularTable",
"use",
"singular",
"table",
"by",
"default"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L173-L177 |
126,539 | jinzhu/gorm | main.go | NewScope | func (s *DB) NewScope(value interface{}) *Scope {
dbClone := s.clone()
dbClone.Value = value
scope := &Scope{db: dbClone, Value: value}
if s.search != nil {
scope.Search = s.search.clone()
} else {
scope.Search = &search{}
}
return scope
} | go | func (s *DB) NewScope(value interface{}) *Scope {
dbClone := s.clone()
dbClone.Value = value
scope := &Scope{db: dbClone, Value: value}
if s.search != nil {
scope.Search = s.search.clone()
} else {
scope.Search = &search{}
}
return scope
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"NewScope",
"(",
"value",
"interface",
"{",
"}",
")",
"*",
"Scope",
"{",
"dbClone",
":=",
"s",
".",
"clone",
"(",
")",
"\n",
"dbClone",
".",
"Value",
"=",
"value",
"\n",
"scope",
":=",
"&",
"Scope",
"{",
"db",
... | // NewScope create a scope for current operation | [
"NewScope",
"create",
"a",
"scope",
"for",
"current",
"operation"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L180-L190 |
126,540 | jinzhu/gorm | main.go | QueryExpr | func (s *DB) QueryExpr() *expr {
scope := s.NewScope(s.Value)
scope.InstanceSet("skip_bindvar", true)
scope.prepareQuerySQL()
return Expr(scope.SQL, scope.SQLVars...)
} | go | func (s *DB) QueryExpr() *expr {
scope := s.NewScope(s.Value)
scope.InstanceSet("skip_bindvar", true)
scope.prepareQuerySQL()
return Expr(scope.SQL, scope.SQLVars...)
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"QueryExpr",
"(",
")",
"*",
"expr",
"{",
"scope",
":=",
"s",
".",
"NewScope",
"(",
"s",
".",
"Value",
")",
"\n",
"scope",
".",
"InstanceSet",
"(",
"\"",
"\"",
",",
"true",
")",
"\n",
"scope",
".",
"prepareQuerySQ... | // QueryExpr returns the query as expr object | [
"QueryExpr",
"returns",
"the",
"query",
"as",
"expr",
"object"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L193-L199 |
126,541 | jinzhu/gorm | main.go | SubQuery | func (s *DB) SubQuery() *expr {
scope := s.NewScope(s.Value)
scope.InstanceSet("skip_bindvar", true)
scope.prepareQuerySQL()
return Expr(fmt.Sprintf("(%v)", scope.SQL), scope.SQLVars...)
} | go | func (s *DB) SubQuery() *expr {
scope := s.NewScope(s.Value)
scope.InstanceSet("skip_bindvar", true)
scope.prepareQuerySQL()
return Expr(fmt.Sprintf("(%v)", scope.SQL), scope.SQLVars...)
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"SubQuery",
"(",
")",
"*",
"expr",
"{",
"scope",
":=",
"s",
".",
"NewScope",
"(",
"s",
".",
"Value",
")",
"\n",
"scope",
".",
"InstanceSet",
"(",
"\"",
"\"",
",",
"true",
")",
"\n",
"scope",
".",
"prepareQuerySQL... | // SubQuery returns the query as sub query | [
"SubQuery",
"returns",
"the",
"query",
"as",
"sub",
"query"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L202-L208 |
126,542 | jinzhu/gorm | main.go | Or | func (s *DB) Or(query interface{}, args ...interface{}) *DB {
return s.clone().search.Or(query, args...).db
} | go | func (s *DB) Or(query interface{}, args ...interface{}) *DB {
return s.clone().search.Or(query, args...).db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Or",
"(",
"query",
"interface",
"{",
"}",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"return",
"s",
".",
"clone",
"(",
")",
".",
"search",
".",
"Or",
"(",
"query",
",",
"args",
"...",
")... | // Or filter records that match before conditions or this one, similar to `Where` | [
"Or",
"filter",
"records",
"that",
"match",
"before",
"conditions",
"or",
"this",
"one",
"similar",
"to",
"Where"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L216-L218 |
126,543 | jinzhu/gorm | main.go | Not | func (s *DB) Not(query interface{}, args ...interface{}) *DB {
return s.clone().search.Not(query, args...).db
} | go | func (s *DB) Not(query interface{}, args ...interface{}) *DB {
return s.clone().search.Not(query, args...).db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Not",
"(",
"query",
"interface",
"{",
"}",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"return",
"s",
".",
"clone",
"(",
")",
".",
"search",
".",
"Not",
"(",
"query",
",",
"args",
"...",
... | // Not filter records that don't match current conditions, similar to `Where` | [
"Not",
"filter",
"records",
"that",
"don",
"t",
"match",
"current",
"conditions",
"similar",
"to",
"Where"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L221-L223 |
126,544 | jinzhu/gorm | main.go | Limit | func (s *DB) Limit(limit interface{}) *DB {
return s.clone().search.Limit(limit).db
} | go | func (s *DB) Limit(limit interface{}) *DB {
return s.clone().search.Limit(limit).db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Limit",
"(",
"limit",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"return",
"s",
".",
"clone",
"(",
")",
".",
"search",
".",
"Limit",
"(",
"limit",
")",
".",
"db",
"\n",
"}"
] | // Limit specify the number of records to be retrieved | [
"Limit",
"specify",
"the",
"number",
"of",
"records",
"to",
"be",
"retrieved"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L226-L228 |
126,545 | jinzhu/gorm | main.go | Offset | func (s *DB) Offset(offset interface{}) *DB {
return s.clone().search.Offset(offset).db
} | go | func (s *DB) Offset(offset interface{}) *DB {
return s.clone().search.Offset(offset).db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Offset",
"(",
"offset",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"return",
"s",
".",
"clone",
"(",
")",
".",
"search",
".",
"Offset",
"(",
"offset",
")",
".",
"db",
"\n",
"}"
] | // Offset specify the number of records to skip before starting to return the records | [
"Offset",
"specify",
"the",
"number",
"of",
"records",
"to",
"skip",
"before",
"starting",
"to",
"return",
"the",
"records"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L231-L233 |
126,546 | jinzhu/gorm | main.go | Omit | func (s *DB) Omit(columns ...string) *DB {
return s.clone().search.Omit(columns...).db
} | go | func (s *DB) Omit(columns ...string) *DB {
return s.clone().search.Omit(columns...).db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Omit",
"(",
"columns",
"...",
"string",
")",
"*",
"DB",
"{",
"return",
"s",
".",
"clone",
"(",
")",
".",
"search",
".",
"Omit",
"(",
"columns",
"...",
")",
".",
"db",
"\n",
"}"
] | // Omit specify fields that you want to ignore when saving to database for creating, updating | [
"Omit",
"specify",
"fields",
"that",
"you",
"want",
"to",
"ignore",
"when",
"saving",
"to",
"database",
"for",
"creating",
"updating"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L250-L252 |
126,547 | jinzhu/gorm | main.go | Group | func (s *DB) Group(query string) *DB {
return s.clone().search.Group(query).db
} | go | func (s *DB) Group(query string) *DB {
return s.clone().search.Group(query).db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Group",
"(",
"query",
"string",
")",
"*",
"DB",
"{",
"return",
"s",
".",
"clone",
"(",
")",
".",
"search",
".",
"Group",
"(",
"query",
")",
".",
"db",
"\n",
"}"
] | // Group specify the group method on the find | [
"Group",
"specify",
"the",
"group",
"method",
"on",
"the",
"find"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L255-L257 |
126,548 | jinzhu/gorm | main.go | Having | func (s *DB) Having(query interface{}, values ...interface{}) *DB {
return s.clone().search.Having(query, values...).db
} | go | func (s *DB) Having(query interface{}, values ...interface{}) *DB {
return s.clone().search.Having(query, values...).db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Having",
"(",
"query",
"interface",
"{",
"}",
",",
"values",
"...",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"return",
"s",
".",
"clone",
"(",
")",
".",
"search",
".",
"Having",
"(",
"query",
",",
"values",
... | // Having specify HAVING conditions for GROUP BY | [
"Having",
"specify",
"HAVING",
"conditions",
"for",
"GROUP",
"BY"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L260-L262 |
126,549 | jinzhu/gorm | main.go | Joins | func (s *DB) Joins(query string, args ...interface{}) *DB {
return s.clone().search.Joins(query, args...).db
} | go | func (s *DB) Joins(query string, args ...interface{}) *DB {
return s.clone().search.Joins(query, args...).db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Joins",
"(",
"query",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"return",
"s",
".",
"clone",
"(",
")",
".",
"search",
".",
"Joins",
"(",
"query",
",",
"args",
"...",
")",
".",
... | // Joins specify Joins conditions
// db.Joins("JOIN emails ON emails.user_id = users.id AND emails.email = ?", "jinzhu@example.org").Find(&user) | [
"Joins",
"specify",
"Joins",
"conditions",
"db",
".",
"Joins",
"(",
"JOIN",
"emails",
"ON",
"emails",
".",
"user_id",
"=",
"users",
".",
"id",
"AND",
"emails",
".",
"email",
"=",
"?",
"jinzhu"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L266-L268 |
126,550 | jinzhu/gorm | main.go | Take | func (s *DB) Take(out interface{}, where ...interface{}) *DB {
newScope := s.NewScope(out)
newScope.Search.Limit(1)
return newScope.inlineCondition(where...).callCallbacks(s.parent.callbacks.queries).db
} | go | func (s *DB) Take(out interface{}, where ...interface{}) *DB {
newScope := s.NewScope(out)
newScope.Search.Limit(1)
return newScope.inlineCondition(where...).callCallbacks(s.parent.callbacks.queries).db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Take",
"(",
"out",
"interface",
"{",
"}",
",",
"where",
"...",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"newScope",
":=",
"s",
".",
"NewScope",
"(",
"out",
")",
"\n",
"newScope",
".",
"Search",
".",
"Limit",
... | // Take return a record that match given conditions, the order will depend on the database implementation | [
"Take",
"return",
"a",
"record",
"that",
"match",
"given",
"conditions",
"the",
"order",
"will",
"depend",
"on",
"the",
"database",
"implementation"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L315-L319 |
126,551 | jinzhu/gorm | main.go | Find | func (s *DB) Find(out interface{}, where ...interface{}) *DB {
return s.NewScope(out).inlineCondition(where...).callCallbacks(s.parent.callbacks.queries).db
} | go | func (s *DB) Find(out interface{}, where ...interface{}) *DB {
return s.NewScope(out).inlineCondition(where...).callCallbacks(s.parent.callbacks.queries).db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Find",
"(",
"out",
"interface",
"{",
"}",
",",
"where",
"...",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"return",
"s",
".",
"NewScope",
"(",
"out",
")",
".",
"inlineCondition",
"(",
"where",
"...",
")",
".",
... | // Find find records that match given conditions | [
"Find",
"find",
"records",
"that",
"match",
"given",
"conditions"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L330-L332 |
126,552 | jinzhu/gorm | main.go | Preloads | func (s *DB) Preloads(out interface{}) *DB {
return s.NewScope(out).InstanceSet("gorm:only_preload", 1).callCallbacks(s.parent.callbacks.queries).db
} | go | func (s *DB) Preloads(out interface{}) *DB {
return s.NewScope(out).InstanceSet("gorm:only_preload", 1).callCallbacks(s.parent.callbacks.queries).db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Preloads",
"(",
"out",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"return",
"s",
".",
"NewScope",
"(",
"out",
")",
".",
"InstanceSet",
"(",
"\"",
"\"",
",",
"1",
")",
".",
"callCallbacks",
"(",
"s",
".",
"par... | //Preloads preloads relations, don`t touch out | [
"Preloads",
"preloads",
"relations",
"don",
"t",
"touch",
"out"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L335-L337 |
126,553 | jinzhu/gorm | main.go | Scan | func (s *DB) Scan(dest interface{}) *DB {
return s.NewScope(s.Value).Set("gorm:query_destination", dest).callCallbacks(s.parent.callbacks.queries).db
} | go | func (s *DB) Scan(dest interface{}) *DB {
return s.NewScope(s.Value).Set("gorm:query_destination", dest).callCallbacks(s.parent.callbacks.queries).db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Scan",
"(",
"dest",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"return",
"s",
".",
"NewScope",
"(",
"s",
".",
"Value",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"dest",
")",
".",
"callCallbacks",
"(",
"s",
"."... | // Scan scan value to a struct | [
"Scan",
"scan",
"value",
"to",
"a",
"struct"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L340-L342 |
126,554 | jinzhu/gorm | main.go | Count | func (s *DB) Count(value interface{}) *DB {
return s.NewScope(s.Value).count(value).db
} | go | func (s *DB) Count(value interface{}) *DB {
return s.NewScope(s.Value).count(value).db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Count",
"(",
"value",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"return",
"s",
".",
"NewScope",
"(",
"s",
".",
"Value",
")",
".",
"count",
"(",
"value",
")",
".",
"db",
"\n",
"}"
] | // Count get how many records for a model | [
"Count",
"get",
"how",
"many",
"records",
"for",
"a",
"model"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L377-L379 |
126,555 | jinzhu/gorm | main.go | Related | func (s *DB) Related(value interface{}, foreignKeys ...string) *DB {
return s.NewScope(s.Value).related(value, foreignKeys...).db
} | go | func (s *DB) Related(value interface{}, foreignKeys ...string) *DB {
return s.NewScope(s.Value).related(value, foreignKeys...).db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Related",
"(",
"value",
"interface",
"{",
"}",
",",
"foreignKeys",
"...",
"string",
")",
"*",
"DB",
"{",
"return",
"s",
".",
"NewScope",
"(",
"s",
".",
"Value",
")",
".",
"related",
"(",
"value",
",",
"foreignKeys... | // Related get related associations | [
"Related",
"get",
"related",
"associations"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L382-L384 |
126,556 | jinzhu/gorm | main.go | Save | func (s *DB) Save(value interface{}) *DB {
scope := s.NewScope(value)
if !scope.PrimaryKeyZero() {
newDB := scope.callCallbacks(s.parent.callbacks.updates).db
if newDB.Error == nil && newDB.RowsAffected == 0 {
return s.New().FirstOrCreate(value)
}
return newDB
}
return scope.callCallbacks(s.parent.callba... | go | func (s *DB) Save(value interface{}) *DB {
scope := s.NewScope(value)
if !scope.PrimaryKeyZero() {
newDB := scope.callCallbacks(s.parent.callbacks.updates).db
if newDB.Error == nil && newDB.RowsAffected == 0 {
return s.New().FirstOrCreate(value)
}
return newDB
}
return scope.callCallbacks(s.parent.callba... | [
"func",
"(",
"s",
"*",
"DB",
")",
"Save",
"(",
"value",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"scope",
":=",
"s",
".",
"NewScope",
"(",
"value",
")",
"\n",
"if",
"!",
"scope",
".",
"PrimaryKeyZero",
"(",
")",
"{",
"newDB",
":=",
"scope",
... | // Save update value in database, if the value doesn't have primary key, will insert it | [
"Save",
"update",
"value",
"in",
"database",
"if",
"the",
"value",
"doesn",
"t",
"have",
"primary",
"key",
"will",
"insert",
"it"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L444-L454 |
126,557 | jinzhu/gorm | main.go | Create | func (s *DB) Create(value interface{}) *DB {
scope := s.NewScope(value)
return scope.callCallbacks(s.parent.callbacks.creates).db
} | go | func (s *DB) Create(value interface{}) *DB {
scope := s.NewScope(value)
return scope.callCallbacks(s.parent.callbacks.creates).db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Create",
"(",
"value",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"scope",
":=",
"s",
".",
"NewScope",
"(",
"value",
")",
"\n",
"return",
"scope",
".",
"callCallbacks",
"(",
"s",
".",
"parent",
".",
"callbacks",
... | // Create insert the value into database | [
"Create",
"insert",
"the",
"value",
"into",
"database"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L457-L460 |
126,558 | jinzhu/gorm | main.go | Delete | func (s *DB) Delete(value interface{}, where ...interface{}) *DB {
return s.NewScope(value).inlineCondition(where...).callCallbacks(s.parent.callbacks.deletes).db
} | go | func (s *DB) Delete(value interface{}, where ...interface{}) *DB {
return s.NewScope(value).inlineCondition(where...).callCallbacks(s.parent.callbacks.deletes).db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Delete",
"(",
"value",
"interface",
"{",
"}",
",",
"where",
"...",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"return",
"s",
".",
"NewScope",
"(",
"value",
")",
".",
"inlineCondition",
"(",
"where",
"...",
")",
... | // Delete delete value match given conditions, if the value has primary key, then will including the primary key as condition | [
"Delete",
"delete",
"value",
"match",
"given",
"conditions",
"if",
"the",
"value",
"has",
"primary",
"key",
"then",
"will",
"including",
"the",
"primary",
"key",
"as",
"condition"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L463-L465 |
126,559 | jinzhu/gorm | main.go | Exec | func (s *DB) Exec(sql string, values ...interface{}) *DB {
scope := s.NewScope(nil)
generatedSQL := scope.buildCondition(map[string]interface{}{"query": sql, "args": values}, true)
generatedSQL = strings.TrimSuffix(strings.TrimPrefix(generatedSQL, "("), ")")
scope.Raw(generatedSQL)
return scope.Exec().db
} | go | func (s *DB) Exec(sql string, values ...interface{}) *DB {
scope := s.NewScope(nil)
generatedSQL := scope.buildCondition(map[string]interface{}{"query": sql, "args": values}, true)
generatedSQL = strings.TrimSuffix(strings.TrimPrefix(generatedSQL, "("), ")")
scope.Raw(generatedSQL)
return scope.Exec().db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Exec",
"(",
"sql",
"string",
",",
"values",
"...",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"scope",
":=",
"s",
".",
"NewScope",
"(",
"nil",
")",
"\n",
"generatedSQL",
":=",
"scope",
".",
"buildCondition",
"(",... | // Exec execute raw sql | [
"Exec",
"execute",
"raw",
"sql"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L474-L480 |
126,560 | jinzhu/gorm | main.go | Table | func (s *DB) Table(name string) *DB {
clone := s.clone()
clone.search.Table(name)
clone.Value = nil
return clone
} | go | func (s *DB) Table(name string) *DB {
clone := s.clone()
clone.search.Table(name)
clone.Value = nil
return clone
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Table",
"(",
"name",
"string",
")",
"*",
"DB",
"{",
"clone",
":=",
"s",
".",
"clone",
"(",
")",
"\n",
"clone",
".",
"search",
".",
"Table",
"(",
"name",
")",
"\n",
"clone",
".",
"Value",
"=",
"nil",
"\n",
"r... | // Table specify the table you would like to run db operations | [
"Table",
"specify",
"the",
"table",
"you",
"would",
"like",
"to",
"run",
"db",
"operations"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L494-L499 |
126,561 | jinzhu/gorm | main.go | Begin | func (s *DB) Begin() *DB {
c := s.clone()
if db, ok := c.db.(sqlDb); ok && db != nil {
tx, err := db.Begin()
c.db = interface{}(tx).(SQLCommon)
c.dialect.SetDB(c.db)
c.AddError(err)
} else {
c.AddError(ErrCantStartTransaction)
}
return c
} | go | func (s *DB) Begin() *DB {
c := s.clone()
if db, ok := c.db.(sqlDb); ok && db != nil {
tx, err := db.Begin()
c.db = interface{}(tx).(SQLCommon)
c.dialect.SetDB(c.db)
c.AddError(err)
} else {
c.AddError(ErrCantStartTransaction)
}
return c
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Begin",
"(",
")",
"*",
"DB",
"{",
"c",
":=",
"s",
".",
"clone",
"(",
")",
"\n",
"if",
"db",
",",
"ok",
":=",
"c",
".",
"db",
".",
"(",
"sqlDb",
")",
";",
"ok",
"&&",
"db",
"!=",
"nil",
"{",
"tx",
",",
... | // Begin begin a transaction | [
"Begin",
"begin",
"a",
"transaction"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L507-L519 |
126,562 | jinzhu/gorm | main.go | Commit | func (s *DB) Commit() *DB {
var emptySQLTx *sql.Tx
if db, ok := s.db.(sqlTx); ok && db != nil && db != emptySQLTx {
s.AddError(db.Commit())
} else {
s.AddError(ErrInvalidTransaction)
}
return s
} | go | func (s *DB) Commit() *DB {
var emptySQLTx *sql.Tx
if db, ok := s.db.(sqlTx); ok && db != nil && db != emptySQLTx {
s.AddError(db.Commit())
} else {
s.AddError(ErrInvalidTransaction)
}
return s
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Commit",
"(",
")",
"*",
"DB",
"{",
"var",
"emptySQLTx",
"*",
"sql",
".",
"Tx",
"\n",
"if",
"db",
",",
"ok",
":=",
"s",
".",
"db",
".",
"(",
"sqlTx",
")",
";",
"ok",
"&&",
"db",
"!=",
"nil",
"&&",
"db",
"... | // Commit commit a transaction | [
"Commit",
"commit",
"a",
"transaction"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L522-L530 |
126,563 | jinzhu/gorm | main.go | RecordNotFound | func (s *DB) RecordNotFound() bool {
for _, err := range s.GetErrors() {
if err == ErrRecordNotFound {
return true
}
}
return false
} | go | func (s *DB) RecordNotFound() bool {
for _, err := range s.GetErrors() {
if err == ErrRecordNotFound {
return true
}
}
return false
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"RecordNotFound",
"(",
")",
"bool",
"{",
"for",
"_",
",",
"err",
":=",
"range",
"s",
".",
"GetErrors",
"(",
")",
"{",
"if",
"err",
"==",
"ErrRecordNotFound",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"re... | // RecordNotFound check if returning ErrRecordNotFound error | [
"RecordNotFound",
"check",
"if",
"returning",
"ErrRecordNotFound",
"error"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L549-L556 |
126,564 | jinzhu/gorm | main.go | CreateTable | func (s *DB) CreateTable(models ...interface{}) *DB {
db := s.Unscoped()
for _, model := range models {
db = db.NewScope(model).createTable().db
}
return db
} | go | func (s *DB) CreateTable(models ...interface{}) *DB {
db := s.Unscoped()
for _, model := range models {
db = db.NewScope(model).createTable().db
}
return db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"CreateTable",
"(",
"models",
"...",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"db",
":=",
"s",
".",
"Unscoped",
"(",
")",
"\n",
"for",
"_",
",",
"model",
":=",
"range",
"models",
"{",
"db",
"=",
"db",
".",
... | // CreateTable create table for models | [
"CreateTable",
"create",
"table",
"for",
"models"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L559-L565 |
126,565 | jinzhu/gorm | main.go | DropTable | func (s *DB) DropTable(values ...interface{}) *DB {
db := s.clone()
for _, value := range values {
if tableName, ok := value.(string); ok {
db = db.Table(tableName)
}
db = db.NewScope(value).dropTable().db
}
return db
} | go | func (s *DB) DropTable(values ...interface{}) *DB {
db := s.clone()
for _, value := range values {
if tableName, ok := value.(string); ok {
db = db.Table(tableName)
}
db = db.NewScope(value).dropTable().db
}
return db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"DropTable",
"(",
"values",
"...",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"db",
":=",
"s",
".",
"clone",
"(",
")",
"\n",
"for",
"_",
",",
"value",
":=",
"range",
"values",
"{",
"if",
"tableName",
",",
"ok"... | // DropTable drop table for models | [
"DropTable",
"drop",
"table",
"for",
"models"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L568-L578 |
126,566 | jinzhu/gorm | main.go | DropTableIfExists | func (s *DB) DropTableIfExists(values ...interface{}) *DB {
db := s.clone()
for _, value := range values {
if s.HasTable(value) {
db.AddError(s.DropTable(value).Error)
}
}
return db
} | go | func (s *DB) DropTableIfExists(values ...interface{}) *DB {
db := s.clone()
for _, value := range values {
if s.HasTable(value) {
db.AddError(s.DropTable(value).Error)
}
}
return db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"DropTableIfExists",
"(",
"values",
"...",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"db",
":=",
"s",
".",
"clone",
"(",
")",
"\n",
"for",
"_",
",",
"value",
":=",
"range",
"values",
"{",
"if",
"s",
".",
"Has... | // DropTableIfExists drop table if it is exist | [
"DropTableIfExists",
"drop",
"table",
"if",
"it",
"is",
"exist"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L581-L589 |
126,567 | jinzhu/gorm | main.go | HasTable | func (s *DB) HasTable(value interface{}) bool {
var (
scope = s.NewScope(value)
tableName string
)
if name, ok := value.(string); ok {
tableName = name
} else {
tableName = scope.TableName()
}
has := scope.Dialect().HasTable(tableName)
s.AddError(scope.db.Error)
return has
} | go | func (s *DB) HasTable(value interface{}) bool {
var (
scope = s.NewScope(value)
tableName string
)
if name, ok := value.(string); ok {
tableName = name
} else {
tableName = scope.TableName()
}
has := scope.Dialect().HasTable(tableName)
s.AddError(scope.db.Error)
return has
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"HasTable",
"(",
"value",
"interface",
"{",
"}",
")",
"bool",
"{",
"var",
"(",
"scope",
"=",
"s",
".",
"NewScope",
"(",
"value",
")",
"\n",
"tableName",
"string",
"\n",
")",
"\n\n",
"if",
"name",
",",
"ok",
":=",... | // HasTable check has table or not | [
"HasTable",
"check",
"has",
"table",
"or",
"not"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L592-L607 |
126,568 | jinzhu/gorm | main.go | ModifyColumn | func (s *DB) ModifyColumn(column string, typ string) *DB {
scope := s.NewScope(s.Value)
scope.modifyColumn(column, typ)
return scope.db
} | go | func (s *DB) ModifyColumn(column string, typ string) *DB {
scope := s.NewScope(s.Value)
scope.modifyColumn(column, typ)
return scope.db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"ModifyColumn",
"(",
"column",
"string",
",",
"typ",
"string",
")",
"*",
"DB",
"{",
"scope",
":=",
"s",
".",
"NewScope",
"(",
"s",
".",
"Value",
")",
"\n",
"scope",
".",
"modifyColumn",
"(",
"column",
",",
"typ",
... | // ModifyColumn modify column to type | [
"ModifyColumn",
"modify",
"column",
"to",
"type"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L619-L623 |
126,569 | jinzhu/gorm | main.go | DropColumn | func (s *DB) DropColumn(column string) *DB {
scope := s.NewScope(s.Value)
scope.dropColumn(column)
return scope.db
} | go | func (s *DB) DropColumn(column string) *DB {
scope := s.NewScope(s.Value)
scope.dropColumn(column)
return scope.db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"DropColumn",
"(",
"column",
"string",
")",
"*",
"DB",
"{",
"scope",
":=",
"s",
".",
"NewScope",
"(",
"s",
".",
"Value",
")",
"\n",
"scope",
".",
"dropColumn",
"(",
"column",
")",
"\n",
"return",
"scope",
".",
"d... | // DropColumn drop a column | [
"DropColumn",
"drop",
"a",
"column"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L626-L630 |
126,570 | jinzhu/gorm | main.go | AddIndex | func (s *DB) AddIndex(indexName string, columns ...string) *DB {
scope := s.Unscoped().NewScope(s.Value)
scope.addIndex(false, indexName, columns...)
return scope.db
} | go | func (s *DB) AddIndex(indexName string, columns ...string) *DB {
scope := s.Unscoped().NewScope(s.Value)
scope.addIndex(false, indexName, columns...)
return scope.db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"AddIndex",
"(",
"indexName",
"string",
",",
"columns",
"...",
"string",
")",
"*",
"DB",
"{",
"scope",
":=",
"s",
".",
"Unscoped",
"(",
")",
".",
"NewScope",
"(",
"s",
".",
"Value",
")",
"\n",
"scope",
".",
"addI... | // AddIndex add index for columns with given name | [
"AddIndex",
"add",
"index",
"for",
"columns",
"with",
"given",
"name"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L633-L637 |
126,571 | jinzhu/gorm | main.go | AddUniqueIndex | func (s *DB) AddUniqueIndex(indexName string, columns ...string) *DB {
scope := s.Unscoped().NewScope(s.Value)
scope.addIndex(true, indexName, columns...)
return scope.db
} | go | func (s *DB) AddUniqueIndex(indexName string, columns ...string) *DB {
scope := s.Unscoped().NewScope(s.Value)
scope.addIndex(true, indexName, columns...)
return scope.db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"AddUniqueIndex",
"(",
"indexName",
"string",
",",
"columns",
"...",
"string",
")",
"*",
"DB",
"{",
"scope",
":=",
"s",
".",
"Unscoped",
"(",
")",
".",
"NewScope",
"(",
"s",
".",
"Value",
")",
"\n",
"scope",
".",
... | // AddUniqueIndex add unique index for columns with given name | [
"AddUniqueIndex",
"add",
"unique",
"index",
"for",
"columns",
"with",
"given",
"name"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L640-L644 |
126,572 | jinzhu/gorm | main.go | RemoveIndex | func (s *DB) RemoveIndex(indexName string) *DB {
scope := s.NewScope(s.Value)
scope.removeIndex(indexName)
return scope.db
} | go | func (s *DB) RemoveIndex(indexName string) *DB {
scope := s.NewScope(s.Value)
scope.removeIndex(indexName)
return scope.db
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"RemoveIndex",
"(",
"indexName",
"string",
")",
"*",
"DB",
"{",
"scope",
":=",
"s",
".",
"NewScope",
"(",
"s",
".",
"Value",
")",
"\n",
"scope",
".",
"removeIndex",
"(",
"indexName",
")",
"\n",
"return",
"scope",
"... | // RemoveIndex remove index with name | [
"RemoveIndex",
"remove",
"index",
"with",
"name"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L647-L651 |
126,573 | jinzhu/gorm | main.go | Set | func (s *DB) Set(name string, value interface{}) *DB {
return s.clone().InstantSet(name, value)
} | go | func (s *DB) Set(name string, value interface{}) *DB {
return s.clone().InstantSet(name, value)
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"Set",
"(",
"name",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"return",
"s",
".",
"clone",
"(",
")",
".",
"InstantSet",
"(",
"name",
",",
"value",
")",
"\n",
"}"
] | // Set set setting by name, which could be used in callbacks, will clone a new db, and update its setting | [
"Set",
"set",
"setting",
"by",
"name",
"which",
"could",
"be",
"used",
"in",
"callbacks",
"will",
"clone",
"a",
"new",
"db",
"and",
"update",
"its",
"setting"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L698-L700 |
126,574 | jinzhu/gorm | main.go | InstantSet | func (s *DB) InstantSet(name string, value interface{}) *DB {
s.values.Store(name, value)
return s
} | go | func (s *DB) InstantSet(name string, value interface{}) *DB {
s.values.Store(name, value)
return s
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"InstantSet",
"(",
"name",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"*",
"DB",
"{",
"s",
".",
"values",
".",
"Store",
"(",
"name",
",",
"value",
")",
"\n",
"return",
"s",
"\n",
"}"
] | // InstantSet instant set setting, will affect current db | [
"InstantSet",
"instant",
"set",
"setting",
"will",
"affect",
"current",
"db"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L703-L706 |
126,575 | jinzhu/gorm | main.go | SetJoinTableHandler | func (s *DB) SetJoinTableHandler(source interface{}, column string, handler JoinTableHandlerInterface) {
scope := s.NewScope(source)
for _, field := range scope.GetModelStruct().StructFields {
if field.Name == column || field.DBName == column {
if many2many, _ := field.TagSettingsGet("MANY2MANY"); many2many != "... | go | func (s *DB) SetJoinTableHandler(source interface{}, column string, handler JoinTableHandlerInterface) {
scope := s.NewScope(source)
for _, field := range scope.GetModelStruct().StructFields {
if field.Name == column || field.DBName == column {
if many2many, _ := field.TagSettingsGet("MANY2MANY"); many2many != "... | [
"func",
"(",
"s",
"*",
"DB",
")",
"SetJoinTableHandler",
"(",
"source",
"interface",
"{",
"}",
",",
"column",
"string",
",",
"handler",
"JoinTableHandlerInterface",
")",
"{",
"scope",
":=",
"s",
".",
"NewScope",
"(",
"source",
")",
"\n",
"for",
"_",
",",... | // SetJoinTableHandler set a model's join table handler for a relation | [
"SetJoinTableHandler",
"set",
"a",
"model",
"s",
"join",
"table",
"handler",
"for",
"a",
"relation"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L715-L730 |
126,576 | jinzhu/gorm | main.go | AddError | func (s *DB) AddError(err error) error {
if err != nil {
if err != ErrRecordNotFound {
if s.logMode == defaultLogMode {
go s.print("error", fileWithLineNum(), err)
} else {
s.log(err)
}
errors := Errors(s.GetErrors())
errors = errors.Add(err)
if len(errors) > 1 {
err = errors
}
}
... | go | func (s *DB) AddError(err error) error {
if err != nil {
if err != ErrRecordNotFound {
if s.logMode == defaultLogMode {
go s.print("error", fileWithLineNum(), err)
} else {
s.log(err)
}
errors := Errors(s.GetErrors())
errors = errors.Add(err)
if len(errors) > 1 {
err = errors
}
}
... | [
"func",
"(",
"s",
"*",
"DB",
")",
"AddError",
"(",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"!=",
"ErrRecordNotFound",
"{",
"if",
"s",
".",
"logMode",
"==",
"defaultLogMode",
"{",
"go",
"s",
".",
"print",
"(",
... | // AddError add error to the db | [
"AddError",
"add",
"error",
"to",
"the",
"db"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L733-L752 |
126,577 | jinzhu/gorm | main.go | GetErrors | func (s *DB) GetErrors() []error {
if errs, ok := s.Error.(Errors); ok {
return errs
} else if s.Error != nil {
return []error{s.Error}
}
return []error{}
} | go | func (s *DB) GetErrors() []error {
if errs, ok := s.Error.(Errors); ok {
return errs
} else if s.Error != nil {
return []error{s.Error}
}
return []error{}
} | [
"func",
"(",
"s",
"*",
"DB",
")",
"GetErrors",
"(",
")",
"[",
"]",
"error",
"{",
"if",
"errs",
",",
"ok",
":=",
"s",
".",
"Error",
".",
"(",
"Errors",
")",
";",
"ok",
"{",
"return",
"errs",
"\n",
"}",
"else",
"if",
"s",
".",
"Error",
"!=",
... | // GetErrors get happened errors from the db | [
"GetErrors",
"get",
"happened",
"errors",
"from",
"the",
"db"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/main.go#L755-L762 |
126,578 | jinzhu/gorm | callback_delete.go | init | func init() {
DefaultCallback.Delete().Register("gorm:begin_transaction", beginTransactionCallback)
DefaultCallback.Delete().Register("gorm:before_delete", beforeDeleteCallback)
DefaultCallback.Delete().Register("gorm:delete", deleteCallback)
DefaultCallback.Delete().Register("gorm:after_delete", afterDeleteCallbac... | go | func init() {
DefaultCallback.Delete().Register("gorm:begin_transaction", beginTransactionCallback)
DefaultCallback.Delete().Register("gorm:before_delete", beforeDeleteCallback)
DefaultCallback.Delete().Register("gorm:delete", deleteCallback)
DefaultCallback.Delete().Register("gorm:after_delete", afterDeleteCallbac... | [
"func",
"init",
"(",
")",
"{",
"DefaultCallback",
".",
"Delete",
"(",
")",
".",
"Register",
"(",
"\"",
"\"",
",",
"beginTransactionCallback",
")",
"\n",
"DefaultCallback",
".",
"Delete",
"(",
")",
".",
"Register",
"(",
"\"",
"\"",
",",
"beforeDeleteCallbac... | // Define callbacks for deleting | [
"Define",
"callbacks",
"for",
"deleting"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/callback_delete.go#L9-L15 |
126,579 | jinzhu/gorm | callback_delete.go | beforeDeleteCallback | func beforeDeleteCallback(scope *Scope) {
if scope.DB().HasBlockGlobalUpdate() && !scope.hasConditions() {
scope.Err(errors.New("Missing WHERE clause while deleting"))
return
}
if !scope.HasError() {
scope.CallMethod("BeforeDelete")
}
} | go | func beforeDeleteCallback(scope *Scope) {
if scope.DB().HasBlockGlobalUpdate() && !scope.hasConditions() {
scope.Err(errors.New("Missing WHERE clause while deleting"))
return
}
if !scope.HasError() {
scope.CallMethod("BeforeDelete")
}
} | [
"func",
"beforeDeleteCallback",
"(",
"scope",
"*",
"Scope",
")",
"{",
"if",
"scope",
".",
"DB",
"(",
")",
".",
"HasBlockGlobalUpdate",
"(",
")",
"&&",
"!",
"scope",
".",
"hasConditions",
"(",
")",
"{",
"scope",
".",
"Err",
"(",
"errors",
".",
"New",
... | // beforeDeleteCallback will invoke `BeforeDelete` method before deleting | [
"beforeDeleteCallback",
"will",
"invoke",
"BeforeDelete",
"method",
"before",
"deleting"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/callback_delete.go#L18-L26 |
126,580 | jinzhu/gorm | dialect_mysql.go | NormalizeIndexAndColumn | func (mysql) NormalizeIndexAndColumn(indexName, columnName string) (string, string) {
submatch := mysqlIndexRegex.FindStringSubmatch(indexName)
if len(submatch) != 3 {
return indexName, columnName
}
indexName = submatch[1]
columnName = fmt.Sprintf("%s(%s)", columnName, submatch[2])
return indexName, columnName
... | go | func (mysql) NormalizeIndexAndColumn(indexName, columnName string) (string, string) {
submatch := mysqlIndexRegex.FindStringSubmatch(indexName)
if len(submatch) != 3 {
return indexName, columnName
}
indexName = submatch[1]
columnName = fmt.Sprintf("%s(%s)", columnName, submatch[2])
return indexName, columnName
... | [
"func",
"(",
"mysql",
")",
"NormalizeIndexAndColumn",
"(",
"indexName",
",",
"columnName",
"string",
")",
"(",
"string",
",",
"string",
")",
"{",
"submatch",
":=",
"mysqlIndexRegex",
".",
"FindStringSubmatch",
"(",
"indexName",
")",
"\n",
"if",
"len",
"(",
"... | // NormalizeIndexAndColumn returns index name and column name for specify an index prefix length if needed | [
"NormalizeIndexAndColumn",
"returns",
"index",
"name",
"and",
"column",
"name",
"for",
"specify",
"an",
"index",
"prefix",
"length",
"if",
"needed"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/dialect_mysql.go#L192-L200 |
126,581 | jinzhu/gorm | dialect_sqlite3.go | DataTypeOf | func (s *sqlite3) DataTypeOf(field *StructField) string {
var dataValue, sqlType, size, additionalType = ParseFieldStructForDialect(field, s)
if sqlType == "" {
switch dataValue.Kind() {
case reflect.Bool:
sqlType = "bool"
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Uint, reflect.U... | go | func (s *sqlite3) DataTypeOf(field *StructField) string {
var dataValue, sqlType, size, additionalType = ParseFieldStructForDialect(field, s)
if sqlType == "" {
switch dataValue.Kind() {
case reflect.Bool:
sqlType = "bool"
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Uint, reflect.U... | [
"func",
"(",
"s",
"*",
"sqlite3",
")",
"DataTypeOf",
"(",
"field",
"*",
"StructField",
")",
"string",
"{",
"var",
"dataValue",
",",
"sqlType",
",",
"size",
",",
"additionalType",
"=",
"ParseFieldStructForDialect",
"(",
"field",
",",
"s",
")",
"\n\n",
"if",... | // Get Data Type for Sqlite Dialect | [
"Get",
"Data",
"Type",
"for",
"Sqlite",
"Dialect"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/dialect_sqlite3.go#L23-L71 |
126,582 | jinzhu/gorm | dialect_common.go | IsByteArrayOrSlice | func IsByteArrayOrSlice(value reflect.Value) bool {
return (value.Kind() == reflect.Array || value.Kind() == reflect.Slice) && value.Type().Elem() == reflect.TypeOf(uint8(0))
} | go | func IsByteArrayOrSlice(value reflect.Value) bool {
return (value.Kind() == reflect.Array || value.Kind() == reflect.Slice) && value.Type().Elem() == reflect.TypeOf(uint8(0))
} | [
"func",
"IsByteArrayOrSlice",
"(",
"value",
"reflect",
".",
"Value",
")",
"bool",
"{",
"return",
"(",
"value",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Array",
"||",
"value",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Slice",
")",
"&&",
"valu... | // IsByteArrayOrSlice returns true of the reflected value is an array or slice | [
"IsByteArrayOrSlice",
"returns",
"true",
"of",
"the",
"reflected",
"value",
"is",
"an",
"array",
"or",
"slice"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/dialect_common.go#L181-L183 |
126,583 | jinzhu/gorm | model_struct.go | TableName | func (s *ModelStruct) TableName(db *DB) string {
s.l.Lock()
defer s.l.Unlock()
if s.defaultTableName == "" && db != nil && s.ModelType != nil {
// Set default table name
if tabler, ok := reflect.New(s.ModelType).Interface().(tabler); ok {
s.defaultTableName = tabler.TableName()
} else {
tableName := ToT... | go | func (s *ModelStruct) TableName(db *DB) string {
s.l.Lock()
defer s.l.Unlock()
if s.defaultTableName == "" && db != nil && s.ModelType != nil {
// Set default table name
if tabler, ok := reflect.New(s.ModelType).Interface().(tabler); ok {
s.defaultTableName = tabler.TableName()
} else {
tableName := ToT... | [
"func",
"(",
"s",
"*",
"ModelStruct",
")",
"TableName",
"(",
"db",
"*",
"DB",
")",
"string",
"{",
"s",
".",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"s",
".",
"defaultTableName",
"==",
"\"... | // TableName returns model's table name | [
"TableName",
"returns",
"model",
"s",
"table",
"name"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/model_struct.go#L33-L53 |
126,584 | jinzhu/gorm | model_struct.go | TagSettingsSet | func (sf *StructField) TagSettingsSet(key, val string) {
sf.tagSettingsLock.Lock()
defer sf.tagSettingsLock.Unlock()
sf.TagSettings[key] = val
} | go | func (sf *StructField) TagSettingsSet(key, val string) {
sf.tagSettingsLock.Lock()
defer sf.tagSettingsLock.Unlock()
sf.TagSettings[key] = val
} | [
"func",
"(",
"sf",
"*",
"StructField",
")",
"TagSettingsSet",
"(",
"key",
",",
"val",
"string",
")",
"{",
"sf",
".",
"tagSettingsLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"sf",
".",
"tagSettingsLock",
".",
"Unlock",
"(",
")",
"\n",
"sf",
".",
"Tag... | // TagSettingsSet Sets a tag in the tag settings map | [
"TagSettingsSet",
"Sets",
"a",
"tag",
"in",
"the",
"tag",
"settings",
"map"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/model_struct.go#L75-L79 |
126,585 | jinzhu/gorm | model_struct.go | TagSettingsGet | func (sf *StructField) TagSettingsGet(key string) (string, bool) {
sf.tagSettingsLock.RLock()
defer sf.tagSettingsLock.RUnlock()
val, ok := sf.TagSettings[key]
return val, ok
} | go | func (sf *StructField) TagSettingsGet(key string) (string, bool) {
sf.tagSettingsLock.RLock()
defer sf.tagSettingsLock.RUnlock()
val, ok := sf.TagSettings[key]
return val, ok
} | [
"func",
"(",
"sf",
"*",
"StructField",
")",
"TagSettingsGet",
"(",
"key",
"string",
")",
"(",
"string",
",",
"bool",
")",
"{",
"sf",
".",
"tagSettingsLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"sf",
".",
"tagSettingsLock",
".",
"RUnlock",
"(",
")",
... | // TagSettingsGet returns a tag from the tag settings | [
"TagSettingsGet",
"returns",
"a",
"tag",
"from",
"the",
"tag",
"settings"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/model_struct.go#L82-L87 |
126,586 | jinzhu/gorm | model_struct.go | TagSettingsDelete | func (sf *StructField) TagSettingsDelete(key string) {
sf.tagSettingsLock.Lock()
defer sf.tagSettingsLock.Unlock()
delete(sf.TagSettings, key)
} | go | func (sf *StructField) TagSettingsDelete(key string) {
sf.tagSettingsLock.Lock()
defer sf.tagSettingsLock.Unlock()
delete(sf.TagSettings, key)
} | [
"func",
"(",
"sf",
"*",
"StructField",
")",
"TagSettingsDelete",
"(",
"key",
"string",
")",
"{",
"sf",
".",
"tagSettingsLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"sf",
".",
"tagSettingsLock",
".",
"Unlock",
"(",
")",
"\n",
"delete",
"(",
"sf",
".",
... | // TagSettingsDelete deletes a tag | [
"TagSettingsDelete",
"deletes",
"a",
"tag"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/model_struct.go#L90-L94 |
126,587 | jinzhu/gorm | dialects/mssql/mssql.go | Value | func (j JSON) Value() (driver.Value, error) {
if len(j.RawMessage) == 0 {
return nil, nil
}
return j.MarshalJSON()
} | go | func (j JSON) Value() (driver.Value, error) {
if len(j.RawMessage) == 0 {
return nil, nil
}
return j.MarshalJSON()
} | [
"func",
"(",
"j",
"JSON",
")",
"Value",
"(",
")",
"(",
"driver",
".",
"Value",
",",
"error",
")",
"{",
"if",
"len",
"(",
"j",
".",
"RawMessage",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"j",
".",
"MarshalJSON... | // Value get value of JSON | [
"Value",
"get",
"value",
"of",
"JSON"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/dialects/mssql/mssql.go#L221-L226 |
126,588 | jinzhu/gorm | dialects/mssql/mssql.go | Scan | func (j *JSON) Scan(value interface{}) error {
str, ok := value.(string)
if !ok {
return errors.New(fmt.Sprint("Failed to unmarshal JSONB value (strcast):", value))
}
bytes := []byte(str)
return json.Unmarshal(bytes, j)
} | go | func (j *JSON) Scan(value interface{}) error {
str, ok := value.(string)
if !ok {
return errors.New(fmt.Sprint("Failed to unmarshal JSONB value (strcast):", value))
}
bytes := []byte(str)
return json.Unmarshal(bytes, j)
} | [
"func",
"(",
"j",
"*",
"JSON",
")",
"Scan",
"(",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"str",
",",
"ok",
":=",
"value",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"fmt",
".",
"Sprint",... | // Scan scan value into JSON | [
"Scan",
"scan",
"value",
"into",
"JSON"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/dialects/mssql/mssql.go#L229-L236 |
126,589 | jinzhu/gorm | errors.go | IsRecordNotFoundError | func IsRecordNotFoundError(err error) bool {
if errs, ok := err.(Errors); ok {
for _, err := range errs {
if err == ErrRecordNotFound {
return true
}
}
}
return err == ErrRecordNotFound
} | go | func IsRecordNotFoundError(err error) bool {
if errs, ok := err.(Errors); ok {
for _, err := range errs {
if err == ErrRecordNotFound {
return true
}
}
}
return err == ErrRecordNotFound
} | [
"func",
"IsRecordNotFoundError",
"(",
"err",
"error",
")",
"bool",
"{",
"if",
"errs",
",",
"ok",
":=",
"err",
".",
"(",
"Errors",
")",
";",
"ok",
"{",
"for",
"_",
",",
"err",
":=",
"range",
"errs",
"{",
"if",
"err",
"==",
"ErrRecordNotFound",
"{",
... | // IsRecordNotFoundError returns true if error contains a RecordNotFound error | [
"IsRecordNotFoundError",
"returns",
"true",
"if",
"error",
"contains",
"a",
"RecordNotFound",
"error"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/errors.go#L25-L34 |
126,590 | jinzhu/gorm | errors.go | Add | func (errs Errors) Add(newErrors ...error) Errors {
for _, err := range newErrors {
if err == nil {
continue
}
if errors, ok := err.(Errors); ok {
errs = errs.Add(errors...)
} else {
ok = true
for _, e := range errs {
if err == e {
ok = false
}
}
if ok {
errs = append(errs, ... | go | func (errs Errors) Add(newErrors ...error) Errors {
for _, err := range newErrors {
if err == nil {
continue
}
if errors, ok := err.(Errors); ok {
errs = errs.Add(errors...)
} else {
ok = true
for _, e := range errs {
if err == e {
ok = false
}
}
if ok {
errs = append(errs, ... | [
"func",
"(",
"errs",
"Errors",
")",
"Add",
"(",
"newErrors",
"...",
"error",
")",
"Errors",
"{",
"for",
"_",
",",
"err",
":=",
"range",
"newErrors",
"{",
"if",
"err",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n\n",
"if",
"errors",
",",
"ok",
":=",... | // Add adds an error to a given slice of errors | [
"Add",
"adds",
"an",
"error",
"to",
"a",
"given",
"slice",
"of",
"errors"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/errors.go#L42-L63 |
126,591 | jinzhu/gorm | errors.go | Error | func (errs Errors) Error() string {
var errors = []string{}
for _, e := range errs {
errors = append(errors, e.Error())
}
return strings.Join(errors, "; ")
} | go | func (errs Errors) Error() string {
var errors = []string{}
for _, e := range errs {
errors = append(errors, e.Error())
}
return strings.Join(errors, "; ")
} | [
"func",
"(",
"errs",
"Errors",
")",
"Error",
"(",
")",
"string",
"{",
"var",
"errors",
"=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"e",
":=",
"range",
"errs",
"{",
"errors",
"=",
"append",
"(",
"errors",
",",
"e",
".",
"Error",
"(... | // Error takes a slice of all errors that have occurred and returns it as a formatted string | [
"Error",
"takes",
"a",
"slice",
"of",
"all",
"errors",
"that",
"have",
"occurred",
"and",
"returns",
"it",
"as",
"a",
"formatted",
"string"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/errors.go#L66-L72 |
126,592 | jinzhu/gorm | callback.go | After | func (cp *CallbackProcessor) After(callbackName string) *CallbackProcessor {
cp.after = callbackName
return cp
} | go | func (cp *CallbackProcessor) After(callbackName string) *CallbackProcessor {
cp.after = callbackName
return cp
} | [
"func",
"(",
"cp",
"*",
"CallbackProcessor",
")",
"After",
"(",
"callbackName",
"string",
")",
"*",
"CallbackProcessor",
"{",
"cp",
".",
"after",
"=",
"callbackName",
"\n",
"return",
"cp",
"\n",
"}"
] | // After insert a new callback after callback `callbackName`, refer `Callbacks.Create` | [
"After",
"insert",
"a",
"new",
"callback",
"after",
"callback",
"callbackName",
"refer",
"Callbacks",
".",
"Create"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/callback.go#L81-L84 |
126,593 | jinzhu/gorm | callback.go | Before | func (cp *CallbackProcessor) Before(callbackName string) *CallbackProcessor {
cp.before = callbackName
return cp
} | go | func (cp *CallbackProcessor) Before(callbackName string) *CallbackProcessor {
cp.before = callbackName
return cp
} | [
"func",
"(",
"cp",
"*",
"CallbackProcessor",
")",
"Before",
"(",
"callbackName",
"string",
")",
"*",
"CallbackProcessor",
"{",
"cp",
".",
"before",
"=",
"callbackName",
"\n",
"return",
"cp",
"\n",
"}"
] | // Before insert a new callback before callback `callbackName`, refer `Callbacks.Create` | [
"Before",
"insert",
"a",
"new",
"callback",
"before",
"callback",
"callbackName",
"refer",
"Callbacks",
".",
"Create"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/callback.go#L87-L90 |
126,594 | jinzhu/gorm | callback.go | Register | func (cp *CallbackProcessor) Register(callbackName string, callback func(scope *Scope)) {
if cp.kind == "row_query" {
if cp.before == "" && cp.after == "" && callbackName != "gorm:row_query" {
log.Printf("Registing RowQuery callback %v without specify order with Before(), After(), applying Before('gorm:row_query'... | go | func (cp *CallbackProcessor) Register(callbackName string, callback func(scope *Scope)) {
if cp.kind == "row_query" {
if cp.before == "" && cp.after == "" && callbackName != "gorm:row_query" {
log.Printf("Registing RowQuery callback %v without specify order with Before(), After(), applying Before('gorm:row_query'... | [
"func",
"(",
"cp",
"*",
"CallbackProcessor",
")",
"Register",
"(",
"callbackName",
"string",
",",
"callback",
"func",
"(",
"scope",
"*",
"Scope",
")",
")",
"{",
"if",
"cp",
".",
"kind",
"==",
"\"",
"\"",
"{",
"if",
"cp",
".",
"before",
"==",
"\"",
... | // Register a new callback, refer `Callbacks.Create` | [
"Register",
"a",
"new",
"callback",
"refer",
"Callbacks",
".",
"Create"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/callback.go#L93-L105 |
126,595 | jinzhu/gorm | callback.go | getRIndex | func getRIndex(strs []string, str string) int {
for i := len(strs) - 1; i >= 0; i-- {
if strs[i] == str {
return i
}
}
return -1
} | go | func getRIndex(strs []string, str string) int {
for i := len(strs) - 1; i >= 0; i-- {
if strs[i] == str {
return i
}
}
return -1
} | [
"func",
"getRIndex",
"(",
"strs",
"[",
"]",
"string",
",",
"str",
"string",
")",
"int",
"{",
"for",
"i",
":=",
"len",
"(",
"strs",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"if",
"strs",
"[",
"i",
"]",
"==",
"str",
"{",
"retu... | // getRIndex get right index from string slice | [
"getRIndex",
"get",
"right",
"index",
"from",
"string",
"slice"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/callback.go#L143-L150 |
126,596 | jinzhu/gorm | callback.go | sortProcessors | func sortProcessors(cps []*CallbackProcessor) []*func(scope *Scope) {
var (
allNames, sortedNames []string
sortCallbackProcessor func(c *CallbackProcessor)
)
for _, cp := range cps {
// show warning message the callback name already exists
if index := getRIndex(allNames, cp.name); index > -1 && !cp.replace ... | go | func sortProcessors(cps []*CallbackProcessor) []*func(scope *Scope) {
var (
allNames, sortedNames []string
sortCallbackProcessor func(c *CallbackProcessor)
)
for _, cp := range cps {
// show warning message the callback name already exists
if index := getRIndex(allNames, cp.name); index > -1 && !cp.replace ... | [
"func",
"sortProcessors",
"(",
"cps",
"[",
"]",
"*",
"CallbackProcessor",
")",
"[",
"]",
"*",
"func",
"(",
"scope",
"*",
"Scope",
")",
"{",
"var",
"(",
"allNames",
",",
"sortedNames",
"[",
"]",
"string",
"\n",
"sortCallbackProcessor",
"func",
"(",
"c",
... | // sortProcessors sort callback processors based on its before, after, remove, replace | [
"sortProcessors",
"sort",
"callback",
"processors",
"based",
"on",
"its",
"before",
"after",
"remove",
"replace"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/callback.go#L153-L214 |
126,597 | jinzhu/gorm | callback.go | reorder | func (c *Callback) reorder() {
var creates, updates, deletes, queries, rowQueries []*CallbackProcessor
for _, processor := range c.processors {
if processor.name != "" {
switch processor.kind {
case "create":
creates = append(creates, processor)
case "update":
updates = append(updates, processor)
... | go | func (c *Callback) reorder() {
var creates, updates, deletes, queries, rowQueries []*CallbackProcessor
for _, processor := range c.processors {
if processor.name != "" {
switch processor.kind {
case "create":
creates = append(creates, processor)
case "update":
updates = append(updates, processor)
... | [
"func",
"(",
"c",
"*",
"Callback",
")",
"reorder",
"(",
")",
"{",
"var",
"creates",
",",
"updates",
",",
"deletes",
",",
"queries",
",",
"rowQueries",
"[",
"]",
"*",
"CallbackProcessor",
"\n\n",
"for",
"_",
",",
"processor",
":=",
"range",
"c",
".",
... | // reorder all registered processors, and reset CRUD callbacks | [
"reorder",
"all",
"registered",
"processors",
"and",
"reset",
"CRUD",
"callbacks"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/callback.go#L217-L242 |
126,598 | jinzhu/gorm | field.go | Set | func (field *Field) Set(value interface{}) (err error) {
if !field.Field.IsValid() {
return errors.New("field value not valid")
}
if !field.Field.CanAddr() {
return ErrUnaddressable
}
reflectValue, ok := value.(reflect.Value)
if !ok {
reflectValue = reflect.ValueOf(value)
}
fieldValue := field.Field
i... | go | func (field *Field) Set(value interface{}) (err error) {
if !field.Field.IsValid() {
return errors.New("field value not valid")
}
if !field.Field.CanAddr() {
return ErrUnaddressable
}
reflectValue, ok := value.(reflect.Value)
if !ok {
reflectValue = reflect.ValueOf(value)
}
fieldValue := field.Field
i... | [
"func",
"(",
"field",
"*",
"Field",
")",
"Set",
"(",
"value",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"if",
"!",
"field",
".",
"Field",
".",
"IsValid",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n"... | // Set set a value to the field | [
"Set",
"set",
"a",
"value",
"to",
"the",
"field"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/field.go#L19-L66 |
126,599 | jinzhu/gorm | association.go | Find | func (association *Association) Find(value interface{}) *Association {
association.scope.related(value, association.column)
return association.setErr(association.scope.db.Error)
} | go | func (association *Association) Find(value interface{}) *Association {
association.scope.related(value, association.column)
return association.setErr(association.scope.db.Error)
} | [
"func",
"(",
"association",
"*",
"Association",
")",
"Find",
"(",
"value",
"interface",
"{",
"}",
")",
"*",
"Association",
"{",
"association",
".",
"scope",
".",
"related",
"(",
"value",
",",
"association",
".",
"column",
")",
"\n",
"return",
"association"... | // Find find out all related associations | [
"Find",
"find",
"out",
"all",
"related",
"associations"
] | b00248862ac8ca12dd54274094d404007173ec2c | https://github.com/jinzhu/gorm/blob/b00248862ac8ca12dd54274094d404007173ec2c/association.go#L18-L21 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.