repo stringlengths 5 67 | path stringlengths 4 218 | func_name stringlengths 0 151 | original_string stringlengths 52 373k | language stringclasses 6 values | code stringlengths 52 373k | code_tokens listlengths 10 512 | docstring stringlengths 3 47.2k | docstring_tokens listlengths 3 234 | sha stringlengths 40 40 | url stringlengths 85 339 | partition stringclasses 3 values |
|---|---|---|---|---|---|---|---|---|---|---|---|
google/go-jsonnet | ast/location.go | LocationRangeBetween | func LocationRangeBetween(a, b *LocationRange) LocationRange {
if a.file != b.file {
panic("Cannot create a LocationRange between different files")
}
return MakeLocationRange(a.FileName, a.file, a.Begin, b.End)
} | go | func LocationRangeBetween(a, b *LocationRange) LocationRange {
if a.file != b.file {
panic("Cannot create a LocationRange between different files")
}
return MakeLocationRange(a.FileName, a.file, a.Begin, b.End)
} | [
"func",
"LocationRangeBetween",
"(",
"a",
",",
"b",
"*",
"LocationRange",
")",
"LocationRange",
"{",
"if",
"a",
".",
"file",
"!=",
"b",
".",
"file",
"{",
"panic",
"(",
"\"Cannot create a LocationRange between different files\"",
")",
"\n",
"}",
"\n",
"return",
... | // LocationRangeBetween returns a LocationRange containing both a and b. | [
"LocationRangeBetween",
"returns",
"a",
"LocationRange",
"containing",
"both",
"a",
"and",
"b",
"."
] | 181c86d8157c7de54d052305b318be18b34d27d0 | https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/location.go#L67-L72 | train |
google/go-jsonnet | ast/location.go | MakeLocationRange | func MakeLocationRange(fn string, fc *Source, begin Location, end Location) LocationRange {
return LocationRange{FileName: fn, file: fc, Begin: begin, End: end}
} | go | func MakeLocationRange(fn string, fc *Source, begin Location, end Location) LocationRange {
return LocationRange{FileName: fn, file: fc, Begin: begin, End: end}
} | [
"func",
"MakeLocationRange",
"(",
"fn",
"string",
",",
"fc",
"*",
"Source",
",",
"begin",
"Location",
",",
"end",
"Location",
")",
"LocationRange",
"{",
"return",
"LocationRange",
"{",
"FileName",
":",
"fn",
",",
"file",
":",
"fc",
",",
"Begin",
":",
"be... | // MakeLocationRange creates a LocationRange. | [
"MakeLocationRange",
"creates",
"a",
"LocationRange",
"."
] | 181c86d8157c7de54d052305b318be18b34d27d0 | https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/location.go#L112-L114 | train |
google/go-jsonnet | ast/location.go | GetSnippet | func (sp *SourceProvider) GetSnippet(loc LocationRange) string {
var result bytes.Buffer
if loc.Begin.Line == 0 {
return ""
}
for i := loc.Begin.Line; i <= loc.End.Line; i++ {
inLineRange := trimToLine(loc, i)
for j := inLineRange.Begin.Column; j < inLineRange.End.Column; j++ {
result.WriteByte(loc.file.lines[i-1][j-1])
}
if i != loc.End.Line {
result.WriteByte('\n')
}
}
return result.String()
} | go | func (sp *SourceProvider) GetSnippet(loc LocationRange) string {
var result bytes.Buffer
if loc.Begin.Line == 0 {
return ""
}
for i := loc.Begin.Line; i <= loc.End.Line; i++ {
inLineRange := trimToLine(loc, i)
for j := inLineRange.Begin.Column; j < inLineRange.End.Column; j++ {
result.WriteByte(loc.file.lines[i-1][j-1])
}
if i != loc.End.Line {
result.WriteByte('\n')
}
}
return result.String()
} | [
"func",
"(",
"sp",
"*",
"SourceProvider",
")",
"GetSnippet",
"(",
"loc",
"LocationRange",
")",
"string",
"{",
"var",
"result",
"bytes",
".",
"Buffer",
"\n",
"if",
"loc",
".",
"Begin",
".",
"Line",
"==",
"0",
"{",
"return",
"\"\"",
"\n",
"}",
"\n",
"f... | // GetSnippet returns a code snippet corresponding to loc. | [
"GetSnippet",
"returns",
"a",
"code",
"snippet",
"corresponding",
"to",
"loc",
"."
] | 181c86d8157c7de54d052305b318be18b34d27d0 | https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/location.go#L122-L137 | train |
google/go-jsonnet | ast/ast.go | NewNodeBase | func NewNodeBase(loc LocationRange, freeVariables Identifiers) NodeBase {
return NodeBase{
loc: loc,
freeVariables: freeVariables,
}
} | go | func NewNodeBase(loc LocationRange, freeVariables Identifiers) NodeBase {
return NodeBase{
loc: loc,
freeVariables: freeVariables,
}
} | [
"func",
"NewNodeBase",
"(",
"loc",
"LocationRange",
",",
"freeVariables",
"Identifiers",
")",
"NodeBase",
"{",
"return",
"NodeBase",
"{",
"loc",
":",
"loc",
",",
"freeVariables",
":",
"freeVariables",
",",
"}",
"\n",
"}"
] | // NewNodeBase creates a new NodeBase from initial LocationRange and
// Identifiers. | [
"NewNodeBase",
"creates",
"a",
"new",
"NodeBase",
"from",
"initial",
"LocationRange",
"and",
"Identifiers",
"."
] | 181c86d8157c7de54d052305b318be18b34d27d0 | https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/ast.go#L62-L67 | train |
google/go-jsonnet | ast/ast.go | FullyEscaped | func (k LiteralStringKind) FullyEscaped() bool {
switch k {
case StringSingle, StringDouble:
return true
case StringBlock, VerbatimStringDouble, VerbatimStringSingle:
return false
}
panic(fmt.Sprintf("Unknown string kind: %v", k))
} | go | func (k LiteralStringKind) FullyEscaped() bool {
switch k {
case StringSingle, StringDouble:
return true
case StringBlock, VerbatimStringDouble, VerbatimStringSingle:
return false
}
panic(fmt.Sprintf("Unknown string kind: %v", k))
} | [
"func",
"(",
"k",
"LiteralStringKind",
")",
"FullyEscaped",
"(",
")",
"bool",
"{",
"switch",
"k",
"{",
"case",
"StringSingle",
",",
"StringDouble",
":",
"return",
"true",
"\n",
"case",
"StringBlock",
",",
"VerbatimStringDouble",
",",
"VerbatimStringSingle",
":",... | // FullyEscaped returns true iff the literal string kind may contain escape
// sequences that require unescaping. | [
"FullyEscaped",
"returns",
"true",
"iff",
"the",
"literal",
"string",
"kind",
"may",
"contain",
"escape",
"sequences",
"that",
"require",
"unescaping",
"."
] | 181c86d8157c7de54d052305b318be18b34d27d0 | https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/ast.go#L453-L461 | train |
google/go-jsonnet | ast/ast.go | ObjectFieldLocalNoMethod | func ObjectFieldLocalNoMethod(id *Identifier, body Node) ObjectField {
return ObjectField{ObjectLocal, ObjectFieldVisible, false, false, nil, nil, id, nil, false, body, nil}
} | go | func ObjectFieldLocalNoMethod(id *Identifier, body Node) ObjectField {
return ObjectField{ObjectLocal, ObjectFieldVisible, false, false, nil, nil, id, nil, false, body, nil}
} | [
"func",
"ObjectFieldLocalNoMethod",
"(",
"id",
"*",
"Identifier",
",",
"body",
"Node",
")",
"ObjectField",
"{",
"return",
"ObjectField",
"{",
"ObjectLocal",
",",
"ObjectFieldVisible",
",",
"false",
",",
"false",
",",
"nil",
",",
"nil",
",",
"id",
",",
"nil",... | // ObjectFieldLocalNoMethod creates a non-method local object field. | [
"ObjectFieldLocalNoMethod",
"creates",
"a",
"non",
"-",
"method",
"local",
"object",
"field",
"."
] | 181c86d8157c7de54d052305b318be18b34d27d0 | https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/ast.go#L514-L516 | train |
google/go-jsonnet | ast/clone.go | cloneForSpec | func cloneForSpec(specPtr *ForSpec) {
clone(&specPtr.Expr)
oldOuter := specPtr.Outer
if oldOuter != nil {
specPtr.Outer = new(ForSpec)
*specPtr.Outer = *oldOuter
cloneForSpec(specPtr.Outer)
}
for i := range specPtr.Conditions {
clone(&specPtr.Conditions[i].Expr)
}
} | go | func cloneForSpec(specPtr *ForSpec) {
clone(&specPtr.Expr)
oldOuter := specPtr.Outer
if oldOuter != nil {
specPtr.Outer = new(ForSpec)
*specPtr.Outer = *oldOuter
cloneForSpec(specPtr.Outer)
}
for i := range specPtr.Conditions {
clone(&specPtr.Conditions[i].Expr)
}
} | [
"func",
"cloneForSpec",
"(",
"specPtr",
"*",
"ForSpec",
")",
"{",
"clone",
"(",
"&",
"specPtr",
".",
"Expr",
")",
"\n",
"oldOuter",
":=",
"specPtr",
".",
"Outer",
"\n",
"if",
"oldOuter",
"!=",
"nil",
"{",
"specPtr",
".",
"Outer",
"=",
"new",
"(",
"Fo... | // Updates fields of specPtr to point to deep clones. | [
"Updates",
"fields",
"of",
"specPtr",
"to",
"point",
"to",
"deep",
"clones",
"."
] | 181c86d8157c7de54d052305b318be18b34d27d0 | https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/clone.go#L25-L36 | train |
google/go-jsonnet | ast/clone.go | cloneParameters | func cloneParameters(params *Parameters) {
if params == nil {
return
}
params.Optional = append(make([]NamedParameter, 0), params.Optional...)
for i := range params.Optional {
clone(¶ms.Optional[i].DefaultArg)
}
} | go | func cloneParameters(params *Parameters) {
if params == nil {
return
}
params.Optional = append(make([]NamedParameter, 0), params.Optional...)
for i := range params.Optional {
clone(¶ms.Optional[i].DefaultArg)
}
} | [
"func",
"cloneParameters",
"(",
"params",
"*",
"Parameters",
")",
"{",
"if",
"params",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"params",
".",
"Optional",
"=",
"append",
"(",
"make",
"(",
"[",
"]",
"NamedParameter",
",",
"0",
")",
",",
"params",
... | // Updates fields of params to point to deep clones. | [
"Updates",
"fields",
"of",
"params",
"to",
"point",
"to",
"deep",
"clones",
"."
] | 181c86d8157c7de54d052305b318be18b34d27d0 | https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/clone.go#L39-L47 | train |
google/go-jsonnet | ast/clone.go | cloneField | func cloneField(field *ObjectField) {
if field.Method != nil {
field.Method = Clone(field.Method).(*Function)
}
oldParams := field.Params
if oldParams != nil {
field.Params = new(Parameters)
*field.Params = *oldParams
}
cloneParameters(field.Params)
clone(&field.Expr1)
clone(&field.Expr2)
clone(&field.Expr3)
} | go | func cloneField(field *ObjectField) {
if field.Method != nil {
field.Method = Clone(field.Method).(*Function)
}
oldParams := field.Params
if oldParams != nil {
field.Params = new(Parameters)
*field.Params = *oldParams
}
cloneParameters(field.Params)
clone(&field.Expr1)
clone(&field.Expr2)
clone(&field.Expr3)
} | [
"func",
"cloneField",
"(",
"field",
"*",
"ObjectField",
")",
"{",
"if",
"field",
".",
"Method",
"!=",
"nil",
"{",
"field",
".",
"Method",
"=",
"Clone",
"(",
"field",
".",
"Method",
")",
".",
"(",
"*",
"Function",
")",
"\n",
"}",
"\n",
"oldParams",
... | // Updates fields of field to point to deep clones. | [
"Updates",
"fields",
"of",
"field",
"to",
"point",
"to",
"deep",
"clones",
"."
] | 181c86d8157c7de54d052305b318be18b34d27d0 | https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/clone.go#L50-L65 | train |
google/go-jsonnet | ast/clone.go | cloneNodeBase | func cloneNodeBase(astPtr Node) {
if astPtr.Context() != nil {
newContext := new(string)
*newContext = *astPtr.Context()
astPtr.SetContext(newContext)
}
astPtr.SetFreeVariables(append(make(Identifiers, 0), astPtr.FreeVariables()...))
} | go | func cloneNodeBase(astPtr Node) {
if astPtr.Context() != nil {
newContext := new(string)
*newContext = *astPtr.Context()
astPtr.SetContext(newContext)
}
astPtr.SetFreeVariables(append(make(Identifiers, 0), astPtr.FreeVariables()...))
} | [
"func",
"cloneNodeBase",
"(",
"astPtr",
"Node",
")",
"{",
"if",
"astPtr",
".",
"Context",
"(",
")",
"!=",
"nil",
"{",
"newContext",
":=",
"new",
"(",
"string",
")",
"\n",
"*",
"newContext",
"=",
"*",
"astPtr",
".",
"Context",
"(",
")",
"\n",
"astPtr"... | // Updates the NodeBase fields of astPtr to point to deep clones. | [
"Updates",
"the",
"NodeBase",
"fields",
"of",
"astPtr",
"to",
"point",
"to",
"deep",
"clones",
"."
] | 181c86d8157c7de54d052305b318be18b34d27d0 | https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/ast/clone.go#L74-L81 | train |
google/go-jsonnet | dump/pointermap.go | getAllAndReusedPointers | func (pm *pointerMap) getAllAndReusedPointers(v reflect.Value) {
if v.Kind() == reflect.Invalid {
return
}
if isPointerValue(v) && v.Pointer() != 0 { // pointer is 0 for unexported fields
reused := pm.addPointer(v.Pointer())
if reused {
// No use descending inside this value, since it have been seen before and all its descendants
// have been considered
return
}
}
// Now descend into any children of this value
switch v.Kind() {
case reflect.Slice, reflect.Array:
numEntries := v.Len()
for i := 0; i < numEntries; i++ {
pm.getAllAndReusedPointers(v.Index(i))
}
case reflect.Interface:
pm.getAllAndReusedPointers(v.Elem())
case reflect.Ptr:
pm.getAllAndReusedPointers(v.Elem())
case reflect.Map:
for _, key := range v.MapKeys() {
pm.getAllAndReusedPointers(v.MapIndex(key))
}
case reflect.Struct:
numFields := v.NumField()
for i := 0; i < numFields; i++ {
pm.getAllAndReusedPointers(v.Field(i))
}
}
} | go | func (pm *pointerMap) getAllAndReusedPointers(v reflect.Value) {
if v.Kind() == reflect.Invalid {
return
}
if isPointerValue(v) && v.Pointer() != 0 { // pointer is 0 for unexported fields
reused := pm.addPointer(v.Pointer())
if reused {
// No use descending inside this value, since it have been seen before and all its descendants
// have been considered
return
}
}
// Now descend into any children of this value
switch v.Kind() {
case reflect.Slice, reflect.Array:
numEntries := v.Len()
for i := 0; i < numEntries; i++ {
pm.getAllAndReusedPointers(v.Index(i))
}
case reflect.Interface:
pm.getAllAndReusedPointers(v.Elem())
case reflect.Ptr:
pm.getAllAndReusedPointers(v.Elem())
case reflect.Map:
for _, key := range v.MapKeys() {
pm.getAllAndReusedPointers(v.MapIndex(key))
}
case reflect.Struct:
numFields := v.NumField()
for i := 0; i < numFields; i++ {
pm.getAllAndReusedPointers(v.Field(i))
}
}
} | [
"func",
"(",
"pm",
"*",
"pointerMap",
")",
"getAllAndReusedPointers",
"(",
"v",
"reflect",
".",
"Value",
")",
"{",
"if",
"v",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Invalid",
"{",
"return",
"\n",
"}",
"\n",
"if",
"isPointerValue",
"(",
"v",
")... | // Recursively consider v and each of its children, updating pointer information | [
"Recursively",
"consider",
"v",
"and",
"each",
"of",
"its",
"children",
"updating",
"pointer",
"information"
] | 181c86d8157c7de54d052305b318be18b34d27d0 | https://github.com/google/go-jsonnet/blob/181c86d8157c7de54d052305b318be18b34d27d0/dump/pointermap.go#L81-L119 | train |
gobuffalo/pop | associations/associations_for_struct.go | ForStruct | func ForStruct(s interface{}, fields ...string) (Associations, error) {
associations := Associations{}
innerAssociations := InnerAssociations{}
t, v := getModelDefinition(s)
fields = trimFields(fields)
// validate if fields contains a non existing field in struct.
// and vefiry is it has inner associations.
for i := range fields {
var innerField, field string
if !validAssociationExpRegexp.MatchString(fields[i]) {
return associations, fmt.Errorf("association '%s' does not match the format %s", fields[i], "'<field>' or '<field>.<nested-field>'")
}
if strings.Contains(fields[i], ".") {
field = fields[i][:strings.Index(fields[i], ".")]
innerField = fields[i][strings.Index(fields[i], ".")+1:]
fields[i] = field
}
if _, ok := t.FieldByName(fields[i]); !ok {
return associations, fmt.Errorf("field %s does not exist in model %s", fields[i], t.Name())
}
if innerField != "" {
innerAssociations = append(innerAssociations, InnerAssociation{fields[i], innerField})
}
}
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)
// ignores those fields not included in fields list.
if len(fields) > 0 && fieldIgnoredIn(fields, f.Name) {
continue
}
tags := columns.TagsFor(f)
for name, builder := range associationBuilders {
tag := tags.Find(name)
if !tag.Empty() {
params := associationParams{
field: f,
model: s,
modelType: t,
modelValue: v,
popTags: tags,
innerAssociations: innerAssociations,
}
a, err := builder(params)
if err != nil {
return associations, err
}
associations = append(associations, a)
break
}
}
}
return associations, nil
} | go | func ForStruct(s interface{}, fields ...string) (Associations, error) {
associations := Associations{}
innerAssociations := InnerAssociations{}
t, v := getModelDefinition(s)
fields = trimFields(fields)
// validate if fields contains a non existing field in struct.
// and vefiry is it has inner associations.
for i := range fields {
var innerField, field string
if !validAssociationExpRegexp.MatchString(fields[i]) {
return associations, fmt.Errorf("association '%s' does not match the format %s", fields[i], "'<field>' or '<field>.<nested-field>'")
}
if strings.Contains(fields[i], ".") {
field = fields[i][:strings.Index(fields[i], ".")]
innerField = fields[i][strings.Index(fields[i], ".")+1:]
fields[i] = field
}
if _, ok := t.FieldByName(fields[i]); !ok {
return associations, fmt.Errorf("field %s does not exist in model %s", fields[i], t.Name())
}
if innerField != "" {
innerAssociations = append(innerAssociations, InnerAssociation{fields[i], innerField})
}
}
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)
// ignores those fields not included in fields list.
if len(fields) > 0 && fieldIgnoredIn(fields, f.Name) {
continue
}
tags := columns.TagsFor(f)
for name, builder := range associationBuilders {
tag := tags.Find(name)
if !tag.Empty() {
params := associationParams{
field: f,
model: s,
modelType: t,
modelValue: v,
popTags: tags,
innerAssociations: innerAssociations,
}
a, err := builder(params)
if err != nil {
return associations, err
}
associations = append(associations, a)
break
}
}
}
return associations, nil
} | [
"func",
"ForStruct",
"(",
"s",
"interface",
"{",
"}",
",",
"fields",
"...",
"string",
")",
"(",
"Associations",
",",
"error",
")",
"{",
"associations",
":=",
"Associations",
"{",
"}",
"\n",
"innerAssociations",
":=",
"InnerAssociations",
"{",
"}",
"\n",
"t... | // ForStruct returns all associations for
// the struct specified. It takes into account tags
// associations like has_many, belongs_to, has_one.
// it throws an error when it finds a field that does
// not exist for a model. | [
"ForStruct",
"returns",
"all",
"associations",
"for",
"the",
"struct",
"specified",
".",
"It",
"takes",
"into",
"account",
"tags",
"associations",
"like",
"has_many",
"belongs_to",
"has_one",
".",
"it",
"throws",
"an",
"error",
"when",
"it",
"finds",
"a",
"fie... | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/associations/associations_for_struct.go#L42-L106 | train |
gobuffalo/pop | slices/uuid.go | Scan | func (s *UUID) Scan(src interface{}) error {
b, ok := src.([]byte)
if !ok {
return errors.New("Scan source was not []byte")
}
us, err := strSliceToUUIDSlice(strToUUID(string(b)))
if err != nil {
return errors.WithStack(err)
}
*s = us
return nil
} | go | func (s *UUID) Scan(src interface{}) error {
b, ok := src.([]byte)
if !ok {
return errors.New("Scan source was not []byte")
}
us, err := strSliceToUUIDSlice(strToUUID(string(b)))
if err != nil {
return errors.WithStack(err)
}
*s = us
return nil
} | [
"func",
"(",
"s",
"*",
"UUID",
")",
"Scan",
"(",
"src",
"interface",
"{",
"}",
")",
"error",
"{",
"b",
",",
"ok",
":=",
"src",
".",
"(",
"[",
"]",
"byte",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"Scan source was ... | // Scan implements the sql.Scanner interface.
// It allows to read the UUID slice from the database value. | [
"Scan",
"implements",
"the",
"sql",
".",
"Scanner",
"interface",
".",
"It",
"allows",
"to",
"read",
"the",
"UUID",
"slice",
"from",
"the",
"database",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/uuid.go#L25-L36 | train |
gobuffalo/pop | slices/uuid.go | Value | func (s UUID) Value() (driver.Value, error) {
ss := make([]string, len(s))
for i, u := range s {
ss[i] = u.String()
}
return fmt.Sprintf("{%s}", strings.Join(ss, ",")), nil
} | go | func (s UUID) Value() (driver.Value, error) {
ss := make([]string, len(s))
for i, u := range s {
ss[i] = u.String()
}
return fmt.Sprintf("{%s}", strings.Join(ss, ",")), nil
} | [
"func",
"(",
"s",
"UUID",
")",
"Value",
"(",
")",
"(",
"driver",
".",
"Value",
",",
"error",
")",
"{",
"ss",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"s",
")",
")",
"\n",
"for",
"i",
",",
"u",
":=",
"range",
"s",
"{",
"ss",
... | // Value implements the driver.Valuer interface.
// It allows to convert the UUID slice to a driver.value. | [
"Value",
"implements",
"the",
"driver",
".",
"Valuer",
"interface",
".",
"It",
"allows",
"to",
"convert",
"the",
"UUID",
"slice",
"to",
"a",
"driver",
".",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/uuid.go#L40-L46 | train |
gobuffalo/pop | slices/uuid.go | UnmarshalJSON | func (s *UUID) UnmarshalJSON(data []byte) error {
var ss []string
if err := json.Unmarshal(data, &ss); err != nil {
return err
}
us, err := strSliceToUUIDSlice(ss)
if err != nil {
return errors.WithStack(err)
}
*s = us
return nil
} | go | func (s *UUID) UnmarshalJSON(data []byte) error {
var ss []string
if err := json.Unmarshal(data, &ss); err != nil {
return err
}
us, err := strSliceToUUIDSlice(ss)
if err != nil {
return errors.WithStack(err)
}
*s = us
return nil
} | [
"func",
"(",
"s",
"*",
"UUID",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ss",
"[",
"]",
"string",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"ss",
")",
";",
"err",
"!=",
"nil"... | // UnmarshalJSON will unmarshall JSON value into
// the UUID slice representation of this value. | [
"UnmarshalJSON",
"will",
"unmarshall",
"JSON",
"value",
"into",
"the",
"UUID",
"slice",
"representation",
"of",
"this",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/uuid.go#L50-L61 | train |
gobuffalo/pop | slices/uuid.go | UnmarshalText | func (s *UUID) UnmarshalText(text []byte) error {
var ss []string
for _, x := range strings.Split(string(text), ",") {
ss = append(ss, strings.TrimSpace(x))
}
us, err := strSliceToUUIDSlice(ss)
if err != nil {
return errors.WithStack(err)
}
*s = us
return nil
} | go | func (s *UUID) UnmarshalText(text []byte) error {
var ss []string
for _, x := range strings.Split(string(text), ",") {
ss = append(ss, strings.TrimSpace(x))
}
us, err := strSliceToUUIDSlice(ss)
if err != nil {
return errors.WithStack(err)
}
*s = us
return nil
} | [
"func",
"(",
"s",
"*",
"UUID",
")",
"UnmarshalText",
"(",
"text",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ss",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"x",
":=",
"range",
"strings",
".",
"Split",
"(",
"string",
"(",
"text",
")",
",",
"\... | // UnmarshalText will unmarshall text value into
// the UUID slice representation of this value. | [
"UnmarshalText",
"will",
"unmarshall",
"text",
"value",
"into",
"the",
"UUID",
"slice",
"representation",
"of",
"this",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/uuid.go#L65-L76 | train |
gobuffalo/pop | migration.go | MigrationCreate | func MigrationCreate(path, name, ext string, up, down []byte) error {
g := makr.New()
n := time.Now().UTC()
s := n.Format("20060102150405")
upf := filepath.Join(path, fmt.Sprintf("%s_%s.up.%s", s, name, ext))
g.Add(makr.NewFile(upf, string(up)))
downf := filepath.Join(path, fmt.Sprintf("%s_%s.down.%s", s, name, ext))
g.Add(makr.NewFile(downf, string(down)))
return g.Run(".", makr.Data{})
} | go | func MigrationCreate(path, name, ext string, up, down []byte) error {
g := makr.New()
n := time.Now().UTC()
s := n.Format("20060102150405")
upf := filepath.Join(path, fmt.Sprintf("%s_%s.up.%s", s, name, ext))
g.Add(makr.NewFile(upf, string(up)))
downf := filepath.Join(path, fmt.Sprintf("%s_%s.down.%s", s, name, ext))
g.Add(makr.NewFile(downf, string(down)))
return g.Run(".", makr.Data{})
} | [
"func",
"MigrationCreate",
"(",
"path",
",",
"name",
",",
"ext",
"string",
",",
"up",
",",
"down",
"[",
"]",
"byte",
")",
"error",
"{",
"g",
":=",
"makr",
".",
"New",
"(",
")",
"\n",
"n",
":=",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
"... | // MigrationCreate writes contents for a given migration in normalized files | [
"MigrationCreate",
"writes",
"contents",
"for",
"a",
"given",
"migration",
"in",
"normalized",
"files"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migration.go#L14-L26 | train |
gobuffalo/pop | migrator.go | NewMigrator | func NewMigrator(c *Connection) Migrator {
return Migrator{
Connection: c,
Migrations: map[string]Migrations{
"up": {},
"down": {},
},
}
} | go | func NewMigrator(c *Connection) Migrator {
return Migrator{
Connection: c,
Migrations: map[string]Migrations{
"up": {},
"down": {},
},
}
} | [
"func",
"NewMigrator",
"(",
"c",
"*",
"Connection",
")",
"Migrator",
"{",
"return",
"Migrator",
"{",
"Connection",
":",
"c",
",",
"Migrations",
":",
"map",
"[",
"string",
"]",
"Migrations",
"{",
"\"up\"",
":",
"{",
"}",
",",
"\"down\"",
":",
"{",
"}",
... | // NewMigrator returns a new "blank" migrator. It is recommended
// to use something like MigrationBox or FileMigrator. A "blank"
// Migrator should only be used as the basis for a new type of
// migration system. | [
"NewMigrator",
"returns",
"a",
"new",
"blank",
"migrator",
".",
"It",
"is",
"recommended",
"to",
"use",
"something",
"like",
"MigrationBox",
"or",
"FileMigrator",
".",
"A",
"blank",
"Migrator",
"should",
"only",
"be",
"used",
"as",
"the",
"basis",
"for",
"a"... | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migrator.go#L22-L30 | train |
gobuffalo/pop | migrator.go | UpLogOnly | func (m Migrator) UpLogOnly() error {
c := m.Connection
return m.exec(func() error {
mtn := c.MigrationTableName()
mfs := m.Migrations["up"]
sort.Sort(mfs)
return c.Transaction(func(tx *Connection) error {
for _, mi := range mfs {
if mi.DBType != "all" && mi.DBType != c.Dialect.Name() {
// Skip migration for non-matching dialect
continue
}
exists, err := c.Where("version = ?", mi.Version).Exists(mtn)
if err != nil {
return errors.Wrapf(err, "problem checking for migration version %s", mi.Version)
}
if exists {
continue
}
_, err = tx.Store.Exec(fmt.Sprintf("insert into %s (version) values ('%s')", mtn, mi.Version))
if err != nil {
return errors.Wrapf(err, "problem inserting migration version %s", mi.Version)
}
}
return nil
})
})
} | go | func (m Migrator) UpLogOnly() error {
c := m.Connection
return m.exec(func() error {
mtn := c.MigrationTableName()
mfs := m.Migrations["up"]
sort.Sort(mfs)
return c.Transaction(func(tx *Connection) error {
for _, mi := range mfs {
if mi.DBType != "all" && mi.DBType != c.Dialect.Name() {
// Skip migration for non-matching dialect
continue
}
exists, err := c.Where("version = ?", mi.Version).Exists(mtn)
if err != nil {
return errors.Wrapf(err, "problem checking for migration version %s", mi.Version)
}
if exists {
continue
}
_, err = tx.Store.Exec(fmt.Sprintf("insert into %s (version) values ('%s')", mtn, mi.Version))
if err != nil {
return errors.Wrapf(err, "problem inserting migration version %s", mi.Version)
}
}
return nil
})
})
} | [
"func",
"(",
"m",
"Migrator",
")",
"UpLogOnly",
"(",
")",
"error",
"{",
"c",
":=",
"m",
".",
"Connection",
"\n",
"return",
"m",
".",
"exec",
"(",
"func",
"(",
")",
"error",
"{",
"mtn",
":=",
"c",
".",
"MigrationTableName",
"(",
")",
"\n",
"mfs",
... | // UpLogOnly insert pending "up" migrations logs only, without applying the patch.
// It's used when loading the schema dump, instead of the migrations. | [
"UpLogOnly",
"insert",
"pending",
"up",
"migrations",
"logs",
"only",
"without",
"applying",
"the",
"patch",
".",
"It",
"s",
"used",
"when",
"loading",
"the",
"schema",
"dump",
"instead",
"of",
"the",
"migrations",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migrator.go#L44-L71 | train |
gobuffalo/pop | migrator.go | Up | func (m Migrator) Up() error {
c := m.Connection
return m.exec(func() error {
mtn := c.MigrationTableName()
mfs := m.Migrations["up"]
sort.Sort(mfs)
applied := 0
for _, mi := range mfs {
if mi.DBType != "all" && mi.DBType != c.Dialect.Name() {
// Skip migration for non-matching dialect
continue
}
exists, err := c.Where("version = ?", mi.Version).Exists(mtn)
if err != nil {
return errors.Wrapf(err, "problem checking for migration version %s", mi.Version)
}
if exists {
continue
}
err = c.Transaction(func(tx *Connection) error {
err := mi.Run(tx)
if err != nil {
return err
}
_, err = tx.Store.Exec(fmt.Sprintf("insert into %s (version) values ('%s')", mtn, mi.Version))
return errors.Wrapf(err, "problem inserting migration version %s", mi.Version)
})
if err != nil {
return errors.WithStack(err)
}
log(logging.Info, "> %s", mi.Name)
applied++
}
if applied == 0 {
log(logging.Info, "Migrations already up to date, nothing to apply")
}
return nil
})
} | go | func (m Migrator) Up() error {
c := m.Connection
return m.exec(func() error {
mtn := c.MigrationTableName()
mfs := m.Migrations["up"]
sort.Sort(mfs)
applied := 0
for _, mi := range mfs {
if mi.DBType != "all" && mi.DBType != c.Dialect.Name() {
// Skip migration for non-matching dialect
continue
}
exists, err := c.Where("version = ?", mi.Version).Exists(mtn)
if err != nil {
return errors.Wrapf(err, "problem checking for migration version %s", mi.Version)
}
if exists {
continue
}
err = c.Transaction(func(tx *Connection) error {
err := mi.Run(tx)
if err != nil {
return err
}
_, err = tx.Store.Exec(fmt.Sprintf("insert into %s (version) values ('%s')", mtn, mi.Version))
return errors.Wrapf(err, "problem inserting migration version %s", mi.Version)
})
if err != nil {
return errors.WithStack(err)
}
log(logging.Info, "> %s", mi.Name)
applied++
}
if applied == 0 {
log(logging.Info, "Migrations already up to date, nothing to apply")
}
return nil
})
} | [
"func",
"(",
"m",
"Migrator",
")",
"Up",
"(",
")",
"error",
"{",
"c",
":=",
"m",
".",
"Connection",
"\n",
"return",
"m",
".",
"exec",
"(",
"func",
"(",
")",
"error",
"{",
"mtn",
":=",
"c",
".",
"MigrationTableName",
"(",
")",
"\n",
"mfs",
":=",
... | // Up runs pending "up" migrations and applies them to the database. | [
"Up",
"runs",
"pending",
"up",
"migrations",
"and",
"applies",
"them",
"to",
"the",
"database",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migrator.go#L74-L112 | train |
gobuffalo/pop | migrator.go | Down | func (m Migrator) Down(step int) error {
c := m.Connection
return m.exec(func() error {
mtn := c.MigrationTableName()
count, err := c.Count(mtn)
if err != nil {
return errors.Wrap(err, "migration down: unable count existing migration")
}
mfs := m.Migrations["down"]
sort.Sort(sort.Reverse(mfs))
// skip all runned migration
if len(mfs) > count {
mfs = mfs[len(mfs)-count:]
}
// run only required steps
if step > 0 && len(mfs) >= step {
mfs = mfs[:step]
}
for _, mi := range mfs {
exists, err := c.Where("version = ?", mi.Version).Exists(mtn)
if err != nil || !exists {
return errors.Wrapf(err, "problem checking for migration version %s", mi.Version)
}
err = c.Transaction(func(tx *Connection) error {
err := mi.Run(tx)
if err != nil {
return err
}
err = tx.RawQuery(fmt.Sprintf("delete from %s where version = ?", mtn), mi.Version).Exec()
return errors.Wrapf(err, "problem deleting migration version %s", mi.Version)
})
if err != nil {
return err
}
log(logging.Info, "< %s", mi.Name)
}
return nil
})
} | go | func (m Migrator) Down(step int) error {
c := m.Connection
return m.exec(func() error {
mtn := c.MigrationTableName()
count, err := c.Count(mtn)
if err != nil {
return errors.Wrap(err, "migration down: unable count existing migration")
}
mfs := m.Migrations["down"]
sort.Sort(sort.Reverse(mfs))
// skip all runned migration
if len(mfs) > count {
mfs = mfs[len(mfs)-count:]
}
// run only required steps
if step > 0 && len(mfs) >= step {
mfs = mfs[:step]
}
for _, mi := range mfs {
exists, err := c.Where("version = ?", mi.Version).Exists(mtn)
if err != nil || !exists {
return errors.Wrapf(err, "problem checking for migration version %s", mi.Version)
}
err = c.Transaction(func(tx *Connection) error {
err := mi.Run(tx)
if err != nil {
return err
}
err = tx.RawQuery(fmt.Sprintf("delete from %s where version = ?", mtn), mi.Version).Exec()
return errors.Wrapf(err, "problem deleting migration version %s", mi.Version)
})
if err != nil {
return err
}
log(logging.Info, "< %s", mi.Name)
}
return nil
})
} | [
"func",
"(",
"m",
"Migrator",
")",
"Down",
"(",
"step",
"int",
")",
"error",
"{",
"c",
":=",
"m",
".",
"Connection",
"\n",
"return",
"m",
".",
"exec",
"(",
"func",
"(",
")",
"error",
"{",
"mtn",
":=",
"c",
".",
"MigrationTableName",
"(",
")",
"\n... | // Down runs pending "down" migrations and rolls back the
// database by the specified number of steps. | [
"Down",
"runs",
"pending",
"down",
"migrations",
"and",
"rolls",
"back",
"the",
"database",
"by",
"the",
"specified",
"number",
"of",
"steps",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migrator.go#L116-L155 | train |
gobuffalo/pop | migrator.go | Reset | func (m Migrator) Reset() error {
err := m.Down(-1)
if err != nil {
return errors.WithStack(err)
}
return m.Up()
} | go | func (m Migrator) Reset() error {
err := m.Down(-1)
if err != nil {
return errors.WithStack(err)
}
return m.Up()
} | [
"func",
"(",
"m",
"Migrator",
")",
"Reset",
"(",
")",
"error",
"{",
"err",
":=",
"m",
".",
"Down",
"(",
"-",
"1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"m",
... | // Reset the database by running the down migrations followed by the up migrations. | [
"Reset",
"the",
"database",
"by",
"running",
"the",
"down",
"migrations",
"followed",
"by",
"the",
"up",
"migrations",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migrator.go#L158-L164 | train |
gobuffalo/pop | migrator.go | CreateSchemaMigrations | func (m Migrator) CreateSchemaMigrations() error {
c := m.Connection
mtn := c.MigrationTableName()
err := c.Open()
if err != nil {
return errors.Wrap(err, "could not open connection")
}
_, err = c.Store.Exec(fmt.Sprintf("select * from %s", mtn))
if err == nil {
return nil
}
return c.Transaction(func(tx *Connection) error {
schemaMigrations := newSchemaMigrations(mtn)
smSQL, err := c.Dialect.FizzTranslator().CreateTable(schemaMigrations)
if err != nil {
return errors.Wrap(err, "could not build SQL for schema migration table")
}
err = tx.RawQuery(smSQL).Exec()
if err != nil {
return errors.WithStack(errors.Wrap(err, smSQL))
}
return nil
})
} | go | func (m Migrator) CreateSchemaMigrations() error {
c := m.Connection
mtn := c.MigrationTableName()
err := c.Open()
if err != nil {
return errors.Wrap(err, "could not open connection")
}
_, err = c.Store.Exec(fmt.Sprintf("select * from %s", mtn))
if err == nil {
return nil
}
return c.Transaction(func(tx *Connection) error {
schemaMigrations := newSchemaMigrations(mtn)
smSQL, err := c.Dialect.FizzTranslator().CreateTable(schemaMigrations)
if err != nil {
return errors.Wrap(err, "could not build SQL for schema migration table")
}
err = tx.RawQuery(smSQL).Exec()
if err != nil {
return errors.WithStack(errors.Wrap(err, smSQL))
}
return nil
})
} | [
"func",
"(",
"m",
"Migrator",
")",
"CreateSchemaMigrations",
"(",
")",
"error",
"{",
"c",
":=",
"m",
".",
"Connection",
"\n",
"mtn",
":=",
"c",
".",
"MigrationTableName",
"(",
")",
"\n",
"err",
":=",
"c",
".",
"Open",
"(",
")",
"\n",
"if",
"err",
"... | // CreateSchemaMigrations sets up a table to track migrations. This is an idempotent
// operation. | [
"CreateSchemaMigrations",
"sets",
"up",
"a",
"table",
"to",
"track",
"migrations",
".",
"This",
"is",
"an",
"idempotent",
"operation",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migrator.go#L168-L192 | train |
gobuffalo/pop | migrator.go | DumpMigrationSchema | func (m Migrator) DumpMigrationSchema() error {
if m.SchemaPath == "" {
return nil
}
c := m.Connection
schema := filepath.Join(m.SchemaPath, "schema.sql")
f, err := os.Create(schema)
if err != nil {
return errors.WithStack(err)
}
err = c.Dialect.DumpSchema(f)
if err != nil {
os.RemoveAll(schema)
return errors.WithStack(err)
}
return nil
} | go | func (m Migrator) DumpMigrationSchema() error {
if m.SchemaPath == "" {
return nil
}
c := m.Connection
schema := filepath.Join(m.SchemaPath, "schema.sql")
f, err := os.Create(schema)
if err != nil {
return errors.WithStack(err)
}
err = c.Dialect.DumpSchema(f)
if err != nil {
os.RemoveAll(schema)
return errors.WithStack(err)
}
return nil
} | [
"func",
"(",
"m",
"Migrator",
")",
"DumpMigrationSchema",
"(",
")",
"error",
"{",
"if",
"m",
".",
"SchemaPath",
"==",
"\"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"c",
":=",
"m",
".",
"Connection",
"\n",
"schema",
":=",
"filepath",
".",
"Join",
"("... | // DumpMigrationSchema will generate a file of the current database schema
// based on the value of Migrator.SchemaPath | [
"DumpMigrationSchema",
"will",
"generate",
"a",
"file",
"of",
"the",
"current",
"database",
"schema",
"based",
"on",
"the",
"value",
"of",
"Migrator",
".",
"SchemaPath"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migrator.go#L218-L234 | train |
gobuffalo/pop | pop.go | DialectSupported | func DialectSupported(d string) bool {
for _, ad := range AvailableDialects {
if ad == d {
return true
}
}
return false
} | go | func DialectSupported(d string) bool {
for _, ad := range AvailableDialects {
if ad == d {
return true
}
}
return false
} | [
"func",
"DialectSupported",
"(",
"d",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"ad",
":=",
"range",
"AvailableDialects",
"{",
"if",
"ad",
"==",
"d",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // DialectSupported checks support for the given database dialect | [
"DialectSupported",
"checks",
"support",
"for",
"the",
"given",
"database",
"dialect"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/pop.go#L20-L27 | train |
gobuffalo/pop | columns/column.go | UpdateString | func (c Column) UpdateString() string {
return fmt.Sprintf("%s = :%s", c.Name, c.Name)
} | go | func (c Column) UpdateString() string {
return fmt.Sprintf("%s = :%s", c.Name, c.Name)
} | [
"func",
"(",
"c",
"Column",
")",
"UpdateString",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"%s = :%s\"",
",",
"c",
".",
"Name",
",",
"c",
".",
"Name",
")",
"\n",
"}"
] | // UpdateString returns the SQL statement to UPDATE the column. | [
"UpdateString",
"returns",
"the",
"SQL",
"statement",
"to",
"UPDATE",
"the",
"column",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/columns/column.go#L14-L16 | train |
gobuffalo/pop | columns/column.go | SetSelectSQL | func (c *Column) SetSelectSQL(s string) {
c.SelectSQL = s
c.Writeable = false
c.Readable = true
} | go | func (c *Column) SetSelectSQL(s string) {
c.SelectSQL = s
c.Writeable = false
c.Readable = true
} | [
"func",
"(",
"c",
"*",
"Column",
")",
"SetSelectSQL",
"(",
"s",
"string",
")",
"{",
"c",
".",
"SelectSQL",
"=",
"s",
"\n",
"c",
".",
"Writeable",
"=",
"false",
"\n",
"c",
".",
"Readable",
"=",
"true",
"\n",
"}"
] | // SetSelectSQL sets a custom SELECT statement for the column. | [
"SetSelectSQL",
"sets",
"a",
"custom",
"SELECT",
"statement",
"for",
"the",
"column",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/columns/column.go#L19-L23 | train |
gobuffalo/pop | query_joins.go | Join | func (q *Query) Join(table string, on string, args ...interface{}) *Query {
if q.RawSQL.Fragment != "" {
log(logging.Warn, "Query is setup to use raw SQL")
return q
}
q.joinClauses = append(q.joinClauses, joinClause{"JOIN", table, on, args})
return q
} | go | func (q *Query) Join(table string, on string, args ...interface{}) *Query {
if q.RawSQL.Fragment != "" {
log(logging.Warn, "Query is setup to use raw SQL")
return q
}
q.joinClauses = append(q.joinClauses, joinClause{"JOIN", table, on, args})
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Join",
"(",
"table",
"string",
",",
"on",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"Query",
"{",
"if",
"q",
".",
"RawSQL",
".",
"Fragment",
"!=",
"\"\"",
"{",
"log",
"(",
"logging",
".",... | // Join will append a JOIN clause to the query | [
"Join",
"will",
"append",
"a",
"JOIN",
"clause",
"to",
"the",
"query"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/query_joins.go#L9-L16 | train |
gobuffalo/pop | query.go | Clone | func (q *Query) Clone(targetQ *Query) {
rawSQL := *q.RawSQL
targetQ.RawSQL = &rawSQL
targetQ.limitResults = q.limitResults
targetQ.whereClauses = q.whereClauses
targetQ.orderClauses = q.orderClauses
targetQ.fromClauses = q.fromClauses
targetQ.belongsToThroughClauses = q.belongsToThroughClauses
targetQ.joinClauses = q.joinClauses
targetQ.groupClauses = q.groupClauses
targetQ.havingClauses = q.havingClauses
targetQ.addColumns = q.addColumns
if q.Paginator != nil {
paginator := *q.Paginator
targetQ.Paginator = &paginator
}
if q.Connection != nil {
connection := *q.Connection
targetQ.Connection = &connection
}
} | go | func (q *Query) Clone(targetQ *Query) {
rawSQL := *q.RawSQL
targetQ.RawSQL = &rawSQL
targetQ.limitResults = q.limitResults
targetQ.whereClauses = q.whereClauses
targetQ.orderClauses = q.orderClauses
targetQ.fromClauses = q.fromClauses
targetQ.belongsToThroughClauses = q.belongsToThroughClauses
targetQ.joinClauses = q.joinClauses
targetQ.groupClauses = q.groupClauses
targetQ.havingClauses = q.havingClauses
targetQ.addColumns = q.addColumns
if q.Paginator != nil {
paginator := *q.Paginator
targetQ.Paginator = &paginator
}
if q.Connection != nil {
connection := *q.Connection
targetQ.Connection = &connection
}
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Clone",
"(",
"targetQ",
"*",
"Query",
")",
"{",
"rawSQL",
":=",
"*",
"q",
".",
"RawSQL",
"\n",
"targetQ",
".",
"RawSQL",
"=",
"&",
"rawSQL",
"\n",
"targetQ",
".",
"limitResults",
"=",
"q",
".",
"limitResults",
... | // Clone will fill targetQ query with the connection used in q, if
// targetQ is not empty, Clone will override all the fields. | [
"Clone",
"will",
"fill",
"targetQ",
"query",
"with",
"the",
"connection",
"used",
"in",
"q",
"if",
"targetQ",
"is",
"not",
"empty",
"Clone",
"will",
"override",
"all",
"the",
"fields",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/query.go#L31-L54 | train |
gobuffalo/pop | query.go | disableEager | func (q *Query) disableEager() {
q.Connection.eager, q.eager = false, false
q.Connection.eagerFields, q.eagerFields = []string{}, []string{}
} | go | func (q *Query) disableEager() {
q.Connection.eager, q.eager = false, false
q.Connection.eagerFields, q.eagerFields = []string{}, []string{}
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"disableEager",
"(",
")",
"{",
"q",
".",
"Connection",
".",
"eager",
",",
"q",
".",
"eager",
"=",
"false",
",",
"false",
"\n",
"q",
".",
"Connection",
".",
"eagerFields",
",",
"q",
".",
"eagerFields",
"=",
"[",
... | // disableEager disables eager mode for current query and Connection. | [
"disableEager",
"disables",
"eager",
"mode",
"for",
"current",
"query",
"and",
"Connection",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/query.go#L107-L110 | train |
gobuffalo/pop | query.go | Q | func Q(c *Connection) *Query {
return &Query{
RawSQL: &clause{},
Connection: c,
eager: c.eager,
eagerFields: c.eagerFields,
}
} | go | func Q(c *Connection) *Query {
return &Query{
RawSQL: &clause{},
Connection: c,
eager: c.eager,
eagerFields: c.eagerFields,
}
} | [
"func",
"Q",
"(",
"c",
"*",
"Connection",
")",
"*",
"Query",
"{",
"return",
"&",
"Query",
"{",
"RawSQL",
":",
"&",
"clause",
"{",
"}",
",",
"Connection",
":",
"c",
",",
"eager",
":",
"c",
".",
"eager",
",",
"eagerFields",
":",
"c",
".",
"eagerFie... | // Q will create a new "empty" query from the current connection. | [
"Q",
"will",
"create",
"a",
"new",
"empty",
"query",
"from",
"the",
"current",
"connection",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/query.go#L179-L186 | train |
gobuffalo/pop | query.go | ToSQL | func (q Query) ToSQL(model *Model, addColumns ...string) (string, []interface{}) {
sb := q.toSQLBuilder(model, addColumns...)
return sb.String(), sb.Args()
} | go | func (q Query) ToSQL(model *Model, addColumns ...string) (string, []interface{}) {
sb := q.toSQLBuilder(model, addColumns...)
return sb.String(), sb.Args()
} | [
"func",
"(",
"q",
"Query",
")",
"ToSQL",
"(",
"model",
"*",
"Model",
",",
"addColumns",
"...",
"string",
")",
"(",
"string",
",",
"[",
"]",
"interface",
"{",
"}",
")",
"{",
"sb",
":=",
"q",
".",
"toSQLBuilder",
"(",
"model",
",",
"addColumns",
"...... | // ToSQL will generate SQL and the appropriate arguments for that SQL
// from the `Model` passed in. | [
"ToSQL",
"will",
"generate",
"SQL",
"and",
"the",
"appropriate",
"arguments",
"for",
"that",
"SQL",
"from",
"the",
"Model",
"passed",
"in",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/query.go#L190-L193 | train |
gobuffalo/pop | query.go | toSQLBuilder | func (q Query) toSQLBuilder(model *Model, addColumns ...string) *sqlBuilder {
if len(q.addColumns) != 0 {
addColumns = q.addColumns
}
return newSQLBuilder(q, model, addColumns...)
} | go | func (q Query) toSQLBuilder(model *Model, addColumns ...string) *sqlBuilder {
if len(q.addColumns) != 0 {
addColumns = q.addColumns
}
return newSQLBuilder(q, model, addColumns...)
} | [
"func",
"(",
"q",
"Query",
")",
"toSQLBuilder",
"(",
"model",
"*",
"Model",
",",
"addColumns",
"...",
"string",
")",
"*",
"sqlBuilder",
"{",
"if",
"len",
"(",
"q",
".",
"addColumns",
")",
"!=",
"0",
"{",
"addColumns",
"=",
"q",
".",
"addColumns",
"\n... | // ToSQLBuilder returns a new `SQLBuilder` that can be used to generate SQL,
// get arguments, and more. | [
"ToSQLBuilder",
"returns",
"a",
"new",
"SQLBuilder",
"that",
"can",
"be",
"used",
"to",
"generate",
"SQL",
"get",
"arguments",
"and",
"more",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/query.go#L197-L202 | train |
gobuffalo/pop | query_having.go | Having | func (q *Query) Having(condition string, args ...interface{}) *Query {
if q.RawSQL.Fragment != "" {
log(logging.Warn, "Query is setup to use raw SQL")
return q
}
q.havingClauses = append(q.havingClauses, HavingClause{condition, args})
return q
} | go | func (q *Query) Having(condition string, args ...interface{}) *Query {
if q.RawSQL.Fragment != "" {
log(logging.Warn, "Query is setup to use raw SQL")
return q
}
q.havingClauses = append(q.havingClauses, HavingClause{condition, args})
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Having",
"(",
"condition",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"Query",
"{",
"if",
"q",
".",
"RawSQL",
".",
"Fragment",
"!=",
"\"\"",
"{",
"log",
"(",
"logging",
".",
"Warn",
",",
"... | // Having will append a HAVING clause to the query | [
"Having",
"will",
"append",
"a",
"HAVING",
"clause",
"to",
"the",
"query"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/query_having.go#L6-L14 | train |
gobuffalo/pop | slices/map.go | Scan | func (m *Map) Scan(src interface{}) error {
b, ok := src.([]byte)
if !ok {
return errors.New("Scan source was not []byte")
}
err := json.Unmarshal(b, m)
if err != nil {
return errors.WithStack(err)
}
return nil
} | go | func (m *Map) Scan(src interface{}) error {
b, ok := src.([]byte)
if !ok {
return errors.New("Scan source was not []byte")
}
err := json.Unmarshal(b, m)
if err != nil {
return errors.WithStack(err)
}
return nil
} | [
"func",
"(",
"m",
"*",
"Map",
")",
"Scan",
"(",
"src",
"interface",
"{",
"}",
")",
"error",
"{",
"b",
",",
"ok",
":=",
"src",
".",
"(",
"[",
"]",
"byte",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"Scan source was n... | // Scan implements the sql.Scanner interface.
// It allows to read the map from the database value. | [
"Scan",
"implements",
"the",
"sql",
".",
"Scanner",
"interface",
".",
"It",
"allows",
"to",
"read",
"the",
"map",
"from",
"the",
"database",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/map.go#L20-L30 | train |
gobuffalo/pop | slices/map.go | Value | func (m Map) Value() (driver.Value, error) {
b, err := json.Marshal(m)
if err != nil {
return nil, errors.WithStack(err)
}
return string(b), nil
} | go | func (m Map) Value() (driver.Value, error) {
b, err := json.Marshal(m)
if err != nil {
return nil, errors.WithStack(err)
}
return string(b), nil
} | [
"func",
"(",
"m",
"Map",
")",
"Value",
"(",
")",
"(",
"driver",
".",
"Value",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"m",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wit... | // Value implements the driver.Valuer interface.
// It allows to convert the map to a driver.value. | [
"Value",
"implements",
"the",
"driver",
".",
"Valuer",
"interface",
".",
"It",
"allows",
"to",
"convert",
"the",
"map",
"to",
"a",
"driver",
".",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/map.go#L34-L40 | train |
gobuffalo/pop | slices/map.go | UnmarshalJSON | func (m Map) UnmarshalJSON(b []byte) error {
var stuff map[string]interface{}
err := json.Unmarshal(b, &stuff)
if err != nil {
return err
}
for key, value := range stuff {
m[key] = value
}
return nil
} | go | func (m Map) UnmarshalJSON(b []byte) error {
var stuff map[string]interface{}
err := json.Unmarshal(b, &stuff)
if err != nil {
return err
}
for key, value := range stuff {
m[key] = value
}
return nil
} | [
"func",
"(",
"m",
"Map",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"stuff",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"stuff",
")",
"\n",
... | // UnmarshalJSON will unmarshall JSON value into
// the map representation of this value. | [
"UnmarshalJSON",
"will",
"unmarshall",
"JSON",
"value",
"into",
"the",
"map",
"representation",
"of",
"this",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/map.go#L44-L54 | train |
gobuffalo/pop | slices/map.go | UnmarshalText | func (m Map) UnmarshalText(text []byte) error {
err := json.Unmarshal(text, &m)
if err != nil {
return errors.WithStack(err)
}
return nil
} | go | func (m Map) UnmarshalText(text []byte) error {
err := json.Unmarshal(text, &m)
if err != nil {
return errors.WithStack(err)
}
return nil
} | [
"func",
"(",
"m",
"Map",
")",
"UnmarshalText",
"(",
"text",
"[",
"]",
"byte",
")",
"error",
"{",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"text",
",",
"&",
"m",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"WithStack",
"(... | // UnmarshalText will unmarshall text value into
// the map representation of this value. | [
"UnmarshalText",
"will",
"unmarshall",
"text",
"value",
"into",
"the",
"map",
"representation",
"of",
"this",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/map.go#L58-L64 | train |
gobuffalo/pop | model.go | ID | func (m *Model) ID() interface{} {
fbn, err := m.fieldByName("ID")
if err != nil {
return 0
}
if m.PrimaryKeyType() == "UUID" {
return fbn.Interface().(uuid.UUID).String()
}
return fbn.Interface()
} | go | func (m *Model) ID() interface{} {
fbn, err := m.fieldByName("ID")
if err != nil {
return 0
}
if m.PrimaryKeyType() == "UUID" {
return fbn.Interface().(uuid.UUID).String()
}
return fbn.Interface()
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"ID",
"(",
")",
"interface",
"{",
"}",
"{",
"fbn",
",",
"err",
":=",
"m",
".",
"fieldByName",
"(",
"\"ID\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"m",
".",
"Prima... | // ID returns the ID of the Model. All models must have an `ID` field this is
// of type `int`,`int64` or of type `uuid.UUID`. | [
"ID",
"returns",
"the",
"ID",
"of",
"the",
"Model",
".",
"All",
"models",
"must",
"have",
"an",
"ID",
"field",
"this",
"is",
"of",
"type",
"int",
"int64",
"or",
"of",
"type",
"uuid",
".",
"UUID",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/model.go#L33-L42 | train |
gobuffalo/pop | model.go | PrimaryKeyType | func (m *Model) PrimaryKeyType() string {
fbn, err := m.fieldByName("ID")
if err != nil {
return "int"
}
return fbn.Type().Name()
} | go | func (m *Model) PrimaryKeyType() string {
fbn, err := m.fieldByName("ID")
if err != nil {
return "int"
}
return fbn.Type().Name()
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"PrimaryKeyType",
"(",
")",
"string",
"{",
"fbn",
",",
"err",
":=",
"m",
".",
"fieldByName",
"(",
"\"ID\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"int\"",
"\n",
"}",
"\n",
"return",
"fbn",
".",
... | // PrimaryKeyType gives the primary key type of the `Model`. | [
"PrimaryKeyType",
"gives",
"the",
"primary",
"key",
"type",
"of",
"the",
"Model",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/model.go#L45-L51 | train |
gobuffalo/pop | model.go | TableName | func (m *Model) TableName() string {
if s, ok := m.Value.(string); ok {
return s
}
if n, ok := m.Value.(TableNameAble); ok {
return n.TableName()
}
if m.tableName != "" {
return m.tableName
}
t := reflect.TypeOf(m.Value)
name := m.typeName(t)
defer tableMapMu.Unlock()
tableMapMu.Lock()
if tableMap[name] == "" {
m.tableName = nflect.Tableize(name)
tableMap[name] = m.tableName
}
return tableMap[name]
} | go | func (m *Model) TableName() string {
if s, ok := m.Value.(string); ok {
return s
}
if n, ok := m.Value.(TableNameAble); ok {
return n.TableName()
}
if m.tableName != "" {
return m.tableName
}
t := reflect.TypeOf(m.Value)
name := m.typeName(t)
defer tableMapMu.Unlock()
tableMapMu.Lock()
if tableMap[name] == "" {
m.tableName = nflect.Tableize(name)
tableMap[name] = m.tableName
}
return tableMap[name]
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"TableName",
"(",
")",
"string",
"{",
"if",
"s",
",",
"ok",
":=",
"m",
".",
"Value",
".",
"(",
"string",
")",
";",
"ok",
"{",
"return",
"s",
"\n",
"}",
"\n",
"if",
"n",
",",
"ok",
":=",
"m",
".",
"Value"... | // TableName returns the corresponding name of the underlying database table
// for a given `Model`. See also `TableNameAble` to change the default name of the table. | [
"TableName",
"returns",
"the",
"corresponding",
"name",
"of",
"the",
"underlying",
"database",
"table",
"for",
"a",
"given",
"Model",
".",
"See",
"also",
"TableNameAble",
"to",
"change",
"the",
"default",
"name",
"of",
"the",
"table",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/model.go#L63-L86 | train |
gobuffalo/pop | belongs_to.go | BelongsTo | func (q *Query) BelongsTo(model interface{}) *Query {
m := &Model{Value: model}
q.Where(fmt.Sprintf("%s = ?", m.associationName()), m.ID())
return q
} | go | func (q *Query) BelongsTo(model interface{}) *Query {
m := &Model{Value: model}
q.Where(fmt.Sprintf("%s = ?", m.associationName()), m.ID())
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"BelongsTo",
"(",
"model",
"interface",
"{",
"}",
")",
"*",
"Query",
"{",
"m",
":=",
"&",
"Model",
"{",
"Value",
":",
"model",
"}",
"\n",
"q",
".",
"Where",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"%s = ?\"",
",",
... | // BelongsTo adds a "where" clause based on the "ID" of the
// "model" passed into it. | [
"BelongsTo",
"adds",
"a",
"where",
"clause",
"based",
"on",
"the",
"ID",
"of",
"the",
"model",
"passed",
"into",
"it",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/belongs_to.go#L21-L25 | train |
gobuffalo/pop | migration_box.go | NewMigrationBox | func NewMigrationBox(box packd.Walkable, c *Connection) (MigrationBox, error) {
fm := MigrationBox{
Migrator: NewMigrator(c),
Box: box,
}
err := fm.findMigrations()
if err != nil {
return fm, errors.WithStack(err)
}
return fm, nil
} | go | func NewMigrationBox(box packd.Walkable, c *Connection) (MigrationBox, error) {
fm := MigrationBox{
Migrator: NewMigrator(c),
Box: box,
}
err := fm.findMigrations()
if err != nil {
return fm, errors.WithStack(err)
}
return fm, nil
} | [
"func",
"NewMigrationBox",
"(",
"box",
"packd",
".",
"Walkable",
",",
"c",
"*",
"Connection",
")",
"(",
"MigrationBox",
",",
"error",
")",
"{",
"fm",
":=",
"MigrationBox",
"{",
"Migrator",
":",
"NewMigrator",
"(",
"c",
")",
",",
"Box",
":",
"box",
",",... | // NewMigrationBox from a packr.Box and a Connection. | [
"NewMigrationBox",
"from",
"a",
"packr",
".",
"Box",
"and",
"a",
"Connection",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migration_box.go#L19-L31 | train |
gobuffalo/pop | soda/cmd/generate/model.go | Fizz | func (m model) Fizz() string {
s := []string{fmt.Sprintf("create_table(\"%s\") {", m.Name.Tableize())}
for _, a := range m.Attributes {
switch a.Name.String() {
case "created_at", "updated_at":
default:
col := fizz.Column{
Name: a.Name.Underscore().String(),
ColType: fizzColType(a.OriginalType),
Options: map[string]interface{}{},
}
if a.Primary {
col.Options["primary"] = true
}
if a.Nullable {
col.Options["null"] = true
}
s = append(s, "\t"+col.String())
}
}
s = append(s, "}")
return strings.Join(s, "\n")
} | go | func (m model) Fizz() string {
s := []string{fmt.Sprintf("create_table(\"%s\") {", m.Name.Tableize())}
for _, a := range m.Attributes {
switch a.Name.String() {
case "created_at", "updated_at":
default:
col := fizz.Column{
Name: a.Name.Underscore().String(),
ColType: fizzColType(a.OriginalType),
Options: map[string]interface{}{},
}
if a.Primary {
col.Options["primary"] = true
}
if a.Nullable {
col.Options["null"] = true
}
s = append(s, "\t"+col.String())
}
}
s = append(s, "}")
return strings.Join(s, "\n")
} | [
"func",
"(",
"m",
"model",
")",
"Fizz",
"(",
")",
"string",
"{",
"s",
":=",
"[",
"]",
"string",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"create_table(\\\"%s\\\") {\"",
",",
"\\\"",
")",
"}",
"\n",
"\\\"",
"\n",
"m",
".",
"Name",
".",
"Tableize",
"(",
")... | // Fizz generates the create table instructions | [
"Fizz",
"generates",
"the",
"create",
"table",
"instructions"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/soda/cmd/generate/model.go#L186-L208 | train |
gobuffalo/pop | soda/cmd/generate/model.go | GenerateSQLFromFizz | func (m model) GenerateSQLFromFizz(content string, f fizz.Translator) string {
content, err := fizz.AString(content, f)
if err != nil {
return ""
}
return content
} | go | func (m model) GenerateSQLFromFizz(content string, f fizz.Translator) string {
content, err := fizz.AString(content, f)
if err != nil {
return ""
}
return content
} | [
"func",
"(",
"m",
"model",
")",
"GenerateSQLFromFizz",
"(",
"content",
"string",
",",
"f",
"fizz",
".",
"Translator",
")",
"string",
"{",
"content",
",",
"err",
":=",
"fizz",
".",
"AString",
"(",
"content",
",",
"f",
")",
"\n",
"if",
"err",
"!=",
"ni... | // GenerateSQLFromFizz generates SQL instructions from fizz instructions | [
"GenerateSQLFromFizz",
"generates",
"SQL",
"instructions",
"from",
"fizz",
"instructions"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/soda/cmd/generate/model.go#L216-L222 | train |
gobuffalo/pop | nulls/nulls.go | Parse | func (nulls *Nulls) Parse(value interface{}) interface{} {
switch nulls.Value.(type) {
case Int:
return NewInt(value.(int))
case Int64:
return NewInt64(value.(int64))
case UUID:
return NewUUID(value.(uuid.UUID))
default:
return value
}
} | go | func (nulls *Nulls) Parse(value interface{}) interface{} {
switch nulls.Value.(type) {
case Int:
return NewInt(value.(int))
case Int64:
return NewInt64(value.(int64))
case UUID:
return NewUUID(value.(uuid.UUID))
default:
return value
}
} | [
"func",
"(",
"nulls",
"*",
"Nulls",
")",
"Parse",
"(",
"value",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"switch",
"nulls",
".",
"Value",
".",
"(",
"type",
")",
"{",
"case",
"Int",
":",
"return",
"NewInt",
"(",
"value",
".",
"(",
"... | // Parse parses the specified value to the corresponding
// nullable type. value is one of the inner value hold
// by a nullable type. i.e int, string, uuid.UUID etc. | [
"Parse",
"parses",
"the",
"specified",
"value",
"to",
"the",
"corresponding",
"nullable",
"type",
".",
"value",
"is",
"one",
"of",
"the",
"inner",
"value",
"hold",
"by",
"a",
"nullable",
"type",
".",
"i",
".",
"e",
"int",
"string",
"uuid",
".",
"UUID",
... | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/nulls/nulls.go#L31-L42 | train |
gobuffalo/pop | nulls/nulls.go | New | func New(i interface{}) *Nulls {
if _, ok := i.(nullable); !ok {
return nil
}
return &Nulls{Value: i}
} | go | func New(i interface{}) *Nulls {
if _, ok := i.(nullable); !ok {
return nil
}
return &Nulls{Value: i}
} | [
"func",
"New",
"(",
"i",
"interface",
"{",
"}",
")",
"*",
"Nulls",
"{",
"if",
"_",
",",
"ok",
":=",
"i",
".",
"(",
"nullable",
")",
";",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"Nulls",
"{",
"Value",
":",
"i",
"}",
... | // New returns a wrapper called nulls for the
// interface passed as a param. | [
"New",
"returns",
"a",
"wrapper",
"called",
"nulls",
"for",
"the",
"interface",
"passed",
"as",
"a",
"param",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/nulls/nulls.go#L46-L51 | train |
gobuffalo/pop | slices/float.go | Scan | func (f *Float) Scan(src interface{}) error {
b, ok := src.([]byte)
if !ok {
return errors.New("Scan source was not []byte")
}
str := string(b)
*f = strToFloat(str)
return nil
} | go | func (f *Float) Scan(src interface{}) error {
b, ok := src.([]byte)
if !ok {
return errors.New("Scan source was not []byte")
}
str := string(b)
*f = strToFloat(str)
return nil
} | [
"func",
"(",
"f",
"*",
"Float",
")",
"Scan",
"(",
"src",
"interface",
"{",
"}",
")",
"error",
"{",
"b",
",",
"ok",
":=",
"src",
".",
"(",
"[",
"]",
"byte",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"Scan source was... | // Scan implements the sql.Scanner interface.
// It allows to read the float slice from the database value. | [
"Scan",
"implements",
"the",
"sql",
".",
"Scanner",
"interface",
".",
"It",
"allows",
"to",
"read",
"the",
"float",
"slice",
"from",
"the",
"database",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/float.go#L22-L30 | train |
gobuffalo/pop | slices/float.go | Value | func (f Float) Value() (driver.Value, error) {
sa := make([]string, len(f))
for x, i := range f {
sa[x] = strconv.FormatFloat(i, 'f', -1, 64)
}
return fmt.Sprintf("{%s}", strings.Join(sa, ",")), nil
} | go | func (f Float) Value() (driver.Value, error) {
sa := make([]string, len(f))
for x, i := range f {
sa[x] = strconv.FormatFloat(i, 'f', -1, 64)
}
return fmt.Sprintf("{%s}", strings.Join(sa, ",")), nil
} | [
"func",
"(",
"f",
"Float",
")",
"Value",
"(",
")",
"(",
"driver",
".",
"Value",
",",
"error",
")",
"{",
"sa",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"f",
")",
")",
"\n",
"for",
"x",
",",
"i",
":=",
"range",
"f",
"{",
"sa",
... | // Value implements the driver.Valuer interface.
// It allows to convert the float slice to a driver.value. | [
"Value",
"implements",
"the",
"driver",
".",
"Valuer",
"interface",
".",
"It",
"allows",
"to",
"convert",
"the",
"float",
"slice",
"to",
"a",
"driver",
".",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/float.go#L34-L40 | train |
gobuffalo/pop | slices/float.go | UnmarshalText | func (f *Float) UnmarshalText(text []byte) error {
var ss []float64
for _, x := range strings.Split(string(text), ",") {
f, err := strconv.ParseFloat(x, 64)
if err != nil {
return errors.WithStack(err)
}
ss = append(ss, f)
}
*f = ss
return nil
} | go | func (f *Float) UnmarshalText(text []byte) error {
var ss []float64
for _, x := range strings.Split(string(text), ",") {
f, err := strconv.ParseFloat(x, 64)
if err != nil {
return errors.WithStack(err)
}
ss = append(ss, f)
}
*f = ss
return nil
} | [
"func",
"(",
"f",
"*",
"Float",
")",
"UnmarshalText",
"(",
"text",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ss",
"[",
"]",
"float64",
"\n",
"for",
"_",
",",
"x",
":=",
"range",
"strings",
".",
"Split",
"(",
"string",
"(",
"text",
")",
",",
... | // UnmarshalText will unmarshall text value into
// the float slice representation of this value. | [
"UnmarshalText",
"will",
"unmarshall",
"text",
"value",
"into",
"the",
"float",
"slice",
"representation",
"of",
"this",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/float.go#L44-L55 | train |
gobuffalo/pop | file_migrator.go | NewFileMigrator | func NewFileMigrator(path string, c *Connection) (FileMigrator, error) {
fm := FileMigrator{
Migrator: NewMigrator(c),
Path: path,
}
fm.SchemaPath = path
err := fm.findMigrations()
if err != nil {
return fm, errors.WithStack(err)
}
return fm, nil
} | go | func NewFileMigrator(path string, c *Connection) (FileMigrator, error) {
fm := FileMigrator{
Migrator: NewMigrator(c),
Path: path,
}
fm.SchemaPath = path
err := fm.findMigrations()
if err != nil {
return fm, errors.WithStack(err)
}
return fm, nil
} | [
"func",
"NewFileMigrator",
"(",
"path",
"string",
",",
"c",
"*",
"Connection",
")",
"(",
"FileMigrator",
",",
"error",
")",
"{",
"fm",
":=",
"FileMigrator",
"{",
"Migrator",
":",
"NewMigrator",
"(",
"c",
")",
",",
"Path",
":",
"path",
",",
"}",
"\n",
... | // NewFileMigrator for a path and a Connection | [
"NewFileMigrator",
"for",
"a",
"path",
"and",
"a",
"Connection"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/file_migrator.go#L27-L40 | train |
gobuffalo/pop | dialect_postgresql.go | Next | func (s *scanner) Next() (rune, bool) {
if s.i >= len(s.s) {
return 0, false
}
r := s.s[s.i]
s.i++
return r, true
} | go | func (s *scanner) Next() (rune, bool) {
if s.i >= len(s.s) {
return 0, false
}
r := s.s[s.i]
s.i++
return r, true
} | [
"func",
"(",
"s",
"*",
"scanner",
")",
"Next",
"(",
")",
"(",
"rune",
",",
"bool",
")",
"{",
"if",
"s",
".",
"i",
">=",
"len",
"(",
"s",
".",
"s",
")",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"r",
":=",
"s",
".",
"s",
"[",
"s... | // Next returns the next rune.
// It returns 0, false if the end of the text has been reached. | [
"Next",
"returns",
"the",
"next",
"rune",
".",
"It",
"returns",
"0",
"false",
"if",
"the",
"end",
"of",
"the",
"text",
"has",
"been",
"reached",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/dialect_postgresql.go#L291-L298 | train |
gobuffalo/pop | dialect_postgresql.go | SkipSpaces | func (s *scanner) SkipSpaces() (rune, bool) {
r, ok := s.Next()
for unicode.IsSpace(r) && ok {
r, ok = s.Next()
}
return r, ok
} | go | func (s *scanner) SkipSpaces() (rune, bool) {
r, ok := s.Next()
for unicode.IsSpace(r) && ok {
r, ok = s.Next()
}
return r, ok
} | [
"func",
"(",
"s",
"*",
"scanner",
")",
"SkipSpaces",
"(",
")",
"(",
"rune",
",",
"bool",
")",
"{",
"r",
",",
"ok",
":=",
"s",
".",
"Next",
"(",
")",
"\n",
"for",
"unicode",
".",
"IsSpace",
"(",
"r",
")",
"&&",
"ok",
"{",
"r",
",",
"ok",
"="... | // SkipSpaces returns the next non-whitespace rune.
// It returns 0, false if the end of the text has been reached. | [
"SkipSpaces",
"returns",
"the",
"next",
"non",
"-",
"whitespace",
"rune",
".",
"It",
"returns",
"0",
"false",
"if",
"the",
"end",
"of",
"the",
"text",
"has",
"been",
"reached",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/dialect_postgresql.go#L302-L308 | train |
gobuffalo/pop | dialect_postgresql.go | parseOpts | func parseOpts(name string, o values) error {
s := newScanner(name)
for {
var (
keyRunes, valRunes []rune
r rune
ok bool
)
if r, ok = s.SkipSpaces(); !ok {
break
}
// Scan the key
for !unicode.IsSpace(r) && r != '=' {
keyRunes = append(keyRunes, r)
if r, ok = s.Next(); !ok {
break
}
}
// Skip any whitespace if we're not at the = yet
if r != '=' {
r, ok = s.SkipSpaces()
}
// The current character should be =
if r != '=' || !ok {
return fmt.Errorf(`missing "=" after %q in connection info string"`, string(keyRunes))
}
// Skip any whitespace after the =
if r, ok = s.SkipSpaces(); !ok {
// If we reach the end here, the last value is just an empty string as per libpq.
o[string(keyRunes)] = ""
break
}
if r != '\'' {
for !unicode.IsSpace(r) {
if r == '\\' {
if r, ok = s.Next(); !ok {
return fmt.Errorf(`missing character after backslash`)
}
}
valRunes = append(valRunes, r)
if r, ok = s.Next(); !ok {
break
}
}
} else {
quote:
for {
if r, ok = s.Next(); !ok {
return fmt.Errorf(`unterminated quoted string literal in connection string`)
}
switch r {
case '\'':
break quote
case '\\':
r, _ = s.Next()
fallthrough
default:
valRunes = append(valRunes, r)
}
}
}
o[string(keyRunes)] = string(valRunes)
}
return nil
} | go | func parseOpts(name string, o values) error {
s := newScanner(name)
for {
var (
keyRunes, valRunes []rune
r rune
ok bool
)
if r, ok = s.SkipSpaces(); !ok {
break
}
// Scan the key
for !unicode.IsSpace(r) && r != '=' {
keyRunes = append(keyRunes, r)
if r, ok = s.Next(); !ok {
break
}
}
// Skip any whitespace if we're not at the = yet
if r != '=' {
r, ok = s.SkipSpaces()
}
// The current character should be =
if r != '=' || !ok {
return fmt.Errorf(`missing "=" after %q in connection info string"`, string(keyRunes))
}
// Skip any whitespace after the =
if r, ok = s.SkipSpaces(); !ok {
// If we reach the end here, the last value is just an empty string as per libpq.
o[string(keyRunes)] = ""
break
}
if r != '\'' {
for !unicode.IsSpace(r) {
if r == '\\' {
if r, ok = s.Next(); !ok {
return fmt.Errorf(`missing character after backslash`)
}
}
valRunes = append(valRunes, r)
if r, ok = s.Next(); !ok {
break
}
}
} else {
quote:
for {
if r, ok = s.Next(); !ok {
return fmt.Errorf(`unterminated quoted string literal in connection string`)
}
switch r {
case '\'':
break quote
case '\\':
r, _ = s.Next()
fallthrough
default:
valRunes = append(valRunes, r)
}
}
}
o[string(keyRunes)] = string(valRunes)
}
return nil
} | [
"func",
"parseOpts",
"(",
"name",
"string",
",",
"o",
"values",
")",
"error",
"{",
"s",
":=",
"newScanner",
"(",
"name",
")",
"\n",
"for",
"{",
"var",
"(",
"keyRunes",
",",
"valRunes",
"[",
"]",
"rune",
"\n",
"r",
"rune",
"\n",
"ok",
"bool",
"\n",
... | // parseOpts parses the options from name and adds them to the values.
//
// The parsing code is based on conninfo_parse from libpq's fe-connect.c | [
"parseOpts",
"parses",
"the",
"options",
"from",
"name",
"and",
"adds",
"them",
"to",
"the",
"values",
".",
"The",
"parsing",
"code",
"is",
"based",
"on",
"conninfo_parse",
"from",
"libpq",
"s",
"fe",
"-",
"connect",
".",
"c"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/dialect_postgresql.go#L313-L387 | train |
gobuffalo/pop | slices/int.go | Scan | func (i *Int) Scan(src interface{}) error {
b, ok := src.([]byte)
if !ok {
return errors.New("Scan source was not []byte")
}
str := string(b)
*i = strToInt(str)
return nil
} | go | func (i *Int) Scan(src interface{}) error {
b, ok := src.([]byte)
if !ok {
return errors.New("Scan source was not []byte")
}
str := string(b)
*i = strToInt(str)
return nil
} | [
"func",
"(",
"i",
"*",
"Int",
")",
"Scan",
"(",
"src",
"interface",
"{",
"}",
")",
"error",
"{",
"b",
",",
"ok",
":=",
"src",
".",
"(",
"[",
"]",
"byte",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"Scan source was n... | // Scan implements the sql.Scanner interface.
// It allows to read the int slice from the database value. | [
"Scan",
"implements",
"the",
"sql",
".",
"Scanner",
"interface",
".",
"It",
"allows",
"to",
"read",
"the",
"int",
"slice",
"from",
"the",
"database",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/int.go#L22-L30 | train |
gobuffalo/pop | slices/int.go | Value | func (i Int) Value() (driver.Value, error) {
sa := make([]string, len(i))
for x, v := range i {
sa[x] = strconv.Itoa(v)
}
return fmt.Sprintf("{%s}", strings.Join(sa, ",")), nil
} | go | func (i Int) Value() (driver.Value, error) {
sa := make([]string, len(i))
for x, v := range i {
sa[x] = strconv.Itoa(v)
}
return fmt.Sprintf("{%s}", strings.Join(sa, ",")), nil
} | [
"func",
"(",
"i",
"Int",
")",
"Value",
"(",
")",
"(",
"driver",
".",
"Value",
",",
"error",
")",
"{",
"sa",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"i",
")",
")",
"\n",
"for",
"x",
",",
"v",
":=",
"range",
"i",
"{",
"sa",
... | // Value implements the driver.Valuer interface.
// It allows to convert the int slice to a driver.value. | [
"Value",
"implements",
"the",
"driver",
".",
"Valuer",
"interface",
".",
"It",
"allows",
"to",
"convert",
"the",
"int",
"slice",
"to",
"a",
"driver",
".",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/int.go#L34-L40 | train |
gobuffalo/pop | slices/int.go | UnmarshalText | func (i *Int) UnmarshalText(text []byte) error {
var ss []int
for _, x := range strings.Split(string(text), ",") {
f, err := strconv.Atoi(x)
if err != nil {
return errors.WithStack(err)
}
ss = append(ss, f)
}
*i = ss
return nil
} | go | func (i *Int) UnmarshalText(text []byte) error {
var ss []int
for _, x := range strings.Split(string(text), ",") {
f, err := strconv.Atoi(x)
if err != nil {
return errors.WithStack(err)
}
ss = append(ss, f)
}
*i = ss
return nil
} | [
"func",
"(",
"i",
"*",
"Int",
")",
"UnmarshalText",
"(",
"text",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ss",
"[",
"]",
"int",
"\n",
"for",
"_",
",",
"x",
":=",
"range",
"strings",
".",
"Split",
"(",
"string",
"(",
"text",
")",
",",
"\",\"... | // UnmarshalText will unmarshall text value into
// the int slice representation of this value. | [
"UnmarshalText",
"will",
"unmarshall",
"text",
"value",
"into",
"the",
"int",
"slice",
"representation",
"of",
"this",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/int.go#L44-L55 | train |
gobuffalo/pop | columns/columns_for_struct.go | ForStructWithAlias | func ForStructWithAlias(s interface{}, tableName string, tableAlias string) (columns Columns) {
columns = NewColumnsWithAlias(tableName, tableAlias)
defer func() {
if r := recover(); r != nil {
columns = NewColumnsWithAlias(tableName, tableAlias)
columns.Add("*")
}
}()
st := reflect.TypeOf(s)
if st.Kind() == reflect.Ptr {
st = st.Elem()
}
if st.Kind() == reflect.Slice {
st = st.Elem()
if st.Kind() == reflect.Ptr {
st = st.Elem()
}
}
fieldCount := st.NumField()
for i := 0; i < fieldCount; i++ {
field := st.Field(i)
popTags := TagsFor(field)
tag := popTags.Find("db")
if !tag.Ignored() && !tag.Empty() {
col := tag.Value
// add writable or readable.
tag := popTags.Find("rw")
if !tag.Empty() {
col = col + "," + tag.Value
}
cs := columns.Add(col)
// add select clause.
tag = popTags.Find("select")
if !tag.Empty() {
c := cs[0]
c.SetSelectSQL(tag.Value)
}
}
}
return columns
} | go | func ForStructWithAlias(s interface{}, tableName string, tableAlias string) (columns Columns) {
columns = NewColumnsWithAlias(tableName, tableAlias)
defer func() {
if r := recover(); r != nil {
columns = NewColumnsWithAlias(tableName, tableAlias)
columns.Add("*")
}
}()
st := reflect.TypeOf(s)
if st.Kind() == reflect.Ptr {
st = st.Elem()
}
if st.Kind() == reflect.Slice {
st = st.Elem()
if st.Kind() == reflect.Ptr {
st = st.Elem()
}
}
fieldCount := st.NumField()
for i := 0; i < fieldCount; i++ {
field := st.Field(i)
popTags := TagsFor(field)
tag := popTags.Find("db")
if !tag.Ignored() && !tag.Empty() {
col := tag.Value
// add writable or readable.
tag := popTags.Find("rw")
if !tag.Empty() {
col = col + "," + tag.Value
}
cs := columns.Add(col)
// add select clause.
tag = popTags.Find("select")
if !tag.Empty() {
c := cs[0]
c.SetSelectSQL(tag.Value)
}
}
}
return columns
} | [
"func",
"ForStructWithAlias",
"(",
"s",
"interface",
"{",
"}",
",",
"tableName",
"string",
",",
"tableAlias",
"string",
")",
"(",
"columns",
"Columns",
")",
"{",
"columns",
"=",
"NewColumnsWithAlias",
"(",
"tableName",
",",
"tableAlias",
")",
"\n",
"defer",
... | // ForStructWithAlias returns a Columns instance for the struct passed in.
// If the tableAlias is not empty, it will be used. | [
"ForStructWithAlias",
"returns",
"a",
"Columns",
"instance",
"for",
"the",
"struct",
"passed",
"in",
".",
"If",
"the",
"tableAlias",
"is",
"not",
"empty",
"it",
"will",
"be",
"used",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/columns/columns_for_struct.go#L35-L83 | train |
gobuffalo/pop | paginator.go | Paginate | func (p Paginator) Paginate() string {
b, _ := json.Marshal(p)
return string(b)
} | go | func (p Paginator) Paginate() string {
b, _ := json.Marshal(p)
return string(b)
} | [
"func",
"(",
"p",
"Paginator",
")",
"Paginate",
"(",
")",
"string",
"{",
"b",
",",
"_",
":=",
"json",
".",
"Marshal",
"(",
"p",
")",
"\n",
"return",
"string",
"(",
"b",
")",
"\n",
"}"
] | // Paginate implements the paginable interface. | [
"Paginate",
"implements",
"the",
"paginable",
"interface",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/paginator.go#L44-L47 | train |
gobuffalo/pop | paginator.go | NewPaginator | func NewPaginator(page int, perPage int) *Paginator {
if page < 1 {
page = 1
}
if perPage < 1 {
perPage = 20
}
p := &Paginator{Page: page, PerPage: perPage}
p.Offset = (page - 1) * p.PerPage
return p
} | go | func NewPaginator(page int, perPage int) *Paginator {
if page < 1 {
page = 1
}
if perPage < 1 {
perPage = 20
}
p := &Paginator{Page: page, PerPage: perPage}
p.Offset = (page - 1) * p.PerPage
return p
} | [
"func",
"NewPaginator",
"(",
"page",
"int",
",",
"perPage",
"int",
")",
"*",
"Paginator",
"{",
"if",
"page",
"<",
"1",
"{",
"page",
"=",
"1",
"\n",
"}",
"\n",
"if",
"perPage",
"<",
"1",
"{",
"perPage",
"=",
"20",
"\n",
"}",
"\n",
"p",
":=",
"&"... | // NewPaginator returns a new `Paginator` value with the appropriate
// defaults set. | [
"NewPaginator",
"returns",
"a",
"new",
"Paginator",
"value",
"with",
"the",
"appropriate",
"defaults",
"set",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/paginator.go#L55-L65 | train |
gobuffalo/pop | paginator.go | NewPaginatorFromParams | func NewPaginatorFromParams(params PaginationParams) *Paginator {
page := defaults.String(params.Get("page"), "1")
perPage := defaults.String(params.Get("per_page"), strconv.Itoa(PaginatorPerPageDefault))
p, err := strconv.Atoi(page)
if err != nil {
p = 1
}
pp, err := strconv.Atoi(perPage)
if err != nil {
pp = PaginatorPerPageDefault
}
return NewPaginator(p, pp)
} | go | func NewPaginatorFromParams(params PaginationParams) *Paginator {
page := defaults.String(params.Get("page"), "1")
perPage := defaults.String(params.Get("per_page"), strconv.Itoa(PaginatorPerPageDefault))
p, err := strconv.Atoi(page)
if err != nil {
p = 1
}
pp, err := strconv.Atoi(perPage)
if err != nil {
pp = PaginatorPerPageDefault
}
return NewPaginator(p, pp)
} | [
"func",
"NewPaginatorFromParams",
"(",
"params",
"PaginationParams",
")",
"*",
"Paginator",
"{",
"page",
":=",
"defaults",
".",
"String",
"(",
"params",
".",
"Get",
"(",
"\"page\"",
")",
",",
"\"1\"",
")",
"\n",
"perPage",
":=",
"defaults",
".",
"String",
... | // NewPaginatorFromParams takes an interface of type `PaginationParams`,
// the `url.Values` type works great with this interface, and returns
// a new `Paginator` based on the params or `PaginatorPageKey` and
// `PaginatorPerPageKey`. Defaults are `1` for the page and
// PaginatorPerPageDefault for the per page value. | [
"NewPaginatorFromParams",
"takes",
"an",
"interface",
"of",
"type",
"PaginationParams",
"the",
"url",
".",
"Values",
"type",
"works",
"great",
"with",
"this",
"interface",
"and",
"returns",
"a",
"new",
"Paginator",
"based",
"on",
"the",
"params",
"or",
"Paginato... | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/paginator.go#L77-L92 | train |
gobuffalo/pop | fix/anko.go | Anko | func Anko(content string) (string, error) {
bb := &bytes.Buffer{}
lines := strings.Split(content, "\n")
l := len(lines)
fre := regexp.MustCompile(`,\s*func\(t\)\s*{`)
for i := 0; i < l; i++ {
line := lines[i]
tl := strings.TrimSpace(line)
if strings.HasPrefix(tl, "create_table") {
// skip already converted create_table
if fre.MatchString(line) {
// fix create_table
line = fre.ReplaceAllString(line, ") {")
ll := i
lines[i] = line
waitParen := false
for {
if strings.HasPrefix(tl, "})") {
line = "}" + tl[2:]
break
} else if strings.HasPrefix(tl, "}") {
// Now, we have to make sure to match the missing ")"
waitParen = true
} else if waitParen && strings.HasPrefix(tl, ")") {
line = tl[1:]
break
}
i++
if l == i {
return "", fmt.Errorf("unclosed create_table statement line %d", ll+1)
}
line = lines[i]
tl = strings.TrimSpace(line)
}
}
} else if strings.HasPrefix(tl, "raw(") {
// fix raw
line = strings.Replace(line, "raw(", "sql(", -1)
}
lines[i] = line
}
body := strings.Join(lines, "\n")
if _, err := plush.Parse(body); err != nil {
return "", err
}
bb.WriteString(body)
return bb.String(), nil
} | go | func Anko(content string) (string, error) {
bb := &bytes.Buffer{}
lines := strings.Split(content, "\n")
l := len(lines)
fre := regexp.MustCompile(`,\s*func\(t\)\s*{`)
for i := 0; i < l; i++ {
line := lines[i]
tl := strings.TrimSpace(line)
if strings.HasPrefix(tl, "create_table") {
// skip already converted create_table
if fre.MatchString(line) {
// fix create_table
line = fre.ReplaceAllString(line, ") {")
ll := i
lines[i] = line
waitParen := false
for {
if strings.HasPrefix(tl, "})") {
line = "}" + tl[2:]
break
} else if strings.HasPrefix(tl, "}") {
// Now, we have to make sure to match the missing ")"
waitParen = true
} else if waitParen && strings.HasPrefix(tl, ")") {
line = tl[1:]
break
}
i++
if l == i {
return "", fmt.Errorf("unclosed create_table statement line %d", ll+1)
}
line = lines[i]
tl = strings.TrimSpace(line)
}
}
} else if strings.HasPrefix(tl, "raw(") {
// fix raw
line = strings.Replace(line, "raw(", "sql(", -1)
}
lines[i] = line
}
body := strings.Join(lines, "\n")
if _, err := plush.Parse(body); err != nil {
return "", err
}
bb.WriteString(body)
return bb.String(), nil
} | [
"func",
"Anko",
"(",
"content",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"bb",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"lines",
":=",
"strings",
".",
"Split",
"(",
"content",
",",
"\"\\n\"",
")",
"\n",
"\\n",
"\n",
"l",
":... | // Anko converts old anko-form migrations to new plush ones. | [
"Anko",
"converts",
"old",
"anko",
"-",
"form",
"migrations",
"to",
"new",
"plush",
"ones",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/fix/anko.go#L13-L66 | train |
gobuffalo/pop | columns/writeable_columns.go | UpdateString | func (c WriteableColumns) UpdateString() string {
var xs []string
for _, t := range c.Cols {
xs = append(xs, t.UpdateString())
}
sort.Strings(xs)
return strings.Join(xs, ", ")
} | go | func (c WriteableColumns) UpdateString() string {
var xs []string
for _, t := range c.Cols {
xs = append(xs, t.UpdateString())
}
sort.Strings(xs)
return strings.Join(xs, ", ")
} | [
"func",
"(",
"c",
"WriteableColumns",
")",
"UpdateString",
"(",
")",
"string",
"{",
"var",
"xs",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"c",
".",
"Cols",
"{",
"xs",
"=",
"append",
"(",
"xs",
",",
"t",
".",
"UpdateString",
... | // UpdateString returns the SQL column list part of the UPDATE query. | [
"UpdateString",
"returns",
"the",
"SQL",
"column",
"list",
"part",
"of",
"the",
"UPDATE",
"query",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/columns/writeable_columns.go#L14-L21 | train |
gobuffalo/pop | columns/readable_columns.go | SelectString | func (c ReadableColumns) SelectString() string {
var xs []string
for _, t := range c.Cols {
xs = append(xs, t.SelectSQL)
}
sort.Strings(xs)
return strings.Join(xs, ", ")
} | go | func (c ReadableColumns) SelectString() string {
var xs []string
for _, t := range c.Cols {
xs = append(xs, t.SelectSQL)
}
sort.Strings(xs)
return strings.Join(xs, ", ")
} | [
"func",
"(",
"c",
"ReadableColumns",
")",
"SelectString",
"(",
")",
"string",
"{",
"var",
"xs",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"c",
".",
"Cols",
"{",
"xs",
"=",
"append",
"(",
"xs",
",",
"t",
".",
"SelectSQL",
")",... | // SelectString returns the SQL column list part of the SELECT
// query. | [
"SelectString",
"returns",
"the",
"SQL",
"column",
"list",
"part",
"of",
"the",
"SELECT",
"query",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/columns/readable_columns.go#L15-L22 | train |
gobuffalo/pop | connection_details.go | withURL | func (cd *ConnectionDetails) withURL() error {
ul := cd.URL
if cd.Dialect == "" {
if dialectX.MatchString(ul) {
// Guess the dialect from the scheme
dialect := ul[:strings.Index(ul, ":")]
cd.Dialect = normalizeSynonyms(dialect)
} else {
return errors.New("no dialect provided, and could not guess it from URL")
}
} else if !dialectX.MatchString(ul) {
ul = cd.Dialect + "://" + ul
}
if !DialectSupported(cd.Dialect) {
return errors.Errorf("unsupported dialect '%s'", cd.Dialect)
}
// warning message is required to prevent confusion
// even though this behavior was documented.
if cd.Database+cd.Host+cd.Port+cd.User+cd.Password != "" {
log(logging.Warn, "One or more of connection details are specified in database.yml. Override them with values in URL.")
}
if up, ok := urlParser[cd.Dialect]; ok {
return up(cd)
}
// Fallback on generic parsing if no URL parser was found for the dialect.
u, err := url.Parse(ul)
if err != nil {
return errors.Wrapf(err, "couldn't parse %s", ul)
}
cd.Database = strings.TrimPrefix(u.Path, "/")
hp := strings.Split(u.Host, ":")
cd.Host = hp[0]
if len(hp) > 1 {
cd.Port = hp[1]
}
if u.User != nil {
cd.User = u.User.Username()
cd.Password, _ = u.User.Password()
}
cd.RawOptions = u.RawQuery
return nil
} | go | func (cd *ConnectionDetails) withURL() error {
ul := cd.URL
if cd.Dialect == "" {
if dialectX.MatchString(ul) {
// Guess the dialect from the scheme
dialect := ul[:strings.Index(ul, ":")]
cd.Dialect = normalizeSynonyms(dialect)
} else {
return errors.New("no dialect provided, and could not guess it from URL")
}
} else if !dialectX.MatchString(ul) {
ul = cd.Dialect + "://" + ul
}
if !DialectSupported(cd.Dialect) {
return errors.Errorf("unsupported dialect '%s'", cd.Dialect)
}
// warning message is required to prevent confusion
// even though this behavior was documented.
if cd.Database+cd.Host+cd.Port+cd.User+cd.Password != "" {
log(logging.Warn, "One or more of connection details are specified in database.yml. Override them with values in URL.")
}
if up, ok := urlParser[cd.Dialect]; ok {
return up(cd)
}
// Fallback on generic parsing if no URL parser was found for the dialect.
u, err := url.Parse(ul)
if err != nil {
return errors.Wrapf(err, "couldn't parse %s", ul)
}
cd.Database = strings.TrimPrefix(u.Path, "/")
hp := strings.Split(u.Host, ":")
cd.Host = hp[0]
if len(hp) > 1 {
cd.Port = hp[1]
}
if u.User != nil {
cd.User = u.User.Username()
cd.Password, _ = u.User.Password()
}
cd.RawOptions = u.RawQuery
return nil
} | [
"func",
"(",
"cd",
"*",
"ConnectionDetails",
")",
"withURL",
"(",
")",
"error",
"{",
"ul",
":=",
"cd",
".",
"URL",
"\n",
"if",
"cd",
".",
"Dialect",
"==",
"\"\"",
"{",
"if",
"dialectX",
".",
"MatchString",
"(",
"ul",
")",
"{",
"dialect",
":=",
"ul"... | // withURL parses and overrides all connection details with values
// from standard URL except Dialect. It also calls dialect specific
// URL parser if exists. | [
"withURL",
"parses",
"and",
"overrides",
"all",
"connection",
"details",
"with",
"values",
"from",
"standard",
"URL",
"except",
"Dialect",
".",
"It",
"also",
"calls",
"dialect",
"specific",
"URL",
"parser",
"if",
"exists",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/connection_details.go#L52-L100 | train |
gobuffalo/pop | connection_details.go | Finalize | func (cd *ConnectionDetails) Finalize() error {
cd.Dialect = normalizeSynonyms(cd.Dialect)
if cd.Options == nil { // for safety
cd.Options = make(map[string]string)
}
// Process the database connection string, if provided.
if cd.URL != "" {
if err := cd.withURL(); err != nil {
return err
}
}
if fin, ok := finalizer[cd.Dialect]; ok {
fin(cd)
}
if DialectSupported(cd.Dialect) {
if cd.Database != "" || cd.URL != "" {
return nil
}
return errors.New("no database or URL specified")
}
return errors.Errorf("unsupported dialect '%v'", cd.Dialect)
} | go | func (cd *ConnectionDetails) Finalize() error {
cd.Dialect = normalizeSynonyms(cd.Dialect)
if cd.Options == nil { // for safety
cd.Options = make(map[string]string)
}
// Process the database connection string, if provided.
if cd.URL != "" {
if err := cd.withURL(); err != nil {
return err
}
}
if fin, ok := finalizer[cd.Dialect]; ok {
fin(cd)
}
if DialectSupported(cd.Dialect) {
if cd.Database != "" || cd.URL != "" {
return nil
}
return errors.New("no database or URL specified")
}
return errors.Errorf("unsupported dialect '%v'", cd.Dialect)
} | [
"func",
"(",
"cd",
"*",
"ConnectionDetails",
")",
"Finalize",
"(",
")",
"error",
"{",
"cd",
".",
"Dialect",
"=",
"normalizeSynonyms",
"(",
"cd",
".",
"Dialect",
")",
"\n",
"if",
"cd",
".",
"Options",
"==",
"nil",
"{",
"cd",
".",
"Options",
"=",
"make... | // Finalize cleans up the connection details by normalizing names,
// filling in default values, etc... | [
"Finalize",
"cleans",
"up",
"the",
"connection",
"details",
"by",
"normalizing",
"names",
"filling",
"in",
"default",
"values",
"etc",
"..."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/connection_details.go#L104-L129 | train |
gobuffalo/pop | connection_details.go | RetrySleep | func (cd *ConnectionDetails) RetrySleep() time.Duration {
d, err := time.ParseDuration(defaults.String(cd.Options["retry_sleep"], "1ms"))
if err != nil {
return 1 * time.Millisecond
}
return d
} | go | func (cd *ConnectionDetails) RetrySleep() time.Duration {
d, err := time.ParseDuration(defaults.String(cd.Options["retry_sleep"], "1ms"))
if err != nil {
return 1 * time.Millisecond
}
return d
} | [
"func",
"(",
"cd",
"*",
"ConnectionDetails",
")",
"RetrySleep",
"(",
")",
"time",
".",
"Duration",
"{",
"d",
",",
"err",
":=",
"time",
".",
"ParseDuration",
"(",
"defaults",
".",
"String",
"(",
"cd",
".",
"Options",
"[",
"\"retry_sleep\"",
"]",
",",
"\... | // RetrySleep returns the amount of time to wait between two connection retries | [
"RetrySleep",
"returns",
"the",
"amount",
"of",
"time",
"to",
"wait",
"between",
"two",
"connection",
"retries"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/connection_details.go#L140-L146 | train |
gobuffalo/pop | connection_details.go | RetryLimit | func (cd *ConnectionDetails) RetryLimit() int {
i, err := strconv.Atoi(defaults.String(cd.Options["retry_limit"], "1000"))
if err != nil {
return 100
}
return i
} | go | func (cd *ConnectionDetails) RetryLimit() int {
i, err := strconv.Atoi(defaults.String(cd.Options["retry_limit"], "1000"))
if err != nil {
return 100
}
return i
} | [
"func",
"(",
"cd",
"*",
"ConnectionDetails",
")",
"RetryLimit",
"(",
")",
"int",
"{",
"i",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"defaults",
".",
"String",
"(",
"cd",
".",
"Options",
"[",
"\"retry_limit\"",
"]",
",",
"\"1000\"",
")",
")",
"\... | // RetryLimit returns the maximum number of accepted connection retries | [
"RetryLimit",
"returns",
"the",
"maximum",
"number",
"of",
"accepted",
"connection",
"retries"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/connection_details.go#L149-L155 | train |
gobuffalo/pop | connection_details.go | OptionsString | func (cd *ConnectionDetails) OptionsString(s string) string {
if cd.RawOptions != "" {
return cd.RawOptions
}
if cd.Options != nil {
for k, v := range cd.Options {
s = fmt.Sprintf("%s&%s=%s", s, k, v)
}
}
return strings.TrimLeft(s, "&")
} | go | func (cd *ConnectionDetails) OptionsString(s string) string {
if cd.RawOptions != "" {
return cd.RawOptions
}
if cd.Options != nil {
for k, v := range cd.Options {
s = fmt.Sprintf("%s&%s=%s", s, k, v)
}
}
return strings.TrimLeft(s, "&")
} | [
"func",
"(",
"cd",
"*",
"ConnectionDetails",
")",
"OptionsString",
"(",
"s",
"string",
")",
"string",
"{",
"if",
"cd",
".",
"RawOptions",
"!=",
"\"\"",
"{",
"return",
"cd",
".",
"RawOptions",
"\n",
"}",
"\n",
"if",
"cd",
".",
"Options",
"!=",
"nil",
... | // OptionsString returns URL parameter encoded string from options. | [
"OptionsString",
"returns",
"URL",
"parameter",
"encoded",
"string",
"from",
"options",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/connection_details.go#L163-L173 | train |
gobuffalo/pop | commands.go | DropDB | func DropDB(c *Connection) error {
deets := c.Dialect.Details()
if deets.Database != "" {
log(logging.Info, fmt.Sprintf("drop %s (%s)", deets.Database, c.URL()))
return errors.Wrapf(c.Dialect.DropDB(), "couldn't drop database %s", deets.Database)
}
return nil
} | go | func DropDB(c *Connection) error {
deets := c.Dialect.Details()
if deets.Database != "" {
log(logging.Info, fmt.Sprintf("drop %s (%s)", deets.Database, c.URL()))
return errors.Wrapf(c.Dialect.DropDB(), "couldn't drop database %s", deets.Database)
}
return nil
} | [
"func",
"DropDB",
"(",
"c",
"*",
"Connection",
")",
"error",
"{",
"deets",
":=",
"c",
".",
"Dialect",
".",
"Details",
"(",
")",
"\n",
"if",
"deets",
".",
"Database",
"!=",
"\"\"",
"{",
"log",
"(",
"logging",
".",
"Info",
",",
"fmt",
".",
"Sprintf",... | // DropDB drops an existing database, given a connection definition | [
"DropDB",
"drops",
"an",
"existing",
"database",
"given",
"a",
"connection",
"definition"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/commands.go#L21-L28 | train |
gobuffalo/pop | columns/columns.go | Add | func (c *Columns) Add(names ...string) []*Column {
var ret []*Column
c.lock.Lock()
tableAlias := c.TableAlias
if tableAlias == "" {
tableAlias = c.TableName
}
for _, name := range names {
var xs []string
var col *Column
ss := ""
//support for distinct xx, or distinct on (field) table.fields
if strings.HasSuffix(name, ",r") || strings.HasSuffix(name, ",w") {
xs = []string{name[0 : len(name)-2], name[len(name)-1:]}
} else {
xs = []string{name}
}
xs[0] = strings.TrimSpace(xs[0])
//eg: id id2 - select id as id2
// also distinct columnname
// and distinct on (column1) column2
if strings.Contains(strings.ToUpper(xs[0]), " AS ") {
//eg: select id as id2
i := strings.LastIndex(strings.ToUpper(xs[0]), " AS ")
ss = xs[0]
xs[0] = xs[0][i+4 : len(xs[0])] //get id2
} else if strings.Contains(xs[0], " ") {
i := strings.LastIndex(name, " ")
ss = xs[0]
xs[0] = xs[0][i+1 : len(xs[0])] //get id2
}
col = c.Cols[xs[0]]
if col == nil {
if ss == "" {
ss = xs[0]
if tableAlias != "" {
ss = fmt.Sprintf("%s.%s", tableAlias, ss)
}
}
col = &Column{
Name: xs[0],
SelectSQL: ss,
Readable: true,
Writeable: true,
}
if len(xs) > 1 {
if xs[1] == "r" {
col.Writeable = false
} else if xs[1] == "w" {
col.Readable = false
}
} else if col.Name == "id" {
col.Writeable = false
}
c.Cols[col.Name] = col
}
ret = append(ret, col)
}
c.lock.Unlock()
return ret
} | go | func (c *Columns) Add(names ...string) []*Column {
var ret []*Column
c.lock.Lock()
tableAlias := c.TableAlias
if tableAlias == "" {
tableAlias = c.TableName
}
for _, name := range names {
var xs []string
var col *Column
ss := ""
//support for distinct xx, or distinct on (field) table.fields
if strings.HasSuffix(name, ",r") || strings.HasSuffix(name, ",w") {
xs = []string{name[0 : len(name)-2], name[len(name)-1:]}
} else {
xs = []string{name}
}
xs[0] = strings.TrimSpace(xs[0])
//eg: id id2 - select id as id2
// also distinct columnname
// and distinct on (column1) column2
if strings.Contains(strings.ToUpper(xs[0]), " AS ") {
//eg: select id as id2
i := strings.LastIndex(strings.ToUpper(xs[0]), " AS ")
ss = xs[0]
xs[0] = xs[0][i+4 : len(xs[0])] //get id2
} else if strings.Contains(xs[0], " ") {
i := strings.LastIndex(name, " ")
ss = xs[0]
xs[0] = xs[0][i+1 : len(xs[0])] //get id2
}
col = c.Cols[xs[0]]
if col == nil {
if ss == "" {
ss = xs[0]
if tableAlias != "" {
ss = fmt.Sprintf("%s.%s", tableAlias, ss)
}
}
col = &Column{
Name: xs[0],
SelectSQL: ss,
Readable: true,
Writeable: true,
}
if len(xs) > 1 {
if xs[1] == "r" {
col.Writeable = false
} else if xs[1] == "w" {
col.Readable = false
}
} else if col.Name == "id" {
col.Writeable = false
}
c.Cols[col.Name] = col
}
ret = append(ret, col)
}
c.lock.Unlock()
return ret
} | [
"func",
"(",
"c",
"*",
"Columns",
")",
"Add",
"(",
"names",
"...",
"string",
")",
"[",
"]",
"*",
"Column",
"{",
"var",
"ret",
"[",
"]",
"*",
"Column",
"\n",
"c",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"tableAlias",
":=",
"c",
".",
"TableAlia... | // Add a column to the list. | [
"Add",
"a",
"column",
"to",
"the",
"list",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/columns/columns.go#L19-L88 | train |
gobuffalo/pop | columns/columns.go | Remove | func (c *Columns) Remove(names ...string) {
for _, name := range names {
xs := strings.Split(name, ",")
name = xs[0]
delete(c.Cols, name)
}
} | go | func (c *Columns) Remove(names ...string) {
for _, name := range names {
xs := strings.Split(name, ",")
name = xs[0]
delete(c.Cols, name)
}
} | [
"func",
"(",
"c",
"*",
"Columns",
")",
"Remove",
"(",
"names",
"...",
"string",
")",
"{",
"for",
"_",
",",
"name",
":=",
"range",
"names",
"{",
"xs",
":=",
"strings",
".",
"Split",
"(",
"name",
",",
"\",\"",
")",
"\n",
"name",
"=",
"xs",
"[",
"... | // Remove a column from the list. | [
"Remove",
"a",
"column",
"from",
"the",
"list",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/columns/columns.go#L91-L97 | train |
gobuffalo/pop | columns/columns.go | Writeable | func (c Columns) Writeable() *WriteableColumns {
w := &WriteableColumns{NewColumnsWithAlias(c.TableName, c.TableAlias)}
for _, col := range c.Cols {
if col.Writeable {
w.Cols[col.Name] = col
}
}
return w
} | go | func (c Columns) Writeable() *WriteableColumns {
w := &WriteableColumns{NewColumnsWithAlias(c.TableName, c.TableAlias)}
for _, col := range c.Cols {
if col.Writeable {
w.Cols[col.Name] = col
}
}
return w
} | [
"func",
"(",
"c",
"Columns",
")",
"Writeable",
"(",
")",
"*",
"WriteableColumns",
"{",
"w",
":=",
"&",
"WriteableColumns",
"{",
"NewColumnsWithAlias",
"(",
"c",
".",
"TableName",
",",
"c",
".",
"TableAlias",
")",
"}",
"\n",
"for",
"_",
",",
"col",
":="... | // Writeable gets a list of the writeable columns from the column list. | [
"Writeable",
"gets",
"a",
"list",
"of",
"the",
"writeable",
"columns",
"from",
"the",
"column",
"list",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/columns/columns.go#L100-L108 | train |
gobuffalo/pop | columns/columns.go | Readable | func (c Columns) Readable() *ReadableColumns {
w := &ReadableColumns{NewColumnsWithAlias(c.TableName, c.TableAlias)}
for _, col := range c.Cols {
if col.Readable {
w.Cols[col.Name] = col
}
}
return w
} | go | func (c Columns) Readable() *ReadableColumns {
w := &ReadableColumns{NewColumnsWithAlias(c.TableName, c.TableAlias)}
for _, col := range c.Cols {
if col.Readable {
w.Cols[col.Name] = col
}
}
return w
} | [
"func",
"(",
"c",
"Columns",
")",
"Readable",
"(",
")",
"*",
"ReadableColumns",
"{",
"w",
":=",
"&",
"ReadableColumns",
"{",
"NewColumnsWithAlias",
"(",
"c",
".",
"TableName",
",",
"c",
".",
"TableAlias",
")",
"}",
"\n",
"for",
"_",
",",
"col",
":=",
... | // Readable gets a list of the readable columns from the column list. | [
"Readable",
"gets",
"a",
"list",
"of",
"the",
"readable",
"columns",
"from",
"the",
"column",
"list",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/columns/columns.go#L111-L119 | train |
gobuffalo/pop | columns/columns.go | NewColumnsWithAlias | func NewColumnsWithAlias(tableName string, tableAlias string) Columns {
return Columns{
lock: &sync.RWMutex{},
Cols: map[string]*Column{},
TableName: tableName,
TableAlias: tableAlias,
}
} | go | func NewColumnsWithAlias(tableName string, tableAlias string) Columns {
return Columns{
lock: &sync.RWMutex{},
Cols: map[string]*Column{},
TableName: tableName,
TableAlias: tableAlias,
}
} | [
"func",
"NewColumnsWithAlias",
"(",
"tableName",
"string",
",",
"tableAlias",
"string",
")",
"Columns",
"{",
"return",
"Columns",
"{",
"lock",
":",
"&",
"sync",
".",
"RWMutex",
"{",
"}",
",",
"Cols",
":",
"map",
"[",
"string",
"]",
"*",
"Column",
"{",
... | // NewColumnsWithAlias constructs a list of columns for a given table
// name, using a given alias for the table. | [
"NewColumnsWithAlias",
"constructs",
"a",
"list",
"of",
"columns",
"for",
"a",
"given",
"table",
"name",
"using",
"a",
"given",
"alias",
"for",
"the",
"table",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/columns/columns.go#L148-L155 | train |
gobuffalo/pop | migration_info.go | Run | func (mf Migration) Run(c *Connection) error {
if mf.Runner == nil {
return errors.Errorf("no runner defined for %s", mf.Path)
}
return mf.Runner(mf, c)
} | go | func (mf Migration) Run(c *Connection) error {
if mf.Runner == nil {
return errors.Errorf("no runner defined for %s", mf.Path)
}
return mf.Runner(mf, c)
} | [
"func",
"(",
"mf",
"Migration",
")",
"Run",
"(",
"c",
"*",
"Connection",
")",
"error",
"{",
"if",
"mf",
".",
"Runner",
"==",
"nil",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"no runner defined for %s\"",
",",
"mf",
".",
"Path",
")",
"\n",
"}",
"... | // Run the migration. Returns an error if there is
// no mf.Runner defined. | [
"Run",
"the",
"migration",
".",
"Returns",
"an",
"error",
"if",
"there",
"is",
"no",
"mf",
".",
"Runner",
"defined",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migration_info.go#L25-L30 | train |
gobuffalo/pop | executors.go | Reload | func (c *Connection) Reload(model interface{}) error {
sm := Model{Value: model}
return sm.iterate(func(m *Model) error {
return c.Find(m.Value, m.ID())
})
} | go | func (c *Connection) Reload(model interface{}) error {
sm := Model{Value: model}
return sm.iterate(func(m *Model) error {
return c.Find(m.Value, m.ID())
})
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"Reload",
"(",
"model",
"interface",
"{",
"}",
")",
"error",
"{",
"sm",
":=",
"Model",
"{",
"Value",
":",
"model",
"}",
"\n",
"return",
"sm",
".",
"iterate",
"(",
"func",
"(",
"m",
"*",
"Model",
")",
"err... | // Reload fetch fresh data for a given model, using its ID. | [
"Reload",
"fetch",
"fresh",
"data",
"for",
"a",
"given",
"model",
"using",
"its",
"ID",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/executors.go#L14-L19 | train |
gobuffalo/pop | executors.go | Exec | func (q *Query) Exec() error {
return q.Connection.timeFunc("Exec", func() error {
sql, args := q.ToSQL(nil)
log(logging.SQL, sql, args...)
_, err := q.Connection.Store.Exec(sql, args...)
return err
})
} | go | func (q *Query) Exec() error {
return q.Connection.timeFunc("Exec", func() error {
sql, args := q.ToSQL(nil)
log(logging.SQL, sql, args...)
_, err := q.Connection.Store.Exec(sql, args...)
return err
})
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Exec",
"(",
")",
"error",
"{",
"return",
"q",
".",
"Connection",
".",
"timeFunc",
"(",
"\"Exec\"",
",",
"func",
"(",
")",
"error",
"{",
"sql",
",",
"args",
":=",
"q",
".",
"ToSQL",
"(",
"nil",
")",
"\n",
"l... | // Exec runs the given query. | [
"Exec",
"runs",
"the",
"given",
"query",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/executors.go#L22-L29 | train |
gobuffalo/pop | executors.go | ExecWithCount | func (q *Query) ExecWithCount() (int, error) {
count := int64(0)
return int(count), q.Connection.timeFunc("Exec", func() error {
sql, args := q.ToSQL(nil)
log(logging.SQL, sql, args...)
result, err := q.Connection.Store.Exec(sql, args...)
if err != nil {
return err
}
count, err = result.RowsAffected()
return err
})
} | go | func (q *Query) ExecWithCount() (int, error) {
count := int64(0)
return int(count), q.Connection.timeFunc("Exec", func() error {
sql, args := q.ToSQL(nil)
log(logging.SQL, sql, args...)
result, err := q.Connection.Store.Exec(sql, args...)
if err != nil {
return err
}
count, err = result.RowsAffected()
return err
})
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"ExecWithCount",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"count",
":=",
"int64",
"(",
"0",
")",
"\n",
"return",
"int",
"(",
"count",
")",
",",
"q",
".",
"Connection",
".",
"timeFunc",
"(",
"\"Exec\"",
",... | // ExecWithCount runs the given query, and returns the amount of
// affected rows. | [
"ExecWithCount",
"runs",
"the",
"given",
"query",
"and",
"returns",
"the",
"amount",
"of",
"affected",
"rows",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/executors.go#L33-L46 | train |
gobuffalo/pop | executors.go | ValidateAndSave | func (c *Connection) ValidateAndSave(model interface{}, excludeColumns ...string) (*validate.Errors, error) {
sm := &Model{Value: model}
verrs, err := sm.validateSave(c)
if err != nil {
return verrs, err
}
if verrs.HasAny() {
return verrs, nil
}
return verrs, c.Save(model, excludeColumns...)
} | go | func (c *Connection) ValidateAndSave(model interface{}, excludeColumns ...string) (*validate.Errors, error) {
sm := &Model{Value: model}
verrs, err := sm.validateSave(c)
if err != nil {
return verrs, err
}
if verrs.HasAny() {
return verrs, nil
}
return verrs, c.Save(model, excludeColumns...)
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ValidateAndSave",
"(",
"model",
"interface",
"{",
"}",
",",
"excludeColumns",
"...",
"string",
")",
"(",
"*",
"validate",
".",
"Errors",
",",
"error",
")",
"{",
"sm",
":=",
"&",
"Model",
"{",
"Value",
":",
"... | // ValidateAndSave applies validation rules on the given entry, then save it
// if the validation succeed, excluding the given columns. | [
"ValidateAndSave",
"applies",
"validation",
"rules",
"on",
"the",
"given",
"entry",
"then",
"save",
"it",
"if",
"the",
"validation",
"succeed",
"excluding",
"the",
"given",
"columns",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/executors.go#L50-L60 | train |
gobuffalo/pop | executors.go | IsZeroOfUnderlyingType | func IsZeroOfUnderlyingType(x interface{}) bool {
return reflect.DeepEqual(x, reflect.Zero(reflect.TypeOf(x)).Interface())
} | go | func IsZeroOfUnderlyingType(x interface{}) bool {
return reflect.DeepEqual(x, reflect.Zero(reflect.TypeOf(x)).Interface())
} | [
"func",
"IsZeroOfUnderlyingType",
"(",
"x",
"interface",
"{",
"}",
")",
"bool",
"{",
"return",
"reflect",
".",
"DeepEqual",
"(",
"x",
",",
"reflect",
".",
"Zero",
"(",
"reflect",
".",
"TypeOf",
"(",
"x",
")",
")",
".",
"Interface",
"(",
")",
")",
"\n... | // IsZeroOfUnderlyingType will check if the value of anything is the equal to the Zero value of that type. | [
"IsZeroOfUnderlyingType",
"will",
"check",
"if",
"the",
"value",
"of",
"anything",
"is",
"the",
"equal",
"to",
"the",
"Zero",
"value",
"of",
"that",
"type",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/executors.go#L65-L67 | train |
gobuffalo/pop | executors.go | Save | func (c *Connection) Save(model interface{}, excludeColumns ...string) error {
sm := &Model{Value: model}
return sm.iterate(func(m *Model) error {
id, err := m.fieldByName("ID")
if err != nil {
return err
}
if IsZeroOfUnderlyingType(id.Interface()) {
return c.Create(m.Value, excludeColumns...)
}
return c.Update(m.Value, excludeColumns...)
})
} | go | func (c *Connection) Save(model interface{}, excludeColumns ...string) error {
sm := &Model{Value: model}
return sm.iterate(func(m *Model) error {
id, err := m.fieldByName("ID")
if err != nil {
return err
}
if IsZeroOfUnderlyingType(id.Interface()) {
return c.Create(m.Value, excludeColumns...)
}
return c.Update(m.Value, excludeColumns...)
})
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"Save",
"(",
"model",
"interface",
"{",
"}",
",",
"excludeColumns",
"...",
"string",
")",
"error",
"{",
"sm",
":=",
"&",
"Model",
"{",
"Value",
":",
"model",
"}",
"\n",
"return",
"sm",
".",
"iterate",
"(",
... | // Save wraps the Create and Update methods. It executes a Create if no ID is provided with the entry;
// or issues an Update otherwise. | [
"Save",
"wraps",
"the",
"Create",
"and",
"Update",
"methods",
".",
"It",
"executes",
"a",
"Create",
"if",
"no",
"ID",
"is",
"provided",
"with",
"the",
"entry",
";",
"or",
"issues",
"an",
"Update",
"otherwise",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/executors.go#L71-L83 | train |
gobuffalo/pop | executors.go | ValidateAndCreate | func (c *Connection) ValidateAndCreate(model interface{}, excludeColumns ...string) (*validate.Errors, error) {
sm := &Model{Value: model}
verrs, err := sm.validateCreate(c)
if err != nil {
return verrs, err
}
if verrs.HasAny() {
return verrs, nil
}
if c.eager {
asos, err2 := associations.ForStruct(model, c.eagerFields...)
if err2 != nil {
return verrs, err2
}
if len(asos) == 0 {
c.disableEager()
return verrs, c.Create(model, excludeColumns...)
}
before := asos.AssociationsBeforeCreatable()
for index := range before {
i := before[index].BeforeInterface()
if i == nil {
continue
}
sm := &Model{Value: i}
verrs, err := sm.validateAndOnlyCreate(c)
if err != nil || verrs.HasAny() {
return verrs, err
}
}
after := asos.AssociationsAfterCreatable()
for index := range after {
i := after[index].AfterInterface()
if i == nil {
continue
}
sm := &Model{Value: i}
verrs, err := sm.validateAndOnlyCreate(c)
if err != nil || verrs.HasAny() {
return verrs, err
}
}
sm := &Model{Value: model}
verrs, err = sm.validateCreate(c)
if err != nil || verrs.HasAny() {
return verrs, err
}
}
return verrs, c.Create(model, excludeColumns...)
} | go | func (c *Connection) ValidateAndCreate(model interface{}, excludeColumns ...string) (*validate.Errors, error) {
sm := &Model{Value: model}
verrs, err := sm.validateCreate(c)
if err != nil {
return verrs, err
}
if verrs.HasAny() {
return verrs, nil
}
if c.eager {
asos, err2 := associations.ForStruct(model, c.eagerFields...)
if err2 != nil {
return verrs, err2
}
if len(asos) == 0 {
c.disableEager()
return verrs, c.Create(model, excludeColumns...)
}
before := asos.AssociationsBeforeCreatable()
for index := range before {
i := before[index].BeforeInterface()
if i == nil {
continue
}
sm := &Model{Value: i}
verrs, err := sm.validateAndOnlyCreate(c)
if err != nil || verrs.HasAny() {
return verrs, err
}
}
after := asos.AssociationsAfterCreatable()
for index := range after {
i := after[index].AfterInterface()
if i == nil {
continue
}
sm := &Model{Value: i}
verrs, err := sm.validateAndOnlyCreate(c)
if err != nil || verrs.HasAny() {
return verrs, err
}
}
sm := &Model{Value: model}
verrs, err = sm.validateCreate(c)
if err != nil || verrs.HasAny() {
return verrs, err
}
}
return verrs, c.Create(model, excludeColumns...)
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ValidateAndCreate",
"(",
"model",
"interface",
"{",
"}",
",",
"excludeColumns",
"...",
"string",
")",
"(",
"*",
"validate",
".",
"Errors",
",",
"error",
")",
"{",
"sm",
":=",
"&",
"Model",
"{",
"Value",
":",
... | // ValidateAndCreate applies validation rules on the given entry, then creates it
// if the validation succeed, excluding the given columns. | [
"ValidateAndCreate",
"applies",
"validation",
"rules",
"on",
"the",
"given",
"entry",
"then",
"creates",
"it",
"if",
"the",
"validation",
"succeed",
"excluding",
"the",
"given",
"columns",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/executors.go#L87-L145 | train |
gobuffalo/pop | executors.go | ValidateAndUpdate | func (c *Connection) ValidateAndUpdate(model interface{}, excludeColumns ...string) (*validate.Errors, error) {
sm := &Model{Value: model}
verrs, err := sm.validateUpdate(c)
if err != nil {
return verrs, err
}
if verrs.HasAny() {
return verrs, nil
}
return verrs, c.Update(model, excludeColumns...)
} | go | func (c *Connection) ValidateAndUpdate(model interface{}, excludeColumns ...string) (*validate.Errors, error) {
sm := &Model{Value: model}
verrs, err := sm.validateUpdate(c)
if err != nil {
return verrs, err
}
if verrs.HasAny() {
return verrs, nil
}
return verrs, c.Update(model, excludeColumns...)
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ValidateAndUpdate",
"(",
"model",
"interface",
"{",
"}",
",",
"excludeColumns",
"...",
"string",
")",
"(",
"*",
"validate",
".",
"Errors",
",",
"error",
")",
"{",
"sm",
":=",
"&",
"Model",
"{",
"Value",
":",
... | // ValidateAndUpdate applies validation rules on the given entry, then update it
// if the validation succeed, excluding the given columns. | [
"ValidateAndUpdate",
"applies",
"validation",
"rules",
"on",
"the",
"given",
"entry",
"then",
"update",
"it",
"if",
"the",
"validation",
"succeed",
"excluding",
"the",
"given",
"columns",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/executors.go#L303-L313 | train |
gobuffalo/pop | executors.go | Update | func (c *Connection) Update(model interface{}, excludeColumns ...string) error {
sm := &Model{Value: model}
return sm.iterate(func(m *Model) error {
return c.timeFunc("Update", func() error {
var err error
if err = m.beforeSave(c); err != nil {
return err
}
if err = m.beforeUpdate(c); err != nil {
return err
}
tn := m.TableName()
cols := columns.ForStructWithAlias(model, tn, m.As)
cols.Remove("id", "created_at")
if tn == sm.TableName() {
cols.Remove(excludeColumns...)
}
m.touchUpdatedAt()
if err = c.Dialect.Update(c.Store, m, cols); err != nil {
return err
}
if err = m.afterUpdate(c); err != nil {
return err
}
return m.afterSave(c)
})
})
} | go | func (c *Connection) Update(model interface{}, excludeColumns ...string) error {
sm := &Model{Value: model}
return sm.iterate(func(m *Model) error {
return c.timeFunc("Update", func() error {
var err error
if err = m.beforeSave(c); err != nil {
return err
}
if err = m.beforeUpdate(c); err != nil {
return err
}
tn := m.TableName()
cols := columns.ForStructWithAlias(model, tn, m.As)
cols.Remove("id", "created_at")
if tn == sm.TableName() {
cols.Remove(excludeColumns...)
}
m.touchUpdatedAt()
if err = c.Dialect.Update(c.Store, m, cols); err != nil {
return err
}
if err = m.afterUpdate(c); err != nil {
return err
}
return m.afterSave(c)
})
})
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"Update",
"(",
"model",
"interface",
"{",
"}",
",",
"excludeColumns",
"...",
"string",
")",
"error",
"{",
"sm",
":=",
"&",
"Model",
"{",
"Value",
":",
"model",
"}",
"\n",
"return",
"sm",
".",
"iterate",
"(",
... | // Update writes changes from an entry to the database, excluding the given columns.
// It updates the `updated_at` column automatically. | [
"Update",
"writes",
"changes",
"from",
"an",
"entry",
"to",
"the",
"database",
"excluding",
"the",
"given",
"columns",
".",
"It",
"updates",
"the",
"updated_at",
"column",
"automatically",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/executors.go#L317-L350 | train |
gobuffalo/pop | executors.go | Destroy | func (c *Connection) Destroy(model interface{}) error {
sm := &Model{Value: model}
return sm.iterate(func(m *Model) error {
return c.timeFunc("Destroy", func() error {
var err error
if err = m.beforeDestroy(c); err != nil {
return err
}
if err = c.Dialect.Destroy(c.Store, m); err != nil {
return err
}
return m.afterDestroy(c)
})
})
} | go | func (c *Connection) Destroy(model interface{}) error {
sm := &Model{Value: model}
return sm.iterate(func(m *Model) error {
return c.timeFunc("Destroy", func() error {
var err error
if err = m.beforeDestroy(c); err != nil {
return err
}
if err = c.Dialect.Destroy(c.Store, m); err != nil {
return err
}
return m.afterDestroy(c)
})
})
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"Destroy",
"(",
"model",
"interface",
"{",
"}",
")",
"error",
"{",
"sm",
":=",
"&",
"Model",
"{",
"Value",
":",
"model",
"}",
"\n",
"return",
"sm",
".",
"iterate",
"(",
"func",
"(",
"m",
"*",
"Model",
")"... | // Destroy deletes a given entry from the database | [
"Destroy",
"deletes",
"a",
"given",
"entry",
"from",
"the",
"database"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/executors.go#L353-L369 | train |
gobuffalo/pop | soda/cmd/generate/model_cmd.go | Model | func Model(name string, opts map[string]interface{}, attributes []string) error {
if strings.TrimSpace(name) == "" {
return errors.New("model name can't be empty")
}
mt, found := opts["marshalType"].(string)
if !found {
return errors.New("marshalType option is required")
}
pp, found := opts["modelPath"].(string)
if !found {
return errors.New("modelPath option is required")
}
model, err := newModel(name, mt, pp)
if err != nil {
return errors.WithStack(err)
}
for _, def := range attributes {
a, err := newAttribute(def, &model)
if err != nil {
return err
}
if err := model.addAttribute(a); err != nil {
return err
}
}
// Add a default UUID, if no custom ID is provided
model.addID()
if err := model.generateModelFile(); err != nil {
return err
}
sm, found := opts["skipMigration"].(bool)
if found && sm {
return nil
}
p, found := opts["path"].(string)
if !found {
return errors.New("path option is required")
}
migrationT, found := opts["migrationType"].(string)
if !found {
return errors.New("migrationType option is required")
}
switch migrationT {
case "sql":
env, found := opts["env"].(string)
if !found {
return errors.New("env option is required")
}
err = model.generateSQL(p, env)
default:
err = model.generateFizz(p)
}
return err
} | go | func Model(name string, opts map[string]interface{}, attributes []string) error {
if strings.TrimSpace(name) == "" {
return errors.New("model name can't be empty")
}
mt, found := opts["marshalType"].(string)
if !found {
return errors.New("marshalType option is required")
}
pp, found := opts["modelPath"].(string)
if !found {
return errors.New("modelPath option is required")
}
model, err := newModel(name, mt, pp)
if err != nil {
return errors.WithStack(err)
}
for _, def := range attributes {
a, err := newAttribute(def, &model)
if err != nil {
return err
}
if err := model.addAttribute(a); err != nil {
return err
}
}
// Add a default UUID, if no custom ID is provided
model.addID()
if err := model.generateModelFile(); err != nil {
return err
}
sm, found := opts["skipMigration"].(bool)
if found && sm {
return nil
}
p, found := opts["path"].(string)
if !found {
return errors.New("path option is required")
}
migrationT, found := opts["migrationType"].(string)
if !found {
return errors.New("migrationType option is required")
}
switch migrationT {
case "sql":
env, found := opts["env"].(string)
if !found {
return errors.New("env option is required")
}
err = model.generateSQL(p, env)
default:
err = model.generateFizz(p)
}
return err
} | [
"func",
"Model",
"(",
"name",
"string",
",",
"opts",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"attributes",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"strings",
".",
"TrimSpace",
"(",
"name",
")",
"==",
"\"\"",
"{",
"return",
"errors... | // Model generates new model files to work with pop. | [
"Model",
"generates",
"new",
"model",
"files",
"to",
"work",
"with",
"pop",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/soda/cmd/generate/model_cmd.go#L49-L110 | train |
gobuffalo/pop | genny/config/config.go | New | func New(opts *Options) (*genny.Generator, error) {
g := genny.New()
if err := opts.Validate(); err != nil {
return g, errors.WithStack(err)
}
f, err := templates.Open(opts.Dialect + ".yml.tmpl")
if err != nil {
return g, errors.Errorf("unable to find database.yml template for dialect %s", opts.Dialect)
}
name := filepath.Join(opts.Root, opts.FileName+".tmpl")
gf := genny.NewFile(name, f)
g.File(gf)
data := map[string]interface{}{
"opts": opts,
}
t := gogen.TemplateTransformer(data, gogen.TemplateHelpers)
g.Transformer(t)
g.Transformer(genny.Dot())
return g, nil
} | go | func New(opts *Options) (*genny.Generator, error) {
g := genny.New()
if err := opts.Validate(); err != nil {
return g, errors.WithStack(err)
}
f, err := templates.Open(opts.Dialect + ".yml.tmpl")
if err != nil {
return g, errors.Errorf("unable to find database.yml template for dialect %s", opts.Dialect)
}
name := filepath.Join(opts.Root, opts.FileName+".tmpl")
gf := genny.NewFile(name, f)
g.File(gf)
data := map[string]interface{}{
"opts": opts,
}
t := gogen.TemplateTransformer(data, gogen.TemplateHelpers)
g.Transformer(t)
g.Transformer(genny.Dot())
return g, nil
} | [
"func",
"New",
"(",
"opts",
"*",
"Options",
")",
"(",
"*",
"genny",
".",
"Generator",
",",
"error",
")",
"{",
"g",
":=",
"genny",
".",
"New",
"(",
")",
"\n",
"if",
"err",
":=",
"opts",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
... | // New generator to create a database.yml file | [
"New",
"generator",
"to",
"create",
"a",
"database",
".",
"yml",
"file"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/genny/config/config.go#L15-L39 | train |
gobuffalo/pop | query_groups.go | GroupBy | func (q *Query) GroupBy(field string, fields ...string) *Query {
if q.RawSQL.Fragment != "" {
log(logging.Warn, "Query is setup to use raw SQL")
return q
}
q.groupClauses = append(q.groupClauses, GroupClause{field})
if len(fields) > 0 {
for i := range fields {
q.groupClauses = append(q.groupClauses, GroupClause{fields[i]})
}
}
return q
} | go | func (q *Query) GroupBy(field string, fields ...string) *Query {
if q.RawSQL.Fragment != "" {
log(logging.Warn, "Query is setup to use raw SQL")
return q
}
q.groupClauses = append(q.groupClauses, GroupClause{field})
if len(fields) > 0 {
for i := range fields {
q.groupClauses = append(q.groupClauses, GroupClause{fields[i]})
}
}
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"GroupBy",
"(",
"field",
"string",
",",
"fields",
"...",
"string",
")",
"*",
"Query",
"{",
"if",
"q",
".",
"RawSQL",
".",
"Fragment",
"!=",
"\"\"",
"{",
"log",
"(",
"logging",
".",
"Warn",
",",
"\"Query is setup t... | // GroupBy will append a GROUP BY clause to the query | [
"GroupBy",
"will",
"append",
"a",
"GROUP",
"BY",
"clause",
"to",
"the",
"query"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/query_groups.go#L6-L18 | train |
gobuffalo/pop | associations/has_one_association.go | Constraint | func (h *hasOneAssociation) Constraint() (string, []interface{}) {
return fmt.Sprintf("%s = ?", h.fkID), []interface{}{h.ownerID}
} | go | func (h *hasOneAssociation) Constraint() (string, []interface{}) {
return fmt.Sprintf("%s = ?", h.fkID), []interface{}{h.ownerID}
} | [
"func",
"(",
"h",
"*",
"hasOneAssociation",
")",
"Constraint",
"(",
")",
"(",
"string",
",",
"[",
"]",
"interface",
"{",
"}",
")",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"%s = ?\"",
",",
"h",
".",
"fkID",
")",
",",
"[",
"]",
"interface",
"{",... | // Constraint returns the content for the WHERE clause, and the args
// needed to execute it. | [
"Constraint",
"returns",
"the",
"content",
"for",
"the",
"WHERE",
"clause",
"and",
"the",
"args",
"needed",
"to",
"execute",
"it",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/associations/has_one_association.go#L74-L76 | train |
gobuffalo/pop | associations/has_one_association.go | AfterInterface | func (h *hasOneAssociation) AfterInterface() interface{} {
m := h.ownedModel
if fieldIsNil(m) {
return nil
}
if m.Kind() == reflect.Ptr {
return m.Interface()
}
if IsZeroOfUnderlyingType(m.Interface()) {
return nil
}
return m.Addr().Interface()
} | go | func (h *hasOneAssociation) AfterInterface() interface{} {
m := h.ownedModel
if fieldIsNil(m) {
return nil
}
if m.Kind() == reflect.Ptr {
return m.Interface()
}
if IsZeroOfUnderlyingType(m.Interface()) {
return nil
}
return m.Addr().Interface()
} | [
"func",
"(",
"h",
"*",
"hasOneAssociation",
")",
"AfterInterface",
"(",
")",
"interface",
"{",
"}",
"{",
"m",
":=",
"h",
".",
"ownedModel",
"\n",
"if",
"fieldIsNil",
"(",
"m",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"m",
".",
"Kind",
"(",... | // AfterInterface gets the value of the model to create after
// creating the parent model. It returns nil if its value is
// not set. | [
"AfterInterface",
"gets",
"the",
"value",
"of",
"the",
"model",
"to",
"create",
"after",
"creating",
"the",
"parent",
"model",
".",
"It",
"returns",
"nil",
"if",
"its",
"value",
"is",
"not",
"set",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/associations/has_one_association.go#L103-L116 | train |
gobuffalo/pop | config.go | LoadConfigFile | func LoadConfigFile() error {
path, err := findConfigPath()
if err != nil {
return errors.WithStack(err)
}
Connections = map[string]*Connection{}
log(logging.Debug, "Loading config file from %s", path)
f, err := os.Open(path)
if err != nil {
return errors.WithStack(err)
}
return LoadFrom(f)
} | go | func LoadConfigFile() error {
path, err := findConfigPath()
if err != nil {
return errors.WithStack(err)
}
Connections = map[string]*Connection{}
log(logging.Debug, "Loading config file from %s", path)
f, err := os.Open(path)
if err != nil {
return errors.WithStack(err)
}
return LoadFrom(f)
} | [
"func",
"LoadConfigFile",
"(",
")",
"error",
"{",
"path",
",",
"err",
":=",
"findConfigPath",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n",
"Connections",
"=",
"map",
"[",
"stri... | // LoadConfigFile loads a POP config file from the configured lookup paths | [
"LoadConfigFile",
"loads",
"a",
"POP",
"config",
"file",
"from",
"the",
"configured",
"lookup",
"paths"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/config.go#L40-L52 | train |
gobuffalo/pop | config.go | LoadFrom | func LoadFrom(r io.Reader) error {
envy.Load()
deets, err := ParseConfig(r)
if err != nil {
return err
}
for n, d := range deets {
con, err := NewConnection(d)
if err != nil {
log(logging.Warn, "unable to load connection %s: %v", n, err)
continue
}
Connections[n] = con
}
return nil
} | go | func LoadFrom(r io.Reader) error {
envy.Load()
deets, err := ParseConfig(r)
if err != nil {
return err
}
for n, d := range deets {
con, err := NewConnection(d)
if err != nil {
log(logging.Warn, "unable to load connection %s: %v", n, err)
continue
}
Connections[n] = con
}
return nil
} | [
"func",
"LoadFrom",
"(",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"envy",
".",
"Load",
"(",
")",
"\n",
"deets",
",",
"err",
":=",
"ParseConfig",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"n... | // LoadFrom reads a configuration from the reader and sets up the connections | [
"LoadFrom",
"reads",
"a",
"configuration",
"from",
"the",
"reader",
"and",
"sets",
"up",
"the",
"connections"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/config.go#L76-L91 | train |
gobuffalo/pop | config.go | ParseConfig | func ParseConfig(r io.Reader) (map[string]*ConnectionDetails, error) {
tmpl := template.New("test")
tmpl.Funcs(map[string]interface{}{
"envOr": func(s1, s2 string) string {
return envy.Get(s1, s2)
},
"env": func(s1 string) string {
return envy.Get(s1, "")
},
})
b, err := ioutil.ReadAll(r)
if err != nil {
return nil, errors.WithStack(err)
}
t, err := tmpl.Parse(string(b))
if err != nil {
return nil, errors.Wrap(err, "couldn't parse config template")
}
var bb bytes.Buffer
err = t.Execute(&bb, nil)
if err != nil {
return nil, errors.Wrap(err, "couldn't execute config template")
}
deets := map[string]*ConnectionDetails{}
err = yaml.Unmarshal(bb.Bytes(), &deets)
return deets, errors.Wrap(err, "couldn't unmarshal config to yaml")
} | go | func ParseConfig(r io.Reader) (map[string]*ConnectionDetails, error) {
tmpl := template.New("test")
tmpl.Funcs(map[string]interface{}{
"envOr": func(s1, s2 string) string {
return envy.Get(s1, s2)
},
"env": func(s1 string) string {
return envy.Get(s1, "")
},
})
b, err := ioutil.ReadAll(r)
if err != nil {
return nil, errors.WithStack(err)
}
t, err := tmpl.Parse(string(b))
if err != nil {
return nil, errors.Wrap(err, "couldn't parse config template")
}
var bb bytes.Buffer
err = t.Execute(&bb, nil)
if err != nil {
return nil, errors.Wrap(err, "couldn't execute config template")
}
deets := map[string]*ConnectionDetails{}
err = yaml.Unmarshal(bb.Bytes(), &deets)
return deets, errors.Wrap(err, "couldn't unmarshal config to yaml")
} | [
"func",
"ParseConfig",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"ConnectionDetails",
",",
"error",
")",
"{",
"tmpl",
":=",
"template",
".",
"New",
"(",
"\"test\"",
")",
"\n",
"tmpl",
".",
"Funcs",
"(",
"map",
"[",
"s... | // ParseConfig reads the pop config from the given io.Reader and returns
// the parsed ConnectionDetails map. | [
"ParseConfig",
"reads",
"the",
"pop",
"config",
"from",
"the",
"given",
"io",
".",
"Reader",
"and",
"returns",
"the",
"parsed",
"ConnectionDetails",
"map",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/config.go#L95-L123 | train |
gobuffalo/pop | associations/association.go | AssociationsBeforeCreatable | func (a Associations) AssociationsBeforeCreatable() []AssociationBeforeCreatable {
var before []AssociationBeforeCreatable
for i := range a {
if _, ok := a[i].(AssociationBeforeCreatable); ok {
before = append(before, a[i].(AssociationBeforeCreatable))
}
}
return before
} | go | func (a Associations) AssociationsBeforeCreatable() []AssociationBeforeCreatable {
var before []AssociationBeforeCreatable
for i := range a {
if _, ok := a[i].(AssociationBeforeCreatable); ok {
before = append(before, a[i].(AssociationBeforeCreatable))
}
}
return before
} | [
"func",
"(",
"a",
"Associations",
")",
"AssociationsBeforeCreatable",
"(",
")",
"[",
"]",
"AssociationBeforeCreatable",
"{",
"var",
"before",
"[",
"]",
"AssociationBeforeCreatable",
"\n",
"for",
"i",
":=",
"range",
"a",
"{",
"if",
"_",
",",
"ok",
":=",
"a",
... | // AssociationsBeforeCreatable returns all associations that implement AssociationBeforeCreatable
// interface. Belongs To association is an example of this implementation. | [
"AssociationsBeforeCreatable",
"returns",
"all",
"associations",
"that",
"implement",
"AssociationBeforeCreatable",
"interface",
".",
"Belongs",
"To",
"association",
"is",
"an",
"example",
"of",
"this",
"implementation",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/associations/association.go#L99-L107 | train |
gobuffalo/pop | associations/association.go | AssociationsAfterCreatable | func (a Associations) AssociationsAfterCreatable() []AssociationAfterCreatable {
var after []AssociationAfterCreatable
for i := range a {
if _, ok := a[i].(AssociationAfterCreatable); ok {
after = append(after, a[i].(AssociationAfterCreatable))
}
}
return after
} | go | func (a Associations) AssociationsAfterCreatable() []AssociationAfterCreatable {
var after []AssociationAfterCreatable
for i := range a {
if _, ok := a[i].(AssociationAfterCreatable); ok {
after = append(after, a[i].(AssociationAfterCreatable))
}
}
return after
} | [
"func",
"(",
"a",
"Associations",
")",
"AssociationsAfterCreatable",
"(",
")",
"[",
"]",
"AssociationAfterCreatable",
"{",
"var",
"after",
"[",
"]",
"AssociationAfterCreatable",
"\n",
"for",
"i",
":=",
"range",
"a",
"{",
"if",
"_",
",",
"ok",
":=",
"a",
"[... | // AssociationsAfterCreatable returns all associations that implement AssociationAfterCreatable
// interface. Has Many and Has One associations are examples of this implementation. | [
"AssociationsAfterCreatable",
"returns",
"all",
"associations",
"that",
"implement",
"AssociationAfterCreatable",
"interface",
".",
"Has",
"Many",
"and",
"Has",
"One",
"associations",
"are",
"examples",
"of",
"this",
"implementation",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/associations/association.go#L111-L119 | train |
gobuffalo/pop | associations/association.go | AssociationsCreatableStatement | func (a Associations) AssociationsCreatableStatement() []AssociationCreatableStatement {
var stm []AssociationCreatableStatement
for i := range a {
if _, ok := a[i].(AssociationCreatableStatement); ok {
stm = append(stm, a[i].(AssociationCreatableStatement))
}
}
return stm
} | go | func (a Associations) AssociationsCreatableStatement() []AssociationCreatableStatement {
var stm []AssociationCreatableStatement
for i := range a {
if _, ok := a[i].(AssociationCreatableStatement); ok {
stm = append(stm, a[i].(AssociationCreatableStatement))
}
}
return stm
} | [
"func",
"(",
"a",
"Associations",
")",
"AssociationsCreatableStatement",
"(",
")",
"[",
"]",
"AssociationCreatableStatement",
"{",
"var",
"stm",
"[",
"]",
"AssociationCreatableStatement",
"\n",
"for",
"i",
":=",
"range",
"a",
"{",
"if",
"_",
",",
"ok",
":=",
... | // AssociationsCreatableStatement returns all associations that implement AssociationCreatableStament
// interface. Many To Many association is an example of this implementation. | [
"AssociationsCreatableStatement",
"returns",
"all",
"associations",
"that",
"implement",
"AssociationCreatableStament",
"interface",
".",
"Many",
"To",
"Many",
"association",
"is",
"an",
"example",
"of",
"this",
"implementation",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/associations/association.go#L123-L131 | train |
gobuffalo/pop | associations/association.go | fieldIsNil | func fieldIsNil(f reflect.Value) bool {
if n := nulls.New(f.Interface()); n != nil {
return n.Interface() == nil
}
if f.Kind() == reflect.Interface || f.Kind() == reflect.Ptr {
return f.IsNil()
}
return f.Interface() == nil
} | go | func fieldIsNil(f reflect.Value) bool {
if n := nulls.New(f.Interface()); n != nil {
return n.Interface() == nil
}
if f.Kind() == reflect.Interface || f.Kind() == reflect.Ptr {
return f.IsNil()
}
return f.Interface() == nil
} | [
"func",
"fieldIsNil",
"(",
"f",
"reflect",
".",
"Value",
")",
"bool",
"{",
"if",
"n",
":=",
"nulls",
".",
"New",
"(",
"f",
".",
"Interface",
"(",
")",
")",
";",
"n",
"!=",
"nil",
"{",
"return",
"n",
".",
"Interface",
"(",
")",
"==",
"nil",
"\n"... | // fieldIsNil validates if a field has a nil reference. Also
// it validates if a field implements nullable interface and
// it has a nil value. | [
"fieldIsNil",
"validates",
"if",
"a",
"field",
"has",
"a",
"nil",
"reference",
".",
"Also",
"it",
"validates",
"if",
"a",
"field",
"implements",
"nullable",
"interface",
"and",
"it",
"has",
"a",
"nil",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/associations/association.go#L151-L159 | train |
gobuffalo/pop | connection.go | NewConnection | func NewConnection(deets *ConnectionDetails) (*Connection, error) {
err := deets.Finalize()
if err != nil {
return nil, errors.WithStack(err)
}
c := &Connection{
ID: randx.String(30),
}
if nc, ok := newConnection[deets.Dialect]; ok {
c.Dialect, err = nc(deets)
if err != nil {
return c, errors.Wrap(err, "could not create new connection")
}
return c, nil
}
return nil, errors.Errorf("could not found connection creator for %v", deets.Dialect)
} | go | func NewConnection(deets *ConnectionDetails) (*Connection, error) {
err := deets.Finalize()
if err != nil {
return nil, errors.WithStack(err)
}
c := &Connection{
ID: randx.String(30),
}
if nc, ok := newConnection[deets.Dialect]; ok {
c.Dialect, err = nc(deets)
if err != nil {
return c, errors.Wrap(err, "could not create new connection")
}
return c, nil
}
return nil, errors.Errorf("could not found connection creator for %v", deets.Dialect)
} | [
"func",
"NewConnection",
"(",
"deets",
"*",
"ConnectionDetails",
")",
"(",
"*",
"Connection",
",",
"error",
")",
"{",
"err",
":=",
"deets",
".",
"Finalize",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"WithStack"... | // NewConnection creates a new connection, and sets it's `Dialect`
// appropriately based on the `ConnectionDetails` passed into it. | [
"NewConnection",
"creates",
"a",
"new",
"connection",
"and",
"sets",
"it",
"s",
"Dialect",
"appropriately",
"based",
"on",
"the",
"ConnectionDetails",
"passed",
"into",
"it",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/connection.go#L48-L65 | train |
gobuffalo/pop | connection.go | Connect | func Connect(e string) (*Connection, error) {
if len(Connections) == 0 {
err := LoadConfigFile()
if err != nil {
return nil, errors.WithStack(err)
}
}
e = defaults.String(e, "development")
c := Connections[e]
if c == nil {
return c, errors.Errorf("could not find connection named %s", e)
}
err := c.Open()
return c, errors.Wrapf(err, "couldn't open connection for %s", e)
} | go | func Connect(e string) (*Connection, error) {
if len(Connections) == 0 {
err := LoadConfigFile()
if err != nil {
return nil, errors.WithStack(err)
}
}
e = defaults.String(e, "development")
c := Connections[e]
if c == nil {
return c, errors.Errorf("could not find connection named %s", e)
}
err := c.Open()
return c, errors.Wrapf(err, "couldn't open connection for %s", e)
} | [
"func",
"Connect",
"(",
"e",
"string",
")",
"(",
"*",
"Connection",
",",
"error",
")",
"{",
"if",
"len",
"(",
"Connections",
")",
"==",
"0",
"{",
"err",
":=",
"LoadConfigFile",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
... | // Connect takes the name of a connection, default is "development", and will
// return that connection from the available `Connections`. If a connection with
// that name can not be found an error will be returned. If a connection is
// found, and it has yet to open a connection with its underlying datastore,
// a connection to that store will be opened. | [
"Connect",
"takes",
"the",
"name",
"of",
"a",
"connection",
"default",
"is",
"development",
"and",
"will",
"return",
"that",
"connection",
"from",
"the",
"available",
"Connections",
".",
"If",
"a",
"connection",
"with",
"that",
"name",
"can",
"not",
"be",
"f... | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/connection.go#L72-L86 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.