repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
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 *C... | 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 *C... | [
"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... | 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... | [
"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",
"(",
"\"",
"\"",
",",
"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.joinClau... | 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.joinClau... | [
"func",
"(",
"q",
"*",
"Query",
")",
"Clone",
"(",
"targetQ",
"*",
"Query",
")",
"{",
"rawSQL",
":=",
"*",
"q",
".",
"RawSQL",
"\n",
"targetQ",
".",
"RawSQL",
"=",
"&",
"rawSQL",
"\n\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 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",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"m",
".",
"P... | // 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",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\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[... | 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[... | [
"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",
"(",
"\"",
"\"",
",",
... | // 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),
... | 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),
... | [
"func",
"(",
"m",
"model",
")",
"Fizz",
"(",
")",
"string",
"{",
"s",
":=",
"[",
"]",
"string",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"m",
".",
"Name",
".",
"Tableize",
"(",
")",
")",
"}",
"\n",
"for",
"_",
",",
... | // 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 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 ... | 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 ... | [
"func",
"parseOpts",
"(",
"name",
"string",
",",
"o",
"values",
")",
"error",
"{",
"s",
":=",
"newScanner",
"(",
"name",
")",
"\n\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 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(... | 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(... | [
"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 {
... | 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 {
... | [
"func",
"NewPaginatorFromParams",
"(",
"params",
"PaginationParams",
")",
"*",
"Paginator",
"{",
"page",
":=",
"defaults",
".",
"String",
"(",
"params",
".",
"Get",
"(",
"\"",
"\"",
")",
",",
"\"",
"\"",
")",
"\n\n",
"perPage",
":=",
"defaults",
".",
"St... | // 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 conver... | 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 conver... | [
"func",
"Anko",
"(",
"content",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"bb",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n\n",
"lines",
":=",
"strings",
".",
"Split",
"(",
"content",
",",
"\"",
"\\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 fr... | 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 fr... | [
"func",
"(",
"cd",
"*",
"ConnectionDetails",
")",
"withURL",
"(",
")",
"error",
"{",
"ul",
":=",
"cd",
".",
"URL",
"\n",
"if",
"cd",
".",
"Dialect",
"==",
"\"",
"\"",
"{",
"if",
"dialectX",
".",
"MatchString",
"(",
"ul",
")",
"{",
"// Guess the diale... | // 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, ... | 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, ... | [
"func",
"(",
"cd",
"*",
"ConnectionDetails",
")",
"Finalize",
"(",
")",
"error",
"{",
"cd",
".",
"Dialect",
"=",
"normalizeSynonyms",
"(",
"cd",
".",
"Dialect",
")",
"\n\n",
"if",
"cd",
".",
"Options",
"==",
"nil",
"{",
"// for safety",
"cd",
".",
"Opt... | // 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",
"[",
"\"",
"\"",
"]",
",",
"\"",
... | // 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",
"[",
"\"",
"\"",
"]",
",",
"\"",
"\"",
")",
")",
"\n",... | // 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",
"!=",
"ni... | // 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",
".",
"Spr... | // 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 stri... | 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 stri... | [
"func",
"(",
"c",
"*",
"Columns",
")",
"Add",
"(",
"names",
"...",
"string",
")",
"[",
"]",
"*",
"Column",
"{",
"var",
"ret",
"[",
"]",
"*",
"Column",
"\n",
"c",
".",
"lock",
".",
"Lock",
"(",
")",
"\n\n",
"tableAlias",
":=",
"c",
".",
"TableAl... | // 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",
"(",
"\"",
"\"",
",",
"mf",
".",
"Path",
")",
"\n",
"}",
"\n",
"return",
... | // 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",
"(",
"\"",
"\"",
",",
"func",
"(",
")",
"error",
"{",
"sql",
",",
"args",
":=",
"q",
".",
"ToSQL",
"(",
"nil",
")",
"\n",
... | // 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()... | 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()... | [
"func",
"(",
"q",
"*",
"Query",
")",
"ExecWithCount",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"count",
":=",
"int64",
"(",
"0",
")",
"\n",
"return",
"int",
"(",
"count",
")",
",",
"q",
".",
"Connection",
".",
"timeFunc",
"(",
"\"",
"\"",
... | // 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...)
}
ret... | 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...)
}
ret... | [
"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,... | 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,... | [
"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 {
... | 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 {
... | [
"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 {
retur... | 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 {
retur... | [
"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"].(str... | 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"].(str... | [
"func",
"Model",
"(",
"name",
"string",
",",
"opts",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"attributes",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"strings",
".",
"TrimSpace",
"(",
"name",
")",
"==",
"\"",
"\"",
"{",
"return",
"... | // 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)
}
... | 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)
}
... | [
"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, GroupC... | 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, GroupC... | [
"func",
"(",
"q",
"*",
"Query",
")",
"GroupBy",
"(",
"field",
"string",
",",
"fields",
"...",
"string",
")",
"*",
"Query",
"{",
"if",
"q",
".",
"RawSQL",
".",
"Fragment",
"!=",
"\"",
"\"",
"{",
"log",
"(",
"logging",
".",
"Warn",
",",
"\"",
"\"",... | // 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",
"(",
"\"",
"\"",
",",
"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 != n... | 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 != n... | [
"func",
"ParseConfig",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"ConnectionDetails",
",",
"error",
")",
"{",
"tmpl",
":=",
"template",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"tmpl",
".",
"Funcs",
"(",
"map",
"[",
... | // 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... | 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... | [
"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.Ope... | 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.Ope... | [
"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 con... | [
"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 |
gobuffalo/pop | connection.go | Open | func (c *Connection) Open() error {
if c.Store != nil {
return nil
}
if c.Dialect == nil {
return errors.New("invalid connection instance")
}
details := c.Dialect.Details()
db, err := sqlx.Open(details.Dialect, c.Dialect.URL())
if err != nil {
return errors.Wrap(err, "could not open database connection")
... | go | func (c *Connection) Open() error {
if c.Store != nil {
return nil
}
if c.Dialect == nil {
return errors.New("invalid connection instance")
}
details := c.Dialect.Details()
db, err := sqlx.Open(details.Dialect, c.Dialect.URL())
if err != nil {
return errors.Wrap(err, "could not open database connection")
... | [
"func",
"(",
"c",
"*",
"Connection",
")",
"Open",
"(",
")",
"error",
"{",
"if",
"c",
".",
"Store",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"c",
".",
"Dialect",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",... | // Open creates a new datasource connection | [
"Open",
"creates",
"a",
"new",
"datasource",
"connection"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/connection.go#L89-L112 | train |
gobuffalo/pop | connection.go | Transaction | func (c *Connection) Transaction(fn func(tx *Connection) error) error {
return c.Dialect.Lock(func() error {
var dberr error
cn, err := c.NewTransaction()
if err != nil {
return err
}
err = fn(cn)
if err != nil {
dberr = cn.TX.Rollback()
} else {
dberr = cn.TX.Commit()
}
if err != nil {
r... | go | func (c *Connection) Transaction(fn func(tx *Connection) error) error {
return c.Dialect.Lock(func() error {
var dberr error
cn, err := c.NewTransaction()
if err != nil {
return err
}
err = fn(cn)
if err != nil {
dberr = cn.TX.Rollback()
} else {
dberr = cn.TX.Commit()
}
if err != nil {
r... | [
"func",
"(",
"c",
"*",
"Connection",
")",
"Transaction",
"(",
"fn",
"func",
"(",
"tx",
"*",
"Connection",
")",
"error",
")",
"error",
"{",
"return",
"c",
".",
"Dialect",
".",
"Lock",
"(",
"func",
"(",
")",
"error",
"{",
"var",
"dberr",
"error",
"\n... | // Transaction will start a new transaction on the connection. If the inner function
// returns an error then the transaction will be rolled back, otherwise the transaction
// will automatically commit at the end. | [
"Transaction",
"will",
"start",
"a",
"new",
"transaction",
"on",
"the",
"connection",
".",
"If",
"the",
"inner",
"function",
"returns",
"an",
"error",
"then",
"the",
"transaction",
"will",
"be",
"rolled",
"back",
"otherwise",
"the",
"transaction",
"will",
"aut... | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/connection.go#L122-L141 | train |
gobuffalo/pop | connection.go | Rollback | func (c *Connection) Rollback(fn func(tx *Connection)) error {
cn, err := c.NewTransaction()
if err != nil {
return err
}
fn(cn)
return cn.TX.Rollback()
} | go | func (c *Connection) Rollback(fn func(tx *Connection)) error {
cn, err := c.NewTransaction()
if err != nil {
return err
}
fn(cn)
return cn.TX.Rollback()
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"Rollback",
"(",
"fn",
"func",
"(",
"tx",
"*",
"Connection",
")",
")",
"error",
"{",
"cn",
",",
"err",
":=",
"c",
".",
"NewTransaction",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n... | // Rollback will open a new transaction and automatically rollback that transaction
// when the inner function returns, regardless. This can be useful for tests, etc... | [
"Rollback",
"will",
"open",
"a",
"new",
"transaction",
"and",
"automatically",
"rollback",
"that",
"transaction",
"when",
"the",
"inner",
"function",
"returns",
"regardless",
".",
"This",
"can",
"be",
"useful",
"for",
"tests",
"etc",
"..."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/connection.go#L145-L152 | train |
gobuffalo/pop | connection.go | NewTransaction | func (c *Connection) NewTransaction() (*Connection, error) {
var cn *Connection
if c.TX == nil {
tx, err := c.Store.Transaction()
if err != nil {
return cn, errors.Wrap(err, "couldn't start a new transaction")
}
cn = &Connection{
ID: randx.String(30),
Store: tx,
Dialect: c.Dialect,
TX: ... | go | func (c *Connection) NewTransaction() (*Connection, error) {
var cn *Connection
if c.TX == nil {
tx, err := c.Store.Transaction()
if err != nil {
return cn, errors.Wrap(err, "couldn't start a new transaction")
}
cn = &Connection{
ID: randx.String(30),
Store: tx,
Dialect: c.Dialect,
TX: ... | [
"func",
"(",
"c",
"*",
"Connection",
")",
"NewTransaction",
"(",
")",
"(",
"*",
"Connection",
",",
"error",
")",
"{",
"var",
"cn",
"*",
"Connection",
"\n",
"if",
"c",
".",
"TX",
"==",
"nil",
"{",
"tx",
",",
"err",
":=",
"c",
".",
"Store",
".",
... | // NewTransaction starts a new transaction on the connection | [
"NewTransaction",
"starts",
"a",
"new",
"transaction",
"on",
"the",
"connection"
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/connection.go#L155-L172 | train |
gobuffalo/pop | columns/tags.go | Find | func (t Tags) Find(name string) Tag {
for _, popTag := range t {
if popTag.Name == name {
return popTag
}
}
return Tag{}
} | go | func (t Tags) Find(name string) Tag {
for _, popTag := range t {
if popTag.Name == name {
return popTag
}
}
return Tag{}
} | [
"func",
"(",
"t",
"Tags",
")",
"Find",
"(",
"name",
"string",
")",
"Tag",
"{",
"for",
"_",
",",
"popTag",
":=",
"range",
"t",
"{",
"if",
"popTag",
".",
"Name",
"==",
"name",
"{",
"return",
"popTag",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"Tag",
... | // Find find for a specific tag with the name passed as
// a param. returns an empty Tag in case it is not found. | [
"Find",
"find",
"for",
"a",
"specific",
"tag",
"with",
"the",
"name",
"passed",
"as",
"a",
"param",
".",
"returns",
"an",
"empty",
"Tag",
"in",
"case",
"it",
"is",
"not",
"found",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/columns/tags.go#L32-L39 | train |
gobuffalo/pop | columns/tags.go | TagsFor | func TagsFor(field reflect.StructField) Tags {
pTags := Tags{}
for _, tag := range strings.Fields(tags) {
if valTag := field.Tag.Get(tag); valTag != "" {
pTags = append(pTags, Tag{valTag, tag})
}
}
if len(pTags) == 0 {
pTags = append(pTags, Tag{field.Name, "db"})
}
return pTags
} | go | func TagsFor(field reflect.StructField) Tags {
pTags := Tags{}
for _, tag := range strings.Fields(tags) {
if valTag := field.Tag.Get(tag); valTag != "" {
pTags = append(pTags, Tag{valTag, tag})
}
}
if len(pTags) == 0 {
pTags = append(pTags, Tag{field.Name, "db"})
}
return pTags
} | [
"func",
"TagsFor",
"(",
"field",
"reflect",
".",
"StructField",
")",
"Tags",
"{",
"pTags",
":=",
"Tags",
"{",
"}",
"\n",
"for",
"_",
",",
"tag",
":=",
"range",
"strings",
".",
"Fields",
"(",
"tags",
")",
"{",
"if",
"valTag",
":=",
"field",
".",
"Ta... | // TagsFor is a function which returns all tags defined
// in model field. | [
"TagsFor",
"is",
"a",
"function",
"which",
"returns",
"all",
"tags",
"defined",
"in",
"model",
"field",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/columns/tags.go#L43-L55 | train |
gobuffalo/pop | slices/string.go | Scan | func (s *String) Scan(src interface{}) error {
ss := pq.StringArray(*s)
err := ss.Scan(src)
*s = String(ss)
return err
} | go | func (s *String) Scan(src interface{}) error {
ss := pq.StringArray(*s)
err := ss.Scan(src)
*s = String(ss)
return err
} | [
"func",
"(",
"s",
"*",
"String",
")",
"Scan",
"(",
"src",
"interface",
"{",
"}",
")",
"error",
"{",
"ss",
":=",
"pq",
".",
"StringArray",
"(",
"*",
"s",
")",
"\n",
"err",
":=",
"ss",
".",
"Scan",
"(",
"src",
")",
"\n",
"*",
"s",
"=",
"String"... | // Scan implements the sql.Scanner interface.
// It allows to read the string slice from the database value. | [
"Scan",
"implements",
"the",
"sql",
".",
"Scanner",
"interface",
".",
"It",
"allows",
"to",
"read",
"the",
"string",
"slice",
"from",
"the",
"database",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/string.go#L26-L31 | train |
gobuffalo/pop | slices/string.go | Value | func (s String) Value() (driver.Value, error) {
ss := pq.StringArray(s)
return ss.Value()
} | go | func (s String) Value() (driver.Value, error) {
ss := pq.StringArray(s)
return ss.Value()
} | [
"func",
"(",
"s",
"String",
")",
"Value",
"(",
")",
"(",
"driver",
".",
"Value",
",",
"error",
")",
"{",
"ss",
":=",
"pq",
".",
"StringArray",
"(",
"s",
")",
"\n",
"return",
"ss",
".",
"Value",
"(",
")",
"\n",
"}"
] | // Value implements the driver.Valuer interface.
// It allows to convert the string slice to a driver.value. | [
"Value",
"implements",
"the",
"driver",
".",
"Valuer",
"interface",
".",
"It",
"allows",
"to",
"convert",
"the",
"string",
"slice",
"to",
"a",
"driver",
".",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/string.go#L35-L38 | train |
gobuffalo/pop | slices/string.go | UnmarshalJSON | func (s *String) UnmarshalJSON(data []byte) error {
var ss pq.StringArray
if err := json.Unmarshal(data, &ss); err != nil {
return err
}
*s = String(ss)
return nil
} | go | func (s *String) UnmarshalJSON(data []byte) error {
var ss pq.StringArray
if err := json.Unmarshal(data, &ss); err != nil {
return err
}
*s = String(ss)
return nil
} | [
"func",
"(",
"s",
"*",
"String",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ss",
"pq",
".",
"StringArray",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"ss",
")",
";",
"err",
"!=",... | // UnmarshalJSON will unmarshall JSON value into
// the string slice representation of this value. | [
"UnmarshalJSON",
"will",
"unmarshall",
"JSON",
"value",
"into",
"the",
"string",
"slice",
"representation",
"of",
"this",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/string.go#L42-L49 | train |
gobuffalo/pop | slices/string.go | UnmarshalText | func (s *String) UnmarshalText(text []byte) error {
r := csv.NewReader(bytes.NewReader(text))
var words []string
for {
record, err := r.Read()
if err == io.EOF {
break
}
if err != nil {
return err
}
words = append(words, record...)
}
*s = String(words)
return nil
} | go | func (s *String) UnmarshalText(text []byte) error {
r := csv.NewReader(bytes.NewReader(text))
var words []string
for {
record, err := r.Read()
if err == io.EOF {
break
}
if err != nil {
return err
}
words = append(words, record...)
}
*s = String(words)
return nil
} | [
"func",
"(",
"s",
"*",
"String",
")",
"UnmarshalText",
"(",
"text",
"[",
"]",
"byte",
")",
"error",
"{",
"r",
":=",
"csv",
".",
"NewReader",
"(",
"bytes",
".",
"NewReader",
"(",
"text",
")",
")",
"\n\n",
"var",
"words",
"[",
"]",
"string",
"\n",
... | // UnmarshalText will unmarshall text value into
// the string slice representation of this value. | [
"UnmarshalText",
"will",
"unmarshall",
"text",
"value",
"into",
"the",
"string",
"slice",
"representation",
"of",
"this",
"value",
"."
] | 9eeaaa184b5e2f2d98ba1a306447621f64bc1826 | https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/string.go#L53-L71 | train |
valyala/quicktemplate | parser/parser.go | Parse | func Parse(w io.Writer, r io.Reader, filename, pkg string) error {
p := &parser{
s: newScanner(r, filename),
w: w,
packageName: pkg,
}
return p.parseTemplate()
} | go | func Parse(w io.Writer, r io.Reader, filename, pkg string) error {
p := &parser{
s: newScanner(r, filename),
w: w,
packageName: pkg,
}
return p.parseTemplate()
} | [
"func",
"Parse",
"(",
"w",
"io",
".",
"Writer",
",",
"r",
"io",
".",
"Reader",
",",
"filename",
",",
"pkg",
"string",
")",
"error",
"{",
"p",
":=",
"&",
"parser",
"{",
"s",
":",
"newScanner",
"(",
"r",
",",
"filename",
")",
",",
"w",
":",
"w",
... | // Parse parses the contents of the supplied reader, writing generated code to
// the supplied writer. Uses filename as the source file for line comments, and
// pkg as the Go package name. | [
"Parse",
"parses",
"the",
"contents",
"of",
"the",
"supplied",
"reader",
"writing",
"generated",
"code",
"to",
"the",
"supplied",
"writer",
".",
"Uses",
"filename",
"as",
"the",
"source",
"file",
"for",
"line",
"comments",
"and",
"pkg",
"as",
"the",
"Go",
... | 480e8b93a60078dd620fcf4b2591f4d6422e3fc1 | https://github.com/valyala/quicktemplate/blob/480e8b93a60078dd620fcf4b2591f4d6422e3fc1/parser/parser.go#L31-L38 | train |
valyala/quicktemplate | writer.go | AcquireWriter | func AcquireWriter(w io.Writer) *Writer {
v := writerPool.Get()
if v == nil {
qw := &Writer{}
qw.e.w = &htmlEscapeWriter{}
v = qw
}
qw := v.(*Writer)
qw.e.w.(*htmlEscapeWriter).w = w
qw.n.w = w
return qw
} | go | func AcquireWriter(w io.Writer) *Writer {
v := writerPool.Get()
if v == nil {
qw := &Writer{}
qw.e.w = &htmlEscapeWriter{}
v = qw
}
qw := v.(*Writer)
qw.e.w.(*htmlEscapeWriter).w = w
qw.n.w = w
return qw
} | [
"func",
"AcquireWriter",
"(",
"w",
"io",
".",
"Writer",
")",
"*",
"Writer",
"{",
"v",
":=",
"writerPool",
".",
"Get",
"(",
")",
"\n",
"if",
"v",
"==",
"nil",
"{",
"qw",
":=",
"&",
"Writer",
"{",
"}",
"\n",
"qw",
".",
"e",
".",
"w",
"=",
"&",
... | // AcquireWriter returns new writer from the pool.
//
// Return unneeded writer to the pool by calling ReleaseWriter
// in order to reduce memory allocations. | [
"AcquireWriter",
"returns",
"new",
"writer",
"from",
"the",
"pool",
".",
"Return",
"unneeded",
"writer",
"to",
"the",
"pool",
"by",
"calling",
"ReleaseWriter",
"in",
"order",
"to",
"reduce",
"memory",
"allocations",
"."
] | 480e8b93a60078dd620fcf4b2591f4d6422e3fc1 | https://github.com/valyala/quicktemplate/blob/480e8b93a60078dd620fcf4b2591f4d6422e3fc1/writer.go#L37-L48 | train |
valyala/quicktemplate | writer.go | ReleaseWriter | func ReleaseWriter(qw *Writer) {
hw := qw.e.w.(*htmlEscapeWriter)
hw.w = nil
qw.e.Reset()
qw.e.w = hw
qw.n.Reset()
writerPool.Put(qw)
} | go | func ReleaseWriter(qw *Writer) {
hw := qw.e.w.(*htmlEscapeWriter)
hw.w = nil
qw.e.Reset()
qw.e.w = hw
qw.n.Reset()
writerPool.Put(qw)
} | [
"func",
"ReleaseWriter",
"(",
"qw",
"*",
"Writer",
")",
"{",
"hw",
":=",
"qw",
".",
"e",
".",
"w",
".",
"(",
"*",
"htmlEscapeWriter",
")",
"\n",
"hw",
".",
"w",
"=",
"nil",
"\n",
"qw",
".",
"e",
".",
"Reset",
"(",
")",
"\n",
"qw",
".",
"e",
... | // ReleaseWriter returns the writer to the pool.
//
// Do not access released writer, otherwise data races may occur. | [
"ReleaseWriter",
"returns",
"the",
"writer",
"to",
"the",
"pool",
".",
"Do",
"not",
"access",
"released",
"writer",
"otherwise",
"data",
"races",
"may",
"occur",
"."
] | 480e8b93a60078dd620fcf4b2591f4d6422e3fc1 | https://github.com/valyala/quicktemplate/blob/480e8b93a60078dd620fcf4b2591f4d6422e3fc1/writer.go#L53-L62 | train |
valyala/quicktemplate | writer.go | D | func (w *QWriter) D(n int) {
bb, ok := w.w.(*ByteBuffer)
if ok {
bb.B = strconv.AppendInt(bb.B, int64(n), 10)
} else {
w.b = strconv.AppendInt(w.b[:0], int64(n), 10)
w.Write(w.b)
}
} | go | func (w *QWriter) D(n int) {
bb, ok := w.w.(*ByteBuffer)
if ok {
bb.B = strconv.AppendInt(bb.B, int64(n), 10)
} else {
w.b = strconv.AppendInt(w.b[:0], int64(n), 10)
w.Write(w.b)
}
} | [
"func",
"(",
"w",
"*",
"QWriter",
")",
"D",
"(",
"n",
"int",
")",
"{",
"bb",
",",
"ok",
":=",
"w",
".",
"w",
".",
"(",
"*",
"ByteBuffer",
")",
"\n",
"if",
"ok",
"{",
"bb",
".",
"B",
"=",
"strconv",
".",
"AppendInt",
"(",
"bb",
".",
"B",
"... | // D writes n to w. | [
"D",
"writes",
"n",
"to",
"w",
"."
] | 480e8b93a60078dd620fcf4b2591f4d6422e3fc1 | https://github.com/valyala/quicktemplate/blob/480e8b93a60078dd620fcf4b2591f4d6422e3fc1/writer.go#L107-L115 | train |
valyala/quicktemplate | writer.go | F | func (w *QWriter) F(f float64) {
n := int(f)
if float64(n) == f {
// Fast path - just int.
w.D(n)
return
}
// Slow path.
w.FPrec(f, -1)
} | go | func (w *QWriter) F(f float64) {
n := int(f)
if float64(n) == f {
// Fast path - just int.
w.D(n)
return
}
// Slow path.
w.FPrec(f, -1)
} | [
"func",
"(",
"w",
"*",
"QWriter",
")",
"F",
"(",
"f",
"float64",
")",
"{",
"n",
":=",
"int",
"(",
"f",
")",
"\n",
"if",
"float64",
"(",
"n",
")",
"==",
"f",
"{",
"// Fast path - just int.",
"w",
".",
"D",
"(",
"n",
")",
"\n",
"return",
"\n",
... | // F writes f to w. | [
"F",
"writes",
"f",
"to",
"w",
"."
] | 480e8b93a60078dd620fcf4b2591f4d6422e3fc1 | https://github.com/valyala/quicktemplate/blob/480e8b93a60078dd620fcf4b2591f4d6422e3fc1/writer.go#L118-L128 | train |
valyala/quicktemplate | writer.go | FPrec | func (w *QWriter) FPrec(f float64, prec int) {
bb, ok := w.w.(*ByteBuffer)
if ok {
bb.B = strconv.AppendFloat(bb.B, f, 'f', prec, 64)
} else {
w.b = strconv.AppendFloat(w.b[:0], f, 'f', prec, 64)
w.Write(w.b)
}
} | go | func (w *QWriter) FPrec(f float64, prec int) {
bb, ok := w.w.(*ByteBuffer)
if ok {
bb.B = strconv.AppendFloat(bb.B, f, 'f', prec, 64)
} else {
w.b = strconv.AppendFloat(w.b[:0], f, 'f', prec, 64)
w.Write(w.b)
}
} | [
"func",
"(",
"w",
"*",
"QWriter",
")",
"FPrec",
"(",
"f",
"float64",
",",
"prec",
"int",
")",
"{",
"bb",
",",
"ok",
":=",
"w",
".",
"w",
".",
"(",
"*",
"ByteBuffer",
")",
"\n",
"if",
"ok",
"{",
"bb",
".",
"B",
"=",
"strconv",
".",
"AppendFloa... | // FPrec writes f to w using the given floating point precision. | [
"FPrec",
"writes",
"f",
"to",
"w",
"using",
"the",
"given",
"floating",
"point",
"precision",
"."
] | 480e8b93a60078dd620fcf4b2591f4d6422e3fc1 | https://github.com/valyala/quicktemplate/blob/480e8b93a60078dd620fcf4b2591f4d6422e3fc1/writer.go#L131-L139 | train |
valyala/quicktemplate | writer.go | Q | func (w *QWriter) Q(s string) {
w.Write(strQuote)
writeJSONString(w, s)
w.Write(strQuote)
} | go | func (w *QWriter) Q(s string) {
w.Write(strQuote)
writeJSONString(w, s)
w.Write(strQuote)
} | [
"func",
"(",
"w",
"*",
"QWriter",
")",
"Q",
"(",
"s",
"string",
")",
"{",
"w",
".",
"Write",
"(",
"strQuote",
")",
"\n",
"writeJSONString",
"(",
"w",
",",
"s",
")",
"\n",
"w",
".",
"Write",
"(",
"strQuote",
")",
"\n",
"}"
] | // Q writes quoted json-safe s to w. | [
"Q",
"writes",
"quoted",
"json",
"-",
"safe",
"s",
"to",
"w",
"."
] | 480e8b93a60078dd620fcf4b2591f4d6422e3fc1 | https://github.com/valyala/quicktemplate/blob/480e8b93a60078dd620fcf4b2591f4d6422e3fc1/writer.go#L142-L146 | train |
valyala/quicktemplate | writer.go | U | func (w *QWriter) U(s string) {
bb, ok := w.w.(*ByteBuffer)
if ok {
bb.B = appendURLEncode(bb.B, s)
} else {
w.b = appendURLEncode(w.b[:0], s)
w.Write(w.b)
}
} | go | func (w *QWriter) U(s string) {
bb, ok := w.w.(*ByteBuffer)
if ok {
bb.B = appendURLEncode(bb.B, s)
} else {
w.b = appendURLEncode(w.b[:0], s)
w.Write(w.b)
}
} | [
"func",
"(",
"w",
"*",
"QWriter",
")",
"U",
"(",
"s",
"string",
")",
"{",
"bb",
",",
"ok",
":=",
"w",
".",
"w",
".",
"(",
"*",
"ByteBuffer",
")",
"\n",
"if",
"ok",
"{",
"bb",
".",
"B",
"=",
"appendURLEncode",
"(",
"bb",
".",
"B",
",",
"s",
... | // U writes url-encoded s to w. | [
"U",
"writes",
"url",
"-",
"encoded",
"s",
"to",
"w",
"."
] | 480e8b93a60078dd620fcf4b2591f4d6422e3fc1 | https://github.com/valyala/quicktemplate/blob/480e8b93a60078dd620fcf4b2591f4d6422e3fc1/writer.go#L175-L183 | train |
docker/distribution | registry/storage/driver/base/regulator.go | GetLimitFromParameter | func GetLimitFromParameter(param interface{}, min, def uint64) (uint64, error) {
limit := def
switch v := param.(type) {
case string:
var err error
if limit, err = strconv.ParseUint(v, 0, 64); err != nil {
return limit, fmt.Errorf("parameter must be an integer, '%v' invalid", param)
}
case uint64:
limit... | go | func GetLimitFromParameter(param interface{}, min, def uint64) (uint64, error) {
limit := def
switch v := param.(type) {
case string:
var err error
if limit, err = strconv.ParseUint(v, 0, 64); err != nil {
return limit, fmt.Errorf("parameter must be an integer, '%v' invalid", param)
}
case uint64:
limit... | [
"func",
"GetLimitFromParameter",
"(",
"param",
"interface",
"{",
"}",
",",
"min",
",",
"def",
"uint64",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"limit",
":=",
"def",
"\n\n",
"switch",
"v",
":=",
"param",
".",
"(",
"type",
")",
"{",
"case",
"strin... | // GetLimitFromParameter takes an interface type as decoded from the YAML
// configuration and returns a uint64 representing the maximum number of
// concurrent calls given a minimum limit and default.
//
// If the parameter supplied is of an invalid type this returns an error. | [
"GetLimitFromParameter",
"takes",
"an",
"interface",
"type",
"as",
"decoded",
"from",
"the",
"YAML",
"configuration",
"and",
"returns",
"a",
"uint64",
"representing",
"the",
"maximum",
"number",
"of",
"concurrent",
"calls",
"given",
"a",
"minimum",
"limit",
"and",... | 3226863cbcba6dbc2f6c83a37b28126c934af3f8 | https://github.com/docker/distribution/blob/3226863cbcba6dbc2f6c83a37b28126c934af3f8/registry/storage/driver/base/regulator.go#L26-L59 | train |
docker/distribution | registry/storage/driver/base/regulator.go | NewRegulator | func NewRegulator(driver storagedriver.StorageDriver, limit uint64) storagedriver.StorageDriver {
return ®ulator{
StorageDriver: driver,
Cond: sync.NewCond(&sync.Mutex{}),
available: limit,
}
} | go | func NewRegulator(driver storagedriver.StorageDriver, limit uint64) storagedriver.StorageDriver {
return ®ulator{
StorageDriver: driver,
Cond: sync.NewCond(&sync.Mutex{}),
available: limit,
}
} | [
"func",
"NewRegulator",
"(",
"driver",
"storagedriver",
".",
"StorageDriver",
",",
"limit",
"uint64",
")",
"storagedriver",
".",
"StorageDriver",
"{",
"return",
"&",
"regulator",
"{",
"StorageDriver",
":",
"driver",
",",
"Cond",
":",
"sync",
".",
"NewCond",
"(... | // NewRegulator wraps the given driver and is used to regulate concurrent calls
// to the given storage driver to a maximum of the given limit. This is useful
// for storage drivers that would otherwise create an unbounded number of OS
// threads if allowed to be called unregulated. | [
"NewRegulator",
"wraps",
"the",
"given",
"driver",
"and",
"is",
"used",
"to",
"regulate",
"concurrent",
"calls",
"to",
"the",
"given",
"storage",
"driver",
"to",
"a",
"maximum",
"of",
"the",
"given",
"limit",
".",
"This",
"is",
"useful",
"for",
"storage",
... | 3226863cbcba6dbc2f6c83a37b28126c934af3f8 | https://github.com/docker/distribution/blob/3226863cbcba6dbc2f6c83a37b28126c934af3f8/registry/storage/driver/base/regulator.go#L65-L71 | train |
docker/distribution | registry/storage/driver/base/regulator.go | Name | func (r *regulator) Name() string {
r.enter()
defer r.exit()
return r.StorageDriver.Name()
} | go | func (r *regulator) Name() string {
r.enter()
defer r.exit()
return r.StorageDriver.Name()
} | [
"func",
"(",
"r",
"*",
"regulator",
")",
"Name",
"(",
")",
"string",
"{",
"r",
".",
"enter",
"(",
")",
"\n",
"defer",
"r",
".",
"exit",
"(",
")",
"\n\n",
"return",
"r",
".",
"StorageDriver",
".",
"Name",
"(",
")",
"\n",
"}"
] | // Name returns the human-readable "name" of the driver, useful in error
// messages and logging. By convention, this will just be the registration
// name, but drivers may provide other information here. | [
"Name",
"returns",
"the",
"human",
"-",
"readable",
"name",
"of",
"the",
"driver",
"useful",
"in",
"error",
"messages",
"and",
"logging",
".",
"By",
"convention",
"this",
"will",
"just",
"be",
"the",
"registration",
"name",
"but",
"drivers",
"may",
"provide"... | 3226863cbcba6dbc2f6c83a37b28126c934af3f8 | https://github.com/docker/distribution/blob/3226863cbcba6dbc2f6c83a37b28126c934af3f8/registry/storage/driver/base/regulator.go#L92-L97 | train |
docker/distribution | registry/storage/driver/base/regulator.go | Writer | func (r *regulator) Writer(ctx context.Context, path string, append bool) (storagedriver.FileWriter, error) {
r.enter()
defer r.exit()
return r.StorageDriver.Writer(ctx, path, append)
} | go | func (r *regulator) Writer(ctx context.Context, path string, append bool) (storagedriver.FileWriter, error) {
r.enter()
defer r.exit()
return r.StorageDriver.Writer(ctx, path, append)
} | [
"func",
"(",
"r",
"*",
"regulator",
")",
"Writer",
"(",
"ctx",
"context",
".",
"Context",
",",
"path",
"string",
",",
"append",
"bool",
")",
"(",
"storagedriver",
".",
"FileWriter",
",",
"error",
")",
"{",
"r",
".",
"enter",
"(",
")",
"\n",
"defer",
... | // Writer stores the contents of the provided io.ReadCloser at a
// location designated by the given path.
// May be used to resume writing a stream by providing a nonzero offset.
// The offset must be no larger than the CurrentSize for this path. | [
"Writer",
"stores",
"the",
"contents",
"of",
"the",
"provided",
"io",
".",
"ReadCloser",
"at",
"a",
"location",
"designated",
"by",
"the",
"given",
"path",
".",
"May",
"be",
"used",
"to",
"resume",
"writing",
"a",
"stream",
"by",
"providing",
"a",
"nonzero... | 3226863cbcba6dbc2f6c83a37b28126c934af3f8 | https://github.com/docker/distribution/blob/3226863cbcba6dbc2f6c83a37b28126c934af3f8/registry/storage/driver/base/regulator.go#L131-L136 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.