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 *Connection) error { schemaMigrations := newSchemaMigrations(mtn) smSQL, err := c.Dialect.FizzTranslator().CreateTable(schemaMigrations) if err != nil { return errors.Wrap(err, "could not build SQL for schema migration table") } err = tx.RawQuery(smSQL).Exec() if err != nil { return errors.WithStack(errors.Wrap(err, smSQL)) } return nil }) }
go
func (m Migrator) CreateSchemaMigrations() error { c := m.Connection mtn := c.MigrationTableName() err := c.Open() if err != nil { return errors.Wrap(err, "could not open connection") } _, err = c.Store.Exec(fmt.Sprintf("select * from %s", mtn)) if err == nil { return nil } return c.Transaction(func(tx *Connection) error { schemaMigrations := newSchemaMigrations(mtn) smSQL, err := c.Dialect.FizzTranslator().CreateTable(schemaMigrations) if err != nil { return errors.Wrap(err, "could not build SQL for schema migration table") } err = tx.RawQuery(smSQL).Exec() if err != nil { return errors.WithStack(errors.Wrap(err, smSQL)) } return nil }) }
[ "func", "(", "m", "Migrator", ")", "CreateSchemaMigrations", "(", ")", "error", "{", "c", ":=", "m", ".", "Connection", "\n", "mtn", ":=", "c", ".", "MigrationTableName", "(", ")", "\n", "err", ":=", "c", ".", "Open", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "_", ",", "err", "=", "c", ".", "Store", ".", "Exec", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "mtn", ")", ")", "\n", "if", "err", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "c", ".", "Transaction", "(", "func", "(", "tx", "*", "Connection", ")", "error", "{", "schemaMigrations", ":=", "newSchemaMigrations", "(", "mtn", ")", "\n", "smSQL", ",", "err", ":=", "c", ".", "Dialect", ".", "FizzTranslator", "(", ")", ".", "CreateTable", "(", "schemaMigrations", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "err", "=", "tx", ".", "RawQuery", "(", "smSQL", ")", ".", "Exec", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "WithStack", "(", "errors", ".", "Wrap", "(", "err", ",", "smSQL", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// CreateSchemaMigrations sets up a table to track migrations. This is an idempotent // operation.
[ "CreateSchemaMigrations", "sets", "up", "a", "table", "to", "track", "migrations", ".", "This", "is", "an", "idempotent", "operation", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migrator.go#L168-L192
train
gobuffalo/pop
migrator.go
DumpMigrationSchema
func (m Migrator) DumpMigrationSchema() error { if m.SchemaPath == "" { return nil } c := m.Connection schema := filepath.Join(m.SchemaPath, "schema.sql") f, err := os.Create(schema) if err != nil { return errors.WithStack(err) } err = c.Dialect.DumpSchema(f) if err != nil { os.RemoveAll(schema) return errors.WithStack(err) } return nil }
go
func (m Migrator) DumpMigrationSchema() error { if m.SchemaPath == "" { return nil } c := m.Connection schema := filepath.Join(m.SchemaPath, "schema.sql") f, err := os.Create(schema) if err != nil { return errors.WithStack(err) } err = c.Dialect.DumpSchema(f) if err != nil { os.RemoveAll(schema) return errors.WithStack(err) } return nil }
[ "func", "(", "m", "Migrator", ")", "DumpMigrationSchema", "(", ")", "error", "{", "if", "m", ".", "SchemaPath", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "c", ":=", "m", ".", "Connection", "\n", "schema", ":=", "filepath", ".", "Join", "(", "m", ".", "SchemaPath", ",", "\"", "\"", ")", "\n", "f", ",", "err", ":=", "os", ".", "Create", "(", "schema", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "err", "=", "c", ".", "Dialect", ".", "DumpSchema", "(", "f", ")", "\n", "if", "err", "!=", "nil", "{", "os", ".", "RemoveAll", "(", "schema", ")", "\n", "return", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", ".", "Warn", ",", "\"", "\"", ")", "\n", "return", "q", "\n", "}", "\n", "q", ".", "joinClauses", "=", "append", "(", "q", ".", "joinClauses", ",", "joinClause", "{", "\"", "\"", ",", "table", ",", "on", ",", "args", "}", ")", "\n", "return", "q", "\n", "}" ]
// Join will append a JOIN clause to the query
[ "Join", "will", "append", "a", "JOIN", "clause", "to", "the", "query" ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/query_joins.go#L9-L16
train
gobuffalo/pop
query.go
Clone
func (q *Query) Clone(targetQ *Query) { rawSQL := *q.RawSQL targetQ.RawSQL = &rawSQL targetQ.limitResults = q.limitResults targetQ.whereClauses = q.whereClauses targetQ.orderClauses = q.orderClauses targetQ.fromClauses = q.fromClauses targetQ.belongsToThroughClauses = q.belongsToThroughClauses targetQ.joinClauses = q.joinClauses targetQ.groupClauses = q.groupClauses targetQ.havingClauses = q.havingClauses targetQ.addColumns = q.addColumns if q.Paginator != nil { paginator := *q.Paginator targetQ.Paginator = &paginator } if q.Connection != nil { connection := *q.Connection targetQ.Connection = &connection } }
go
func (q *Query) Clone(targetQ *Query) { rawSQL := *q.RawSQL targetQ.RawSQL = &rawSQL targetQ.limitResults = q.limitResults targetQ.whereClauses = q.whereClauses targetQ.orderClauses = q.orderClauses targetQ.fromClauses = q.fromClauses targetQ.belongsToThroughClauses = q.belongsToThroughClauses targetQ.joinClauses = q.joinClauses targetQ.groupClauses = q.groupClauses targetQ.havingClauses = q.havingClauses targetQ.addColumns = q.addColumns if q.Paginator != nil { paginator := *q.Paginator targetQ.Paginator = &paginator } if q.Connection != nil { connection := *q.Connection targetQ.Connection = &connection } }
[ "func", "(", "q", "*", "Query", ")", "Clone", "(", "targetQ", "*", "Query", ")", "{", "rawSQL", ":=", "*", "q", ".", "RawSQL", "\n", "targetQ", ".", "RawSQL", "=", "&", "rawSQL", "\n\n", "targetQ", ".", "limitResults", "=", "q", ".", "limitResults", "\n", "targetQ", ".", "whereClauses", "=", "q", ".", "whereClauses", "\n", "targetQ", ".", "orderClauses", "=", "q", ".", "orderClauses", "\n", "targetQ", ".", "fromClauses", "=", "q", ".", "fromClauses", "\n", "targetQ", ".", "belongsToThroughClauses", "=", "q", ".", "belongsToThroughClauses", "\n", "targetQ", ".", "joinClauses", "=", "q", ".", "joinClauses", "\n", "targetQ", ".", "groupClauses", "=", "q", ".", "groupClauses", "\n", "targetQ", ".", "havingClauses", "=", "q", ".", "havingClauses", "\n", "targetQ", ".", "addColumns", "=", "q", ".", "addColumns", "\n\n", "if", "q", ".", "Paginator", "!=", "nil", "{", "paginator", ":=", "*", "q", ".", "Paginator", "\n", "targetQ", ".", "Paginator", "=", "&", "paginator", "\n", "}", "\n\n", "if", "q", ".", "Connection", "!=", "nil", "{", "connection", ":=", "*", "q", ".", "Connection", "\n", "targetQ", ".", "Connection", "=", "&", "connection", "\n", "}", "\n", "}" ]
// 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", "=", "[", "]", "string", "{", "}", ",", "[", "]", "string", "{", "}", "\n", "}" ]
// 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", ".", "eagerFields", ",", "}", "\n", "}" ]
// 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", "...", ")", "\n", "return", "sb", ".", "String", "(", ")", ",", "sb", ".", "Args", "(", ")", "\n", "}" ]
// 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", "}", "\n", "return", "newSQLBuilder", "(", "q", ",", "model", ",", "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", ",", "\"", "\"", ")", "\n", "return", "q", "\n", "}", "\n", "q", ".", "havingClauses", "=", "append", "(", "q", ".", "havingClauses", ",", "HavingClause", "{", "condition", ",", "args", "}", ")", "\n\n", "return", "q", "\n", "}" ]
// 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", "(", "\"", "\"", ")", "\n", "}", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "b", ",", "m", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Scan implements the sql.Scanner interface. // It allows to read the map from the database value.
[ "Scan", "implements", "the", "sql", ".", "Scanner", "interface", ".", "It", "allows", "to", "read", "the", "map", "from", "the", "database", "value", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/map.go#L20-L30
train
gobuffalo/pop
slices/map.go
Value
func (m Map) Value() (driver.Value, error) { b, err := json.Marshal(m) if err != nil { return nil, errors.WithStack(err) } return string(b), nil }
go
func (m Map) Value() (driver.Value, error) { b, err := json.Marshal(m) if err != nil { return nil, errors.WithStack(err) } return string(b), nil }
[ "func", "(", "m", "Map", ")", "Value", "(", ")", "(", "driver", ".", "Value", ",", "error", ")", "{", "b", ",", "err", ":=", "json", ".", "Marshal", "(", "m", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "string", "(", "b", ")", ",", "nil", "\n", "}" ]
// 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", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "key", ",", "value", ":=", "range", "stuff", "{", "m", "[", "key", "]", "=", "value", "\n", "}", "\n", "return", "nil", "\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", "(", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", ".", "PrimaryKeyType", "(", ")", "==", "\"", "\"", "{", "return", "fbn", ".", "Interface", "(", ")", ".", "(", "uuid", ".", "UUID", ")", ".", "String", "(", ")", "\n", "}", "\n", "return", "fbn", ".", "Interface", "(", ")", "\n", "}" ]
// 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", ".", "Type", "(", ")", ".", "Name", "(", ")", "\n", "}" ]
// PrimaryKeyType gives the primary key type of the `Model`.
[ "PrimaryKeyType", "gives", "the", "primary", "key", "type", "of", "the", "Model", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/model.go#L45-L51
train
gobuffalo/pop
model.go
TableName
func (m *Model) TableName() string { if s, ok := m.Value.(string); ok { return s } if n, ok := m.Value.(TableNameAble); ok { return n.TableName() } if m.tableName != "" { return m.tableName } t := reflect.TypeOf(m.Value) name := m.typeName(t) defer tableMapMu.Unlock() tableMapMu.Lock() if tableMap[name] == "" { m.tableName = nflect.Tableize(name) tableMap[name] = m.tableName } return tableMap[name] }
go
func (m *Model) TableName() string { if s, ok := m.Value.(string); ok { return s } if n, ok := m.Value.(TableNameAble); ok { return n.TableName() } if m.tableName != "" { return m.tableName } t := reflect.TypeOf(m.Value) name := m.typeName(t) defer tableMapMu.Unlock() tableMapMu.Lock() if tableMap[name] == "" { m.tableName = nflect.Tableize(name) tableMap[name] = m.tableName } return tableMap[name] }
[ "func", "(", "m", "*", "Model", ")", "TableName", "(", ")", "string", "{", "if", "s", ",", "ok", ":=", "m", ".", "Value", ".", "(", "string", ")", ";", "ok", "{", "return", "s", "\n", "}", "\n", "if", "n", ",", "ok", ":=", "m", ".", "Value", ".", "(", "TableNameAble", ")", ";", "ok", "{", "return", "n", ".", "TableName", "(", ")", "\n", "}", "\n\n", "if", "m", ".", "tableName", "!=", "\"", "\"", "{", "return", "m", ".", "tableName", "\n", "}", "\n\n", "t", ":=", "reflect", ".", "TypeOf", "(", "m", ".", "Value", ")", "\n", "name", ":=", "m", ".", "typeName", "(", "t", ")", "\n\n", "defer", "tableMapMu", ".", "Unlock", "(", ")", "\n", "tableMapMu", ".", "Lock", "(", ")", "\n\n", "if", "tableMap", "[", "name", "]", "==", "\"", "\"", "{", "m", ".", "tableName", "=", "nflect", ".", "Tableize", "(", "name", ")", "\n", "tableMap", "[", "name", "]", "=", "m", ".", "tableName", "\n", "}", "\n", "return", "tableMap", "[", "name", "]", "\n", "}" ]
// 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", "(", "\"", "\"", ",", "m", ".", "associationName", "(", ")", ")", ",", "m", ".", "ID", "(", ")", ")", "\n", "return", "q", "\n", "}" ]
// 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", ",", "}", "\n\n", "err", ":=", "fm", ".", "findMigrations", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fm", ",", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "return", "fm", ",", "nil", "\n", "}" ]
// NewMigrationBox from a packr.Box and a Connection.
[ "NewMigrationBox", "from", "a", "packr", ".", "Box", "and", "a", "Connection", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migration_box.go#L19-L31
train
gobuffalo/pop
soda/cmd/generate/model.go
Fizz
func (m model) Fizz() string { s := []string{fmt.Sprintf("create_table(\"%s\") {", m.Name.Tableize())} for _, a := range m.Attributes { switch a.Name.String() { case "created_at", "updated_at": default: col := fizz.Column{ Name: a.Name.Underscore().String(), ColType: fizzColType(a.OriginalType), Options: map[string]interface{}{}, } if a.Primary { col.Options["primary"] = true } if a.Nullable { col.Options["null"] = true } s = append(s, "\t"+col.String()) } } s = append(s, "}") return strings.Join(s, "\n") }
go
func (m model) Fizz() string { s := []string{fmt.Sprintf("create_table(\"%s\") {", m.Name.Tableize())} for _, a := range m.Attributes { switch a.Name.String() { case "created_at", "updated_at": default: col := fizz.Column{ Name: a.Name.Underscore().String(), ColType: fizzColType(a.OriginalType), Options: map[string]interface{}{}, } if a.Primary { col.Options["primary"] = true } if a.Nullable { col.Options["null"] = true } s = append(s, "\t"+col.String()) } } s = append(s, "}") return strings.Join(s, "\n") }
[ "func", "(", "m", "model", ")", "Fizz", "(", ")", "string", "{", "s", ":=", "[", "]", "string", "{", "fmt", ".", "Sprintf", "(", "\"", "\\\"", "\\\"", "\"", ",", "m", ".", "Name", ".", "Tableize", "(", ")", ")", "}", "\n", "for", "_", ",", "a", ":=", "range", "m", ".", "Attributes", "{", "switch", "a", ".", "Name", ".", "String", "(", ")", "{", "case", "\"", "\"", ",", "\"", "\"", ":", "default", ":", "col", ":=", "fizz", ".", "Column", "{", "Name", ":", "a", ".", "Name", ".", "Underscore", "(", ")", ".", "String", "(", ")", ",", "ColType", ":", "fizzColType", "(", "a", ".", "OriginalType", ")", ",", "Options", ":", "map", "[", "string", "]", "interface", "{", "}", "{", "}", ",", "}", "\n", "if", "a", ".", "Primary", "{", "col", ".", "Options", "[", "\"", "\"", "]", "=", "true", "\n", "}", "\n", "if", "a", ".", "Nullable", "{", "col", ".", "Options", "[", "\"", "\"", "]", "=", "true", "\n", "}", "\n", "s", "=", "append", "(", "s", ",", "\"", "\\t", "\"", "+", "col", ".", "String", "(", ")", ")", "\n", "}", "\n", "}", "\n", "s", "=", "append", "(", "s", ",", "\"", "\"", ")", "\n", "return", "strings", ".", "Join", "(", "s", ",", "\"", "\\n", "\"", ")", "\n", "}" ]
// 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", "!=", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "content", "\n", "}" ]
// 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", ".", "(", "int", ")", ")", "\n", "case", "Int64", ":", "return", "NewInt64", "(", "value", ".", "(", "int64", ")", ")", "\n", "case", "UUID", ":", "return", "NewUUID", "(", "value", ".", "(", "uuid", ".", "UUID", ")", ")", "\n", "default", ":", "return", "value", "\n", "}", "\n", "}" ]
// 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", "etc", "." ]
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", "}", "\n", "}" ]
// 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", "(", "\"", "\"", ")", "\n", "}", "\n", "str", ":=", "string", "(", "b", ")", "\n", "*", "f", "=", "strToFloat", "(", "str", ")", "\n", "return", "nil", "\n", "}" ]
// 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", "[", "x", "]", "=", "strconv", ".", "FormatFloat", "(", "i", ",", "'f'", ",", "-", "1", ",", "64", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "sa", ",", "\"", "\"", ")", ")", ",", "nil", "\n", "}" ]
// 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", ")", ",", "\"", "\"", ")", "{", "f", ",", "err", ":=", "strconv", ".", "ParseFloat", "(", "x", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "ss", "=", "append", "(", "ss", ",", "f", ")", "\n", "}", "\n", "*", "f", "=", "ss", "\n", "return", "nil", "\n", "}" ]
// 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", "fm", ".", "SchemaPath", "=", "path", "\n\n", "err", ":=", "fm", ".", "findMigrations", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fm", ",", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "return", "fm", ",", "nil", "\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", ".", "i", "]", "\n", "s", ".", "i", "++", "\n", "return", "r", ",", "true", "\n", "}" ]
// 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", "=", "s", ".", "Next", "(", ")", "\n", "}", "\n", "return", "r", ",", "ok", "\n", "}" ]
// SkipSpaces returns the next non-whitespace rune. // It returns 0, false if the end of the text has been reached.
[ "SkipSpaces", "returns", "the", "next", "non", "-", "whitespace", "rune", ".", "It", "returns", "0", "false", "if", "the", "end", "of", "the", "text", "has", "been", "reached", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/dialect_postgresql.go#L302-L308
train
gobuffalo/pop
dialect_postgresql.go
parseOpts
func parseOpts(name string, o values) error { s := newScanner(name) for { var ( keyRunes, valRunes []rune r rune ok bool ) if r, ok = s.SkipSpaces(); !ok { break } // Scan the key for !unicode.IsSpace(r) && r != '=' { keyRunes = append(keyRunes, r) if r, ok = s.Next(); !ok { break } } // Skip any whitespace if we're not at the = yet if r != '=' { r, ok = s.SkipSpaces() } // The current character should be = if r != '=' || !ok { return fmt.Errorf(`missing "=" after %q in connection info string"`, string(keyRunes)) } // Skip any whitespace after the = if r, ok = s.SkipSpaces(); !ok { // If we reach the end here, the last value is just an empty string as per libpq. o[string(keyRunes)] = "" break } if r != '\'' { for !unicode.IsSpace(r) { if r == '\\' { if r, ok = s.Next(); !ok { return fmt.Errorf(`missing character after backslash`) } } valRunes = append(valRunes, r) if r, ok = s.Next(); !ok { break } } } else { quote: for { if r, ok = s.Next(); !ok { return fmt.Errorf(`unterminated quoted string literal in connection string`) } switch r { case '\'': break quote case '\\': r, _ = s.Next() fallthrough default: valRunes = append(valRunes, r) } } } o[string(keyRunes)] = string(valRunes) } return nil }
go
func parseOpts(name string, o values) error { s := newScanner(name) for { var ( keyRunes, valRunes []rune r rune ok bool ) if r, ok = s.SkipSpaces(); !ok { break } // Scan the key for !unicode.IsSpace(r) && r != '=' { keyRunes = append(keyRunes, r) if r, ok = s.Next(); !ok { break } } // Skip any whitespace if we're not at the = yet if r != '=' { r, ok = s.SkipSpaces() } // The current character should be = if r != '=' || !ok { return fmt.Errorf(`missing "=" after %q in connection info string"`, string(keyRunes)) } // Skip any whitespace after the = if r, ok = s.SkipSpaces(); !ok { // If we reach the end here, the last value is just an empty string as per libpq. o[string(keyRunes)] = "" break } if r != '\'' { for !unicode.IsSpace(r) { if r == '\\' { if r, ok = s.Next(); !ok { return fmt.Errorf(`missing character after backslash`) } } valRunes = append(valRunes, r) if r, ok = s.Next(); !ok { break } } } else { quote: for { if r, ok = s.Next(); !ok { return fmt.Errorf(`unterminated quoted string literal in connection string`) } switch r { case '\'': break quote case '\\': r, _ = s.Next() fallthrough default: valRunes = append(valRunes, r) } } } o[string(keyRunes)] = string(valRunes) } return nil }
[ "func", "parseOpts", "(", "name", "string", ",", "o", "values", ")", "error", "{", "s", ":=", "newScanner", "(", "name", ")", "\n\n", "for", "{", "var", "(", "keyRunes", ",", "valRunes", "[", "]", "rune", "\n", "r", "rune", "\n", "ok", "bool", "\n", ")", "\n\n", "if", "r", ",", "ok", "=", "s", ".", "SkipSpaces", "(", ")", ";", "!", "ok", "{", "break", "\n", "}", "\n\n", "// Scan the key", "for", "!", "unicode", ".", "IsSpace", "(", "r", ")", "&&", "r", "!=", "'='", "{", "keyRunes", "=", "append", "(", "keyRunes", ",", "r", ")", "\n", "if", "r", ",", "ok", "=", "s", ".", "Next", "(", ")", ";", "!", "ok", "{", "break", "\n", "}", "\n", "}", "\n\n", "// Skip any whitespace if we're not at the = yet", "if", "r", "!=", "'='", "{", "r", ",", "ok", "=", "s", ".", "SkipSpaces", "(", ")", "\n", "}", "\n\n", "// The current character should be =", "if", "r", "!=", "'='", "||", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", "`missing \"=\" after %q in connection info string\"`", ",", "string", "(", "keyRunes", ")", ")", "\n", "}", "\n\n", "// Skip any whitespace after the =", "if", "r", ",", "ok", "=", "s", ".", "SkipSpaces", "(", ")", ";", "!", "ok", "{", "// If we reach the end here, the last value is just an empty string as per libpq.", "o", "[", "string", "(", "keyRunes", ")", "]", "=", "\"", "\"", "\n", "break", "\n", "}", "\n\n", "if", "r", "!=", "'\\''", "{", "for", "!", "unicode", ".", "IsSpace", "(", "r", ")", "{", "if", "r", "==", "'\\\\'", "{", "if", "r", ",", "ok", "=", "s", ".", "Next", "(", ")", ";", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", "`missing character after backslash`", ")", "\n", "}", "\n", "}", "\n", "valRunes", "=", "append", "(", "valRunes", ",", "r", ")", "\n\n", "if", "r", ",", "ok", "=", "s", ".", "Next", "(", ")", ";", "!", "ok", "{", "break", "\n", "}", "\n", "}", "\n", "}", "else", "{", "quote", ":", "for", "{", "if", "r", ",", "ok", "=", "s", ".", "Next", "(", ")", ";", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", "`unterminated quoted string literal in connection string`", ")", "\n", "}", "\n", "switch", "r", "{", "case", "'\\''", ":", "break", "quote", "\n", "case", "'\\\\'", ":", "r", ",", "_", "=", "s", ".", "Next", "(", ")", "\n", "fallthrough", "\n", "default", ":", "valRunes", "=", "append", "(", "valRunes", ",", "r", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "o", "[", "string", "(", "keyRunes", ")", "]", "=", "string", "(", "valRunes", ")", "\n", "}", "\n\n", "return", "nil", "\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", "(", "\"", "\"", ")", "\n", "}", "\n", "str", ":=", "string", "(", "b", ")", "\n", "*", "i", "=", "strToInt", "(", "str", ")", "\n", "return", "nil", "\n", "}" ]
// Scan implements the sql.Scanner interface. // It allows to read the int slice from the database value.
[ "Scan", "implements", "the", "sql", ".", "Scanner", "interface", ".", "It", "allows", "to", "read", "the", "int", "slice", "from", "the", "database", "value", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/int.go#L22-L30
train
gobuffalo/pop
slices/int.go
Value
func (i Int) Value() (driver.Value, error) { sa := make([]string, len(i)) for x, v := range i { sa[x] = strconv.Itoa(v) } return fmt.Sprintf("{%s}", strings.Join(sa, ",")), nil }
go
func (i Int) Value() (driver.Value, error) { sa := make([]string, len(i)) for x, v := range i { sa[x] = strconv.Itoa(v) } return fmt.Sprintf("{%s}", strings.Join(sa, ",")), nil }
[ "func", "(", "i", "Int", ")", "Value", "(", ")", "(", "driver", ".", "Value", ",", "error", ")", "{", "sa", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "i", ")", ")", "\n", "for", "x", ",", "v", ":=", "range", "i", "{", "sa", "[", "x", "]", "=", "strconv", ".", "Itoa", "(", "v", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "sa", ",", "\"", "\"", ")", ")", ",", "nil", "\n", "}" ]
// 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", ")", ",", "\"", "\"", ")", "{", "f", ",", "err", ":=", "strconv", ".", "Atoi", "(", "x", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "ss", "=", "append", "(", "ss", ",", "f", ")", "\n", "}", "\n", "*", "i", "=", "ss", "\n", "return", "nil", "\n", "}" ]
// UnmarshalText will unmarshall text value into // the int slice representation of this value.
[ "UnmarshalText", "will", "unmarshall", "text", "value", "into", "the", "int", "slice", "representation", "of", "this", "value", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/slices/int.go#L44-L55
train
gobuffalo/pop
columns/columns_for_struct.go
ForStructWithAlias
func ForStructWithAlias(s interface{}, tableName string, tableAlias string) (columns Columns) { columns = NewColumnsWithAlias(tableName, tableAlias) defer func() { if r := recover(); r != nil { columns = NewColumnsWithAlias(tableName, tableAlias) columns.Add("*") } }() st := reflect.TypeOf(s) if st.Kind() == reflect.Ptr { st = st.Elem() } if st.Kind() == reflect.Slice { st = st.Elem() if st.Kind() == reflect.Ptr { st = st.Elem() } } fieldCount := st.NumField() for i := 0; i < fieldCount; i++ { field := st.Field(i) popTags := TagsFor(field) tag := popTags.Find("db") if !tag.Ignored() && !tag.Empty() { col := tag.Value // add writable or readable. tag := popTags.Find("rw") if !tag.Empty() { col = col + "," + tag.Value } cs := columns.Add(col) // add select clause. tag = popTags.Find("select") if !tag.Empty() { c := cs[0] c.SetSelectSQL(tag.Value) } } } return columns }
go
func ForStructWithAlias(s interface{}, tableName string, tableAlias string) (columns Columns) { columns = NewColumnsWithAlias(tableName, tableAlias) defer func() { if r := recover(); r != nil { columns = NewColumnsWithAlias(tableName, tableAlias) columns.Add("*") } }() st := reflect.TypeOf(s) if st.Kind() == reflect.Ptr { st = st.Elem() } if st.Kind() == reflect.Slice { st = st.Elem() if st.Kind() == reflect.Ptr { st = st.Elem() } } fieldCount := st.NumField() for i := 0; i < fieldCount; i++ { field := st.Field(i) popTags := TagsFor(field) tag := popTags.Find("db") if !tag.Ignored() && !tag.Empty() { col := tag.Value // add writable or readable. tag := popTags.Find("rw") if !tag.Empty() { col = col + "," + tag.Value } cs := columns.Add(col) // add select clause. tag = popTags.Find("select") if !tag.Empty() { c := cs[0] c.SetSelectSQL(tag.Value) } } } return columns }
[ "func", "ForStructWithAlias", "(", "s", "interface", "{", "}", ",", "tableName", "string", ",", "tableAlias", "string", ")", "(", "columns", "Columns", ")", "{", "columns", "=", "NewColumnsWithAlias", "(", "tableName", ",", "tableAlias", ")", "\n", "defer", "func", "(", ")", "{", "if", "r", ":=", "recover", "(", ")", ";", "r", "!=", "nil", "{", "columns", "=", "NewColumnsWithAlias", "(", "tableName", ",", "tableAlias", ")", "\n", "columns", ".", "Add", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "(", ")", "\n", "st", ":=", "reflect", ".", "TypeOf", "(", "s", ")", "\n", "if", "st", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "st", "=", "st", ".", "Elem", "(", ")", "\n", "}", "\n", "if", "st", ".", "Kind", "(", ")", "==", "reflect", ".", "Slice", "{", "st", "=", "st", ".", "Elem", "(", ")", "\n", "if", "st", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "st", "=", "st", ".", "Elem", "(", ")", "\n", "}", "\n", "}", "\n\n", "fieldCount", ":=", "st", ".", "NumField", "(", ")", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "fieldCount", ";", "i", "++", "{", "field", ":=", "st", ".", "Field", "(", "i", ")", "\n\n", "popTags", ":=", "TagsFor", "(", "field", ")", "\n", "tag", ":=", "popTags", ".", "Find", "(", "\"", "\"", ")", "\n\n", "if", "!", "tag", ".", "Ignored", "(", ")", "&&", "!", "tag", ".", "Empty", "(", ")", "{", "col", ":=", "tag", ".", "Value", "\n\n", "// add writable or readable.", "tag", ":=", "popTags", ".", "Find", "(", "\"", "\"", ")", "\n", "if", "!", "tag", ".", "Empty", "(", ")", "{", "col", "=", "col", "+", "\"", "\"", "+", "tag", ".", "Value", "\n", "}", "\n\n", "cs", ":=", "columns", ".", "Add", "(", "col", ")", "\n\n", "// add select clause.", "tag", "=", "popTags", ".", "Find", "(", "\"", "\"", ")", "\n", "if", "!", "tag", ".", "Empty", "(", ")", "{", "c", ":=", "cs", "[", "0", "]", "\n", "c", ".", "SetSelectSQL", "(", "tag", ".", "Value", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "columns", "\n", "}" ]
// 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", ":=", "&", "Paginator", "{", "Page", ":", "page", ",", "PerPage", ":", "perPage", "}", "\n", "p", ".", "Offset", "=", "(", "page", "-", "1", ")", "*", "p", ".", "PerPage", "\n", "return", "p", "\n", "}" ]
// NewPaginator returns a new `Paginator` value with the appropriate // defaults set.
[ "NewPaginator", "returns", "a", "new", "Paginator", "value", "with", "the", "appropriate", "defaults", "set", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/paginator.go#L55-L65
train
gobuffalo/pop
paginator.go
NewPaginatorFromParams
func NewPaginatorFromParams(params PaginationParams) *Paginator { page := defaults.String(params.Get("page"), "1") perPage := defaults.String(params.Get("per_page"), strconv.Itoa(PaginatorPerPageDefault)) p, err := strconv.Atoi(page) if err != nil { p = 1 } pp, err := strconv.Atoi(perPage) if err != nil { pp = PaginatorPerPageDefault } return NewPaginator(p, pp) }
go
func NewPaginatorFromParams(params PaginationParams) *Paginator { page := defaults.String(params.Get("page"), "1") perPage := defaults.String(params.Get("per_page"), strconv.Itoa(PaginatorPerPageDefault)) p, err := strconv.Atoi(page) if err != nil { p = 1 } pp, err := strconv.Atoi(perPage) if err != nil { pp = PaginatorPerPageDefault } return NewPaginator(p, pp) }
[ "func", "NewPaginatorFromParams", "(", "params", "PaginationParams", ")", "*", "Paginator", "{", "page", ":=", "defaults", ".", "String", "(", "params", ".", "Get", "(", "\"", "\"", ")", ",", "\"", "\"", ")", "\n\n", "perPage", ":=", "defaults", ".", "String", "(", "params", ".", "Get", "(", "\"", "\"", ")", ",", "strconv", ".", "Itoa", "(", "PaginatorPerPageDefault", ")", ")", "\n\n", "p", ",", "err", ":=", "strconv", ".", "Atoi", "(", "page", ")", "\n", "if", "err", "!=", "nil", "{", "p", "=", "1", "\n", "}", "\n\n", "pp", ",", "err", ":=", "strconv", ".", "Atoi", "(", "perPage", ")", "\n", "if", "err", "!=", "nil", "{", "pp", "=", "PaginatorPerPageDefault", "\n", "}", "\n", "return", "NewPaginator", "(", "p", ",", "pp", ")", "\n", "}" ]
// 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", "PaginatorPageKey", "and", "PaginatorPerPageKey", ".", "Defaults", "are", "1", "for", "the", "page", "and", "PaginatorPerPageDefault", "for", "the", "per", "page", "value", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/paginator.go#L77-L92
train
gobuffalo/pop
fix/anko.go
Anko
func Anko(content string) (string, error) { bb := &bytes.Buffer{} lines := strings.Split(content, "\n") l := len(lines) fre := regexp.MustCompile(`,\s*func\(t\)\s*{`) for i := 0; i < l; i++ { line := lines[i] tl := strings.TrimSpace(line) if strings.HasPrefix(tl, "create_table") { // skip already converted create_table if fre.MatchString(line) { // fix create_table line = fre.ReplaceAllString(line, ") {") ll := i lines[i] = line waitParen := false for { if strings.HasPrefix(tl, "})") { line = "}" + tl[2:] break } else if strings.HasPrefix(tl, "}") { // Now, we have to make sure to match the missing ")" waitParen = true } else if waitParen && strings.HasPrefix(tl, ")") { line = tl[1:] break } i++ if l == i { return "", fmt.Errorf("unclosed create_table statement line %d", ll+1) } line = lines[i] tl = strings.TrimSpace(line) } } } else if strings.HasPrefix(tl, "raw(") { // fix raw line = strings.Replace(line, "raw(", "sql(", -1) } lines[i] = line } body := strings.Join(lines, "\n") if _, err := plush.Parse(body); err != nil { return "", err } bb.WriteString(body) return bb.String(), nil }
go
func Anko(content string) (string, error) { bb := &bytes.Buffer{} lines := strings.Split(content, "\n") l := len(lines) fre := regexp.MustCompile(`,\s*func\(t\)\s*{`) for i := 0; i < l; i++ { line := lines[i] tl := strings.TrimSpace(line) if strings.HasPrefix(tl, "create_table") { // skip already converted create_table if fre.MatchString(line) { // fix create_table line = fre.ReplaceAllString(line, ") {") ll := i lines[i] = line waitParen := false for { if strings.HasPrefix(tl, "})") { line = "}" + tl[2:] break } else if strings.HasPrefix(tl, "}") { // Now, we have to make sure to match the missing ")" waitParen = true } else if waitParen && strings.HasPrefix(tl, ")") { line = tl[1:] break } i++ if l == i { return "", fmt.Errorf("unclosed create_table statement line %d", ll+1) } line = lines[i] tl = strings.TrimSpace(line) } } } else if strings.HasPrefix(tl, "raw(") { // fix raw line = strings.Replace(line, "raw(", "sql(", -1) } lines[i] = line } body := strings.Join(lines, "\n") if _, err := plush.Parse(body); err != nil { return "", err } bb.WriteString(body) return bb.String(), nil }
[ "func", "Anko", "(", "content", "string", ")", "(", "string", ",", "error", ")", "{", "bb", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n\n", "lines", ":=", "strings", ".", "Split", "(", "content", ",", "\"", "\\n", "\"", ")", "\n", "l", ":=", "len", "(", "lines", ")", "\n", "fre", ":=", "regexp", ".", "MustCompile", "(", "`,\\s*func\\(t\\)\\s*{`", ")", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "l", ";", "i", "++", "{", "line", ":=", "lines", "[", "i", "]", "\n", "tl", ":=", "strings", ".", "TrimSpace", "(", "line", ")", "\n", "if", "strings", ".", "HasPrefix", "(", "tl", ",", "\"", "\"", ")", "{", "// skip already converted create_table", "if", "fre", ".", "MatchString", "(", "line", ")", "{", "// fix create_table", "line", "=", "fre", ".", "ReplaceAllString", "(", "line", ",", "\"", "\"", ")", "\n", "ll", ":=", "i", "\n", "lines", "[", "i", "]", "=", "line", "\n", "waitParen", ":=", "false", "\n", "for", "{", "if", "strings", ".", "HasPrefix", "(", "tl", ",", "\"", "\"", ")", "{", "line", "=", "\"", "\"", "+", "tl", "[", "2", ":", "]", "\n", "break", "\n", "}", "else", "if", "strings", ".", "HasPrefix", "(", "tl", ",", "\"", "\"", ")", "{", "// Now, we have to make sure to match the missing \")\"", "waitParen", "=", "true", "\n", "}", "else", "if", "waitParen", "&&", "strings", ".", "HasPrefix", "(", "tl", ",", "\"", "\"", ")", "{", "line", "=", "tl", "[", "1", ":", "]", "\n", "break", "\n", "}", "\n", "i", "++", "\n", "if", "l", "==", "i", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ll", "+", "1", ")", "\n", "}", "\n", "line", "=", "lines", "[", "i", "]", "\n", "tl", "=", "strings", ".", "TrimSpace", "(", "line", ")", "\n", "}", "\n", "}", "\n", "}", "else", "if", "strings", ".", "HasPrefix", "(", "tl", ",", "\"", "\"", ")", "{", "// fix raw", "line", "=", "strings", ".", "Replace", "(", "line", ",", "\"", "\"", ",", "\"", "\"", ",", "-", "1", ")", "\n", "}", "\n", "lines", "[", "i", "]", "=", "line", "\n", "}", "\n\n", "body", ":=", "strings", ".", "Join", "(", "lines", ",", "\"", "\\n", "\"", ")", "\n\n", "if", "_", ",", "err", ":=", "plush", ".", "Parse", "(", "body", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "bb", ".", "WriteString", "(", "body", ")", "\n\n", "return", "bb", ".", "String", "(", ")", ",", "nil", "\n", "}" ]
// 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", "(", ")", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "xs", ")", "\n", "return", "strings", ".", "Join", "(", "xs", ",", "\"", "\"", ")", "\n", "}" ]
// 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", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "xs", ")", "\n", "return", "strings", ".", "Join", "(", "xs", ",", "\"", "\"", ")", "\n", "}" ]
// SelectString returns the SQL column list part of the SELECT // query.
[ "SelectString", "returns", "the", "SQL", "column", "list", "part", "of", "the", "SELECT", "query", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/columns/readable_columns.go#L15-L22
train
gobuffalo/pop
connection_details.go
withURL
func (cd *ConnectionDetails) withURL() error { ul := cd.URL if cd.Dialect == "" { if dialectX.MatchString(ul) { // Guess the dialect from the scheme dialect := ul[:strings.Index(ul, ":")] cd.Dialect = normalizeSynonyms(dialect) } else { return errors.New("no dialect provided, and could not guess it from URL") } } else if !dialectX.MatchString(ul) { ul = cd.Dialect + "://" + ul } if !DialectSupported(cd.Dialect) { return errors.Errorf("unsupported dialect '%s'", cd.Dialect) } // warning message is required to prevent confusion // even though this behavior was documented. if cd.Database+cd.Host+cd.Port+cd.User+cd.Password != "" { log(logging.Warn, "One or more of connection details are specified in database.yml. Override them with values in URL.") } if up, ok := urlParser[cd.Dialect]; ok { return up(cd) } // Fallback on generic parsing if no URL parser was found for the dialect. u, err := url.Parse(ul) if err != nil { return errors.Wrapf(err, "couldn't parse %s", ul) } cd.Database = strings.TrimPrefix(u.Path, "/") hp := strings.Split(u.Host, ":") cd.Host = hp[0] if len(hp) > 1 { cd.Port = hp[1] } if u.User != nil { cd.User = u.User.Username() cd.Password, _ = u.User.Password() } cd.RawOptions = u.RawQuery return nil }
go
func (cd *ConnectionDetails) withURL() error { ul := cd.URL if cd.Dialect == "" { if dialectX.MatchString(ul) { // Guess the dialect from the scheme dialect := ul[:strings.Index(ul, ":")] cd.Dialect = normalizeSynonyms(dialect) } else { return errors.New("no dialect provided, and could not guess it from URL") } } else if !dialectX.MatchString(ul) { ul = cd.Dialect + "://" + ul } if !DialectSupported(cd.Dialect) { return errors.Errorf("unsupported dialect '%s'", cd.Dialect) } // warning message is required to prevent confusion // even though this behavior was documented. if cd.Database+cd.Host+cd.Port+cd.User+cd.Password != "" { log(logging.Warn, "One or more of connection details are specified in database.yml. Override them with values in URL.") } if up, ok := urlParser[cd.Dialect]; ok { return up(cd) } // Fallback on generic parsing if no URL parser was found for the dialect. u, err := url.Parse(ul) if err != nil { return errors.Wrapf(err, "couldn't parse %s", ul) } cd.Database = strings.TrimPrefix(u.Path, "/") hp := strings.Split(u.Host, ":") cd.Host = hp[0] if len(hp) > 1 { cd.Port = hp[1] } if u.User != nil { cd.User = u.User.Username() cd.Password, _ = u.User.Password() } cd.RawOptions = u.RawQuery return nil }
[ "func", "(", "cd", "*", "ConnectionDetails", ")", "withURL", "(", ")", "error", "{", "ul", ":=", "cd", ".", "URL", "\n", "if", "cd", ".", "Dialect", "==", "\"", "\"", "{", "if", "dialectX", ".", "MatchString", "(", "ul", ")", "{", "// Guess the dialect from the scheme", "dialect", ":=", "ul", "[", ":", "strings", ".", "Index", "(", "ul", ",", "\"", "\"", ")", "]", "\n", "cd", ".", "Dialect", "=", "normalizeSynonyms", "(", "dialect", ")", "\n", "}", "else", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "else", "if", "!", "dialectX", ".", "MatchString", "(", "ul", ")", "{", "ul", "=", "cd", ".", "Dialect", "+", "\"", "\"", "+", "ul", "\n", "}", "\n\n", "if", "!", "DialectSupported", "(", "cd", ".", "Dialect", ")", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "cd", ".", "Dialect", ")", "\n", "}", "\n\n", "// warning message is required to prevent confusion", "// even though this behavior was documented.", "if", "cd", ".", "Database", "+", "cd", ".", "Host", "+", "cd", ".", "Port", "+", "cd", ".", "User", "+", "cd", ".", "Password", "!=", "\"", "\"", "{", "log", "(", "logging", ".", "Warn", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "up", ",", "ok", ":=", "urlParser", "[", "cd", ".", "Dialect", "]", ";", "ok", "{", "return", "up", "(", "cd", ")", "\n", "}", "\n\n", "// Fallback on generic parsing if no URL parser was found for the dialect.", "u", ",", "err", ":=", "url", ".", "Parse", "(", "ul", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "ul", ")", "\n", "}", "\n", "cd", ".", "Database", "=", "strings", ".", "TrimPrefix", "(", "u", ".", "Path", ",", "\"", "\"", ")", "\n\n", "hp", ":=", "strings", ".", "Split", "(", "u", ".", "Host", ",", "\"", "\"", ")", "\n", "cd", ".", "Host", "=", "hp", "[", "0", "]", "\n", "if", "len", "(", "hp", ")", ">", "1", "{", "cd", ".", "Port", "=", "hp", "[", "1", "]", "\n", "}", "\n\n", "if", "u", ".", "User", "!=", "nil", "{", "cd", ".", "User", "=", "u", ".", "User", ".", "Username", "(", ")", "\n", "cd", ".", "Password", ",", "_", "=", "u", ".", "User", ".", "Password", "(", ")", "\n", "}", "\n", "cd", ".", "RawOptions", "=", "u", ".", "RawQuery", "\n\n", "return", "nil", "\n", "}" ]
// withURL parses and overrides all connection details with values // from standard URL except Dialect. It also calls dialect specific // URL parser if exists.
[ "withURL", "parses", "and", "overrides", "all", "connection", "details", "with", "values", "from", "standard", "URL", "except", "Dialect", ".", "It", "also", "calls", "dialect", "specific", "URL", "parser", "if", "exists", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/connection_details.go#L52-L100
train
gobuffalo/pop
connection_details.go
Finalize
func (cd *ConnectionDetails) Finalize() error { cd.Dialect = normalizeSynonyms(cd.Dialect) if cd.Options == nil { // for safety cd.Options = make(map[string]string) } // Process the database connection string, if provided. if cd.URL != "" { if err := cd.withURL(); err != nil { return err } } if fin, ok := finalizer[cd.Dialect]; ok { fin(cd) } if DialectSupported(cd.Dialect) { if cd.Database != "" || cd.URL != "" { return nil } return errors.New("no database or URL specified") } return errors.Errorf("unsupported dialect '%v'", cd.Dialect) }
go
func (cd *ConnectionDetails) Finalize() error { cd.Dialect = normalizeSynonyms(cd.Dialect) if cd.Options == nil { // for safety cd.Options = make(map[string]string) } // Process the database connection string, if provided. if cd.URL != "" { if err := cd.withURL(); err != nil { return err } } if fin, ok := finalizer[cd.Dialect]; ok { fin(cd) } if DialectSupported(cd.Dialect) { if cd.Database != "" || cd.URL != "" { return nil } return errors.New("no database or URL specified") } return errors.Errorf("unsupported dialect '%v'", cd.Dialect) }
[ "func", "(", "cd", "*", "ConnectionDetails", ")", "Finalize", "(", ")", "error", "{", "cd", ".", "Dialect", "=", "normalizeSynonyms", "(", "cd", ".", "Dialect", ")", "\n\n", "if", "cd", ".", "Options", "==", "nil", "{", "// for safety", "cd", ".", "Options", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "}", "\n\n", "// Process the database connection string, if provided.", "if", "cd", ".", "URL", "!=", "\"", "\"", "{", "if", "err", ":=", "cd", ".", "withURL", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "if", "fin", ",", "ok", ":=", "finalizer", "[", "cd", ".", "Dialect", "]", ";", "ok", "{", "fin", "(", "cd", ")", "\n", "}", "\n\n", "if", "DialectSupported", "(", "cd", ".", "Dialect", ")", "{", "if", "cd", ".", "Database", "!=", "\"", "\"", "||", "cd", ".", "URL", "!=", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "cd", ".", "Dialect", ")", "\n", "}" ]
// 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", "[", "\"", "\"", "]", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "1", "*", "time", ".", "Millisecond", "\n", "}", "\n", "return", "d", "\n", "}" ]
// 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", "if", "err", "!=", "nil", "{", "return", "100", "\n", "}", "\n", "return", "i", "\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", "!=", "nil", "{", "for", "k", ",", "v", ":=", "range", "cd", ".", "Options", "{", "s", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ",", "k", ",", "v", ")", "\n", "}", "\n", "}", "\n", "return", "strings", ".", "TrimLeft", "(", "s", ",", "\"", "\"", ")", "\n", "}" ]
// OptionsString returns URL parameter encoded string from options.
[ "OptionsString", "returns", "URL", "parameter", "encoded", "string", "from", "options", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/connection_details.go#L163-L173
train
gobuffalo/pop
commands.go
DropDB
func DropDB(c *Connection) error { deets := c.Dialect.Details() if deets.Database != "" { log(logging.Info, fmt.Sprintf("drop %s (%s)", deets.Database, c.URL())) return errors.Wrapf(c.Dialect.DropDB(), "couldn't drop database %s", deets.Database) } return nil }
go
func DropDB(c *Connection) error { deets := c.Dialect.Details() if deets.Database != "" { log(logging.Info, fmt.Sprintf("drop %s (%s)", deets.Database, c.URL())) return errors.Wrapf(c.Dialect.DropDB(), "couldn't drop database %s", deets.Database) } return nil }
[ "func", "DropDB", "(", "c", "*", "Connection", ")", "error", "{", "deets", ":=", "c", ".", "Dialect", ".", "Details", "(", ")", "\n", "if", "deets", ".", "Database", "!=", "\"", "\"", "{", "log", "(", "logging", ".", "Info", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "deets", ".", "Database", ",", "c", ".", "URL", "(", ")", ")", ")", "\n", "return", "errors", ".", "Wrapf", "(", "c", ".", "Dialect", ".", "DropDB", "(", ")", ",", "\"", "\"", ",", "deets", ".", "Database", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DropDB drops an existing database, given a connection definition
[ "DropDB", "drops", "an", "existing", "database", "given", "a", "connection", "definition" ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/commands.go#L21-L28
train
gobuffalo/pop
columns/columns.go
Add
func (c *Columns) Add(names ...string) []*Column { var ret []*Column c.lock.Lock() tableAlias := c.TableAlias if tableAlias == "" { tableAlias = c.TableName } for _, name := range names { var xs []string var col *Column ss := "" //support for distinct xx, or distinct on (field) table.fields if strings.HasSuffix(name, ",r") || strings.HasSuffix(name, ",w") { xs = []string{name[0 : len(name)-2], name[len(name)-1:]} } else { xs = []string{name} } xs[0] = strings.TrimSpace(xs[0]) //eg: id id2 - select id as id2 // also distinct columnname // and distinct on (column1) column2 if strings.Contains(strings.ToUpper(xs[0]), " AS ") { //eg: select id as id2 i := strings.LastIndex(strings.ToUpper(xs[0]), " AS ") ss = xs[0] xs[0] = xs[0][i+4 : len(xs[0])] //get id2 } else if strings.Contains(xs[0], " ") { i := strings.LastIndex(name, " ") ss = xs[0] xs[0] = xs[0][i+1 : len(xs[0])] //get id2 } col = c.Cols[xs[0]] if col == nil { if ss == "" { ss = xs[0] if tableAlias != "" { ss = fmt.Sprintf("%s.%s", tableAlias, ss) } } col = &Column{ Name: xs[0], SelectSQL: ss, Readable: true, Writeable: true, } if len(xs) > 1 { if xs[1] == "r" { col.Writeable = false } else if xs[1] == "w" { col.Readable = false } } else if col.Name == "id" { col.Writeable = false } c.Cols[col.Name] = col } ret = append(ret, col) } c.lock.Unlock() return ret }
go
func (c *Columns) Add(names ...string) []*Column { var ret []*Column c.lock.Lock() tableAlias := c.TableAlias if tableAlias == "" { tableAlias = c.TableName } for _, name := range names { var xs []string var col *Column ss := "" //support for distinct xx, or distinct on (field) table.fields if strings.HasSuffix(name, ",r") || strings.HasSuffix(name, ",w") { xs = []string{name[0 : len(name)-2], name[len(name)-1:]} } else { xs = []string{name} } xs[0] = strings.TrimSpace(xs[0]) //eg: id id2 - select id as id2 // also distinct columnname // and distinct on (column1) column2 if strings.Contains(strings.ToUpper(xs[0]), " AS ") { //eg: select id as id2 i := strings.LastIndex(strings.ToUpper(xs[0]), " AS ") ss = xs[0] xs[0] = xs[0][i+4 : len(xs[0])] //get id2 } else if strings.Contains(xs[0], " ") { i := strings.LastIndex(name, " ") ss = xs[0] xs[0] = xs[0][i+1 : len(xs[0])] //get id2 } col = c.Cols[xs[0]] if col == nil { if ss == "" { ss = xs[0] if tableAlias != "" { ss = fmt.Sprintf("%s.%s", tableAlias, ss) } } col = &Column{ Name: xs[0], SelectSQL: ss, Readable: true, Writeable: true, } if len(xs) > 1 { if xs[1] == "r" { col.Writeable = false } else if xs[1] == "w" { col.Readable = false } } else if col.Name == "id" { col.Writeable = false } c.Cols[col.Name] = col } ret = append(ret, col) } c.lock.Unlock() return ret }
[ "func", "(", "c", "*", "Columns", ")", "Add", "(", "names", "...", "string", ")", "[", "]", "*", "Column", "{", "var", "ret", "[", "]", "*", "Column", "\n", "c", ".", "lock", ".", "Lock", "(", ")", "\n\n", "tableAlias", ":=", "c", ".", "TableAlias", "\n", "if", "tableAlias", "==", "\"", "\"", "{", "tableAlias", "=", "c", ".", "TableName", "\n", "}", "\n\n", "for", "_", ",", "name", ":=", "range", "names", "{", "var", "xs", "[", "]", "string", "\n", "var", "col", "*", "Column", "\n", "ss", ":=", "\"", "\"", "\n", "//support for distinct xx, or distinct on (field) table.fields", "if", "strings", ".", "HasSuffix", "(", "name", ",", "\"", "\"", ")", "||", "strings", ".", "HasSuffix", "(", "name", ",", "\"", "\"", ")", "{", "xs", "=", "[", "]", "string", "{", "name", "[", "0", ":", "len", "(", "name", ")", "-", "2", "]", ",", "name", "[", "len", "(", "name", ")", "-", "1", ":", "]", "}", "\n", "}", "else", "{", "xs", "=", "[", "]", "string", "{", "name", "}", "\n", "}", "\n\n", "xs", "[", "0", "]", "=", "strings", ".", "TrimSpace", "(", "xs", "[", "0", "]", ")", "\n", "//eg: id id2 - select id as id2", "// also distinct columnname", "// and distinct on (column1) column2", "if", "strings", ".", "Contains", "(", "strings", ".", "ToUpper", "(", "xs", "[", "0", "]", ")", ",", "\"", "\"", ")", "{", "//eg: select id as id2", "i", ":=", "strings", ".", "LastIndex", "(", "strings", ".", "ToUpper", "(", "xs", "[", "0", "]", ")", ",", "\"", "\"", ")", "\n", "ss", "=", "xs", "[", "0", "]", "\n", "xs", "[", "0", "]", "=", "xs", "[", "0", "]", "[", "i", "+", "4", ":", "len", "(", "xs", "[", "0", "]", ")", "]", "//get id2", "\n", "}", "else", "if", "strings", ".", "Contains", "(", "xs", "[", "0", "]", ",", "\"", "\"", ")", "{", "i", ":=", "strings", ".", "LastIndex", "(", "name", ",", "\"", "\"", ")", "\n", "ss", "=", "xs", "[", "0", "]", "\n", "xs", "[", "0", "]", "=", "xs", "[", "0", "]", "[", "i", "+", "1", ":", "len", "(", "xs", "[", "0", "]", ")", "]", "//get id2", "\n", "}", "\n\n", "col", "=", "c", ".", "Cols", "[", "xs", "[", "0", "]", "]", "\n", "if", "col", "==", "nil", "{", "if", "ss", "==", "\"", "\"", "{", "ss", "=", "xs", "[", "0", "]", "\n", "if", "tableAlias", "!=", "\"", "\"", "{", "ss", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "tableAlias", ",", "ss", ")", "\n", "}", "\n", "}", "\n\n", "col", "=", "&", "Column", "{", "Name", ":", "xs", "[", "0", "]", ",", "SelectSQL", ":", "ss", ",", "Readable", ":", "true", ",", "Writeable", ":", "true", ",", "}", "\n\n", "if", "len", "(", "xs", ")", ">", "1", "{", "if", "xs", "[", "1", "]", "==", "\"", "\"", "{", "col", ".", "Writeable", "=", "false", "\n", "}", "else", "if", "xs", "[", "1", "]", "==", "\"", "\"", "{", "col", ".", "Readable", "=", "false", "\n", "}", "\n", "}", "else", "if", "col", ".", "Name", "==", "\"", "\"", "{", "col", ".", "Writeable", "=", "false", "\n", "}", "\n\n", "c", ".", "Cols", "[", "col", ".", "Name", "]", "=", "col", "\n", "}", "\n", "ret", "=", "append", "(", "ret", ",", "col", ")", "\n", "}", "\n\n", "c", ".", "lock", ".", "Unlock", "(", ")", "\n", "return", "ret", "\n", "}" ]
// 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", "[", "0", "]", "\n", "delete", "(", "c", ".", "Cols", ",", "name", ")", "\n", "}", "\n", "}" ]
// 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", ":=", "range", "c", ".", "Cols", "{", "if", "col", ".", "Writeable", "{", "w", ".", "Cols", "[", "col", ".", "Name", "]", "=", "col", "\n", "}", "\n", "}", "\n", "return", "w", "\n", "}" ]
// 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", ":=", "range", "c", ".", "Cols", "{", "if", "col", ".", "Readable", "{", "w", ".", "Cols", "[", "col", ".", "Name", "]", "=", "col", "\n", "}", "\n", "}", "\n", "return", "w", "\n", "}" ]
// 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", "{", "}", ",", "TableName", ":", "tableName", ",", "TableAlias", ":", "tableAlias", ",", "}", "\n", "}" ]
// 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", "mf", ".", "Runner", "(", "mf", ",", "c", ")", "\n", "}" ]
// Run the migration. Returns an error if there is // no mf.Runner defined.
[ "Run", "the", "migration", ".", "Returns", "an", "error", "if", "there", "is", "no", "mf", ".", "Runner", "defined", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/migration_info.go#L25-L30
train
gobuffalo/pop
executors.go
Reload
func (c *Connection) Reload(model interface{}) error { sm := Model{Value: model} return sm.iterate(func(m *Model) error { return c.Find(m.Value, m.ID()) }) }
go
func (c *Connection) Reload(model interface{}) error { sm := Model{Value: model} return sm.iterate(func(m *Model) error { return c.Find(m.Value, m.ID()) }) }
[ "func", "(", "c", "*", "Connection", ")", "Reload", "(", "model", "interface", "{", "}", ")", "error", "{", "sm", ":=", "Model", "{", "Value", ":", "model", "}", "\n", "return", "sm", ".", "iterate", "(", "func", "(", "m", "*", "Model", ")", "error", "{", "return", "c", ".", "Find", "(", "m", ".", "Value", ",", "m", ".", "ID", "(", ")", ")", "\n", "}", ")", "\n", "}" ]
// 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", "log", "(", "logging", ".", "SQL", ",", "sql", ",", "args", "...", ")", "\n", "_", ",", "err", ":=", "q", ".", "Connection", ".", "Store", ".", "Exec", "(", "sql", ",", "args", "...", ")", "\n", "return", "err", "\n", "}", ")", "\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() return err }) }
go
func (q *Query) ExecWithCount() (int, error) { count := int64(0) return int(count), q.Connection.timeFunc("Exec", func() error { sql, args := q.ToSQL(nil) log(logging.SQL, sql, args...) result, err := q.Connection.Store.Exec(sql, args...) if err != nil { return err } count, err = result.RowsAffected() return err }) }
[ "func", "(", "q", "*", "Query", ")", "ExecWithCount", "(", ")", "(", "int", ",", "error", ")", "{", "count", ":=", "int64", "(", "0", ")", "\n", "return", "int", "(", "count", ")", ",", "q", ".", "Connection", ".", "timeFunc", "(", "\"", "\"", ",", "func", "(", ")", "error", "{", "sql", ",", "args", ":=", "q", ".", "ToSQL", "(", "nil", ")", "\n", "log", "(", "logging", ".", "SQL", ",", "sql", ",", "args", "...", ")", "\n", "result", ",", "err", ":=", "q", ".", "Connection", ".", "Store", ".", "Exec", "(", "sql", ",", "args", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "count", ",", "err", "=", "result", ".", "RowsAffected", "(", ")", "\n", "return", "err", "\n", "}", ")", "\n", "}" ]
// 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", ":", "model", "}", "\n", "verrs", ",", "err", ":=", "sm", ".", "validateSave", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "verrs", ",", "err", "\n", "}", "\n", "if", "verrs", ".", "HasAny", "(", ")", "{", "return", "verrs", ",", "nil", "\n", "}", "\n", "return", "verrs", ",", "c", ".", "Save", "(", "model", ",", "excludeColumns", "...", ")", "\n", "}" ]
// ValidateAndSave applies validation rules on the given entry, then save it // if the validation succeed, excluding the given columns.
[ "ValidateAndSave", "applies", "validation", "rules", "on", "the", "given", "entry", "then", "save", "it", "if", "the", "validation", "succeed", "excluding", "the", "given", "columns", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/executors.go#L50-L60
train
gobuffalo/pop
executors.go
IsZeroOfUnderlyingType
func IsZeroOfUnderlyingType(x interface{}) bool { return reflect.DeepEqual(x, reflect.Zero(reflect.TypeOf(x)).Interface()) }
go
func IsZeroOfUnderlyingType(x interface{}) bool { return reflect.DeepEqual(x, reflect.Zero(reflect.TypeOf(x)).Interface()) }
[ "func", "IsZeroOfUnderlyingType", "(", "x", "interface", "{", "}", ")", "bool", "{", "return", "reflect", ".", "DeepEqual", "(", "x", ",", "reflect", ".", "Zero", "(", "reflect", ".", "TypeOf", "(", "x", ")", ")", ".", "Interface", "(", ")", ")", "\n", "}" ]
// IsZeroOfUnderlyingType will check if the value of anything is the equal to the Zero value of that type.
[ "IsZeroOfUnderlyingType", "will", "check", "if", "the", "value", "of", "anything", "is", "the", "equal", "to", "the", "Zero", "value", "of", "that", "type", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/executors.go#L65-L67
train
gobuffalo/pop
executors.go
Save
func (c *Connection) Save(model interface{}, excludeColumns ...string) error { sm := &Model{Value: model} return sm.iterate(func(m *Model) error { id, err := m.fieldByName("ID") if err != nil { return err } if IsZeroOfUnderlyingType(id.Interface()) { return c.Create(m.Value, excludeColumns...) } return c.Update(m.Value, excludeColumns...) }) }
go
func (c *Connection) Save(model interface{}, excludeColumns ...string) error { sm := &Model{Value: model} return sm.iterate(func(m *Model) error { id, err := m.fieldByName("ID") if err != nil { return err } if IsZeroOfUnderlyingType(id.Interface()) { return c.Create(m.Value, excludeColumns...) } return c.Update(m.Value, excludeColumns...) }) }
[ "func", "(", "c", "*", "Connection", ")", "Save", "(", "model", "interface", "{", "}", ",", "excludeColumns", "...", "string", ")", "error", "{", "sm", ":=", "&", "Model", "{", "Value", ":", "model", "}", "\n", "return", "sm", ".", "iterate", "(", "func", "(", "m", "*", "Model", ")", "error", "{", "id", ",", "err", ":=", "m", ".", "fieldByName", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "IsZeroOfUnderlyingType", "(", "id", ".", "Interface", "(", ")", ")", "{", "return", "c", ".", "Create", "(", "m", ".", "Value", ",", "excludeColumns", "...", ")", "\n", "}", "\n", "return", "c", ".", "Update", "(", "m", ".", "Value", ",", "excludeColumns", "...", ")", "\n", "}", ")", "\n", "}" ]
// Save wraps the Create and Update methods. It executes a Create if no ID is provided with the entry; // or issues an Update otherwise.
[ "Save", "wraps", "the", "Create", "and", "Update", "methods", ".", "It", "executes", "a", "Create", "if", "no", "ID", "is", "provided", "with", "the", "entry", ";", "or", "issues", "an", "Update", "otherwise", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/executors.go#L71-L83
train
gobuffalo/pop
executors.go
ValidateAndCreate
func (c *Connection) ValidateAndCreate(model interface{}, excludeColumns ...string) (*validate.Errors, error) { sm := &Model{Value: model} verrs, err := sm.validateCreate(c) if err != nil { return verrs, err } if verrs.HasAny() { return verrs, nil } if c.eager { asos, err2 := associations.ForStruct(model, c.eagerFields...) if err2 != nil { return verrs, err2 } if len(asos) == 0 { c.disableEager() return verrs, c.Create(model, excludeColumns...) } before := asos.AssociationsBeforeCreatable() for index := range before { i := before[index].BeforeInterface() if i == nil { continue } sm := &Model{Value: i} verrs, err := sm.validateAndOnlyCreate(c) if err != nil || verrs.HasAny() { return verrs, err } } after := asos.AssociationsAfterCreatable() for index := range after { i := after[index].AfterInterface() if i == nil { continue } sm := &Model{Value: i} verrs, err := sm.validateAndOnlyCreate(c) if err != nil || verrs.HasAny() { return verrs, err } } sm := &Model{Value: model} verrs, err = sm.validateCreate(c) if err != nil || verrs.HasAny() { return verrs, err } } return verrs, c.Create(model, excludeColumns...) }
go
func (c *Connection) ValidateAndCreate(model interface{}, excludeColumns ...string) (*validate.Errors, error) { sm := &Model{Value: model} verrs, err := sm.validateCreate(c) if err != nil { return verrs, err } if verrs.HasAny() { return verrs, nil } if c.eager { asos, err2 := associations.ForStruct(model, c.eagerFields...) if err2 != nil { return verrs, err2 } if len(asos) == 0 { c.disableEager() return verrs, c.Create(model, excludeColumns...) } before := asos.AssociationsBeforeCreatable() for index := range before { i := before[index].BeforeInterface() if i == nil { continue } sm := &Model{Value: i} verrs, err := sm.validateAndOnlyCreate(c) if err != nil || verrs.HasAny() { return verrs, err } } after := asos.AssociationsAfterCreatable() for index := range after { i := after[index].AfterInterface() if i == nil { continue } sm := &Model{Value: i} verrs, err := sm.validateAndOnlyCreate(c) if err != nil || verrs.HasAny() { return verrs, err } } sm := &Model{Value: model} verrs, err = sm.validateCreate(c) if err != nil || verrs.HasAny() { return verrs, err } } return verrs, c.Create(model, excludeColumns...) }
[ "func", "(", "c", "*", "Connection", ")", "ValidateAndCreate", "(", "model", "interface", "{", "}", ",", "excludeColumns", "...", "string", ")", "(", "*", "validate", ".", "Errors", ",", "error", ")", "{", "sm", ":=", "&", "Model", "{", "Value", ":", "model", "}", "\n", "verrs", ",", "err", ":=", "sm", ".", "validateCreate", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "verrs", ",", "err", "\n", "}", "\n", "if", "verrs", ".", "HasAny", "(", ")", "{", "return", "verrs", ",", "nil", "\n", "}", "\n\n", "if", "c", ".", "eager", "{", "asos", ",", "err2", ":=", "associations", ".", "ForStruct", "(", "model", ",", "c", ".", "eagerFields", "...", ")", "\n\n", "if", "err2", "!=", "nil", "{", "return", "verrs", ",", "err2", "\n", "}", "\n\n", "if", "len", "(", "asos", ")", "==", "0", "{", "c", ".", "disableEager", "(", ")", "\n", "return", "verrs", ",", "c", ".", "Create", "(", "model", ",", "excludeColumns", "...", ")", "\n", "}", "\n\n", "before", ":=", "asos", ".", "AssociationsBeforeCreatable", "(", ")", "\n", "for", "index", ":=", "range", "before", "{", "i", ":=", "before", "[", "index", "]", ".", "BeforeInterface", "(", ")", "\n", "if", "i", "==", "nil", "{", "continue", "\n", "}", "\n\n", "sm", ":=", "&", "Model", "{", "Value", ":", "i", "}", "\n", "verrs", ",", "err", ":=", "sm", ".", "validateAndOnlyCreate", "(", "c", ")", "\n", "if", "err", "!=", "nil", "||", "verrs", ".", "HasAny", "(", ")", "{", "return", "verrs", ",", "err", "\n", "}", "\n", "}", "\n\n", "after", ":=", "asos", ".", "AssociationsAfterCreatable", "(", ")", "\n", "for", "index", ":=", "range", "after", "{", "i", ":=", "after", "[", "index", "]", ".", "AfterInterface", "(", ")", "\n", "if", "i", "==", "nil", "{", "continue", "\n", "}", "\n\n", "sm", ":=", "&", "Model", "{", "Value", ":", "i", "}", "\n", "verrs", ",", "err", ":=", "sm", ".", "validateAndOnlyCreate", "(", "c", ")", "\n", "if", "err", "!=", "nil", "||", "verrs", ".", "HasAny", "(", ")", "{", "return", "verrs", ",", "err", "\n", "}", "\n", "}", "\n\n", "sm", ":=", "&", "Model", "{", "Value", ":", "model", "}", "\n", "verrs", ",", "err", "=", "sm", ".", "validateCreate", "(", "c", ")", "\n", "if", "err", "!=", "nil", "||", "verrs", ".", "HasAny", "(", ")", "{", "return", "verrs", ",", "err", "\n", "}", "\n", "}", "\n\n", "return", "verrs", ",", "c", ".", "Create", "(", "model", ",", "excludeColumns", "...", ")", "\n", "}" ]
// 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", ":", "model", "}", "\n", "verrs", ",", "err", ":=", "sm", ".", "validateUpdate", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "verrs", ",", "err", "\n", "}", "\n", "if", "verrs", ".", "HasAny", "(", ")", "{", "return", "verrs", ",", "nil", "\n", "}", "\n", "return", "verrs", ",", "c", ".", "Update", "(", "model", ",", "excludeColumns", "...", ")", "\n", "}" ]
// ValidateAndUpdate applies validation rules on the given entry, then update it // if the validation succeed, excluding the given columns.
[ "ValidateAndUpdate", "applies", "validation", "rules", "on", "the", "given", "entry", "then", "update", "it", "if", "the", "validation", "succeed", "excluding", "the", "given", "columns", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/executors.go#L303-L313
train
gobuffalo/pop
executors.go
Update
func (c *Connection) Update(model interface{}, excludeColumns ...string) error { sm := &Model{Value: model} return sm.iterate(func(m *Model) error { return c.timeFunc("Update", func() error { var err error if err = m.beforeSave(c); err != nil { return err } if err = m.beforeUpdate(c); err != nil { return err } tn := m.TableName() cols := columns.ForStructWithAlias(model, tn, m.As) cols.Remove("id", "created_at") if tn == sm.TableName() { cols.Remove(excludeColumns...) } m.touchUpdatedAt() if err = c.Dialect.Update(c.Store, m, cols); err != nil { return err } if err = m.afterUpdate(c); err != nil { return err } return m.afterSave(c) }) }) }
go
func (c *Connection) Update(model interface{}, excludeColumns ...string) error { sm := &Model{Value: model} return sm.iterate(func(m *Model) error { return c.timeFunc("Update", func() error { var err error if err = m.beforeSave(c); err != nil { return err } if err = m.beforeUpdate(c); err != nil { return err } tn := m.TableName() cols := columns.ForStructWithAlias(model, tn, m.As) cols.Remove("id", "created_at") if tn == sm.TableName() { cols.Remove(excludeColumns...) } m.touchUpdatedAt() if err = c.Dialect.Update(c.Store, m, cols); err != nil { return err } if err = m.afterUpdate(c); err != nil { return err } return m.afterSave(c) }) }) }
[ "func", "(", "c", "*", "Connection", ")", "Update", "(", "model", "interface", "{", "}", ",", "excludeColumns", "...", "string", ")", "error", "{", "sm", ":=", "&", "Model", "{", "Value", ":", "model", "}", "\n", "return", "sm", ".", "iterate", "(", "func", "(", "m", "*", "Model", ")", "error", "{", "return", "c", ".", "timeFunc", "(", "\"", "\"", ",", "func", "(", ")", "error", "{", "var", "err", "error", "\n\n", "if", "err", "=", "m", ".", "beforeSave", "(", "c", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", "=", "m", ".", "beforeUpdate", "(", "c", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "tn", ":=", "m", ".", "TableName", "(", ")", "\n", "cols", ":=", "columns", ".", "ForStructWithAlias", "(", "model", ",", "tn", ",", "m", ".", "As", ")", "\n", "cols", ".", "Remove", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "if", "tn", "==", "sm", ".", "TableName", "(", ")", "{", "cols", ".", "Remove", "(", "excludeColumns", "...", ")", "\n", "}", "\n\n", "m", ".", "touchUpdatedAt", "(", ")", "\n\n", "if", "err", "=", "c", ".", "Dialect", ".", "Update", "(", "c", ".", "Store", ",", "m", ",", "cols", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", "=", "m", ".", "afterUpdate", "(", "c", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "m", ".", "afterSave", "(", "c", ")", "\n", "}", ")", "\n", "}", ")", "\n", "}" ]
// Update writes changes from an entry to the database, excluding the given columns. // It updates the `updated_at` column automatically.
[ "Update", "writes", "changes", "from", "an", "entry", "to", "the", "database", "excluding", "the", "given", "columns", ".", "It", "updates", "the", "updated_at", "column", "automatically", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/executors.go#L317-L350
train
gobuffalo/pop
executors.go
Destroy
func (c *Connection) Destroy(model interface{}) error { sm := &Model{Value: model} return sm.iterate(func(m *Model) error { return c.timeFunc("Destroy", func() error { var err error if err = m.beforeDestroy(c); err != nil { return err } if err = c.Dialect.Destroy(c.Store, m); err != nil { return err } return m.afterDestroy(c) }) }) }
go
func (c *Connection) Destroy(model interface{}) error { sm := &Model{Value: model} return sm.iterate(func(m *Model) error { return c.timeFunc("Destroy", func() error { var err error if err = m.beforeDestroy(c); err != nil { return err } if err = c.Dialect.Destroy(c.Store, m); err != nil { return err } return m.afterDestroy(c) }) }) }
[ "func", "(", "c", "*", "Connection", ")", "Destroy", "(", "model", "interface", "{", "}", ")", "error", "{", "sm", ":=", "&", "Model", "{", "Value", ":", "model", "}", "\n", "return", "sm", ".", "iterate", "(", "func", "(", "m", "*", "Model", ")", "error", "{", "return", "c", ".", "timeFunc", "(", "\"", "\"", ",", "func", "(", ")", "error", "{", "var", "err", "error", "\n\n", "if", "err", "=", "m", ".", "beforeDestroy", "(", "c", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", "=", "c", ".", "Dialect", ".", "Destroy", "(", "c", ".", "Store", ",", "m", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "m", ".", "afterDestroy", "(", "c", ")", "\n", "}", ")", "\n", "}", ")", "\n", "}" ]
// Destroy deletes a given entry from the database
[ "Destroy", "deletes", "a", "given", "entry", "from", "the", "database" ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/executors.go#L353-L369
train
gobuffalo/pop
soda/cmd/generate/model_cmd.go
Model
func Model(name string, opts map[string]interface{}, attributes []string) error { if strings.TrimSpace(name) == "" { return errors.New("model name can't be empty") } mt, found := opts["marshalType"].(string) if !found { return errors.New("marshalType option is required") } pp, found := opts["modelPath"].(string) if !found { return errors.New("modelPath option is required") } model, err := newModel(name, mt, pp) if err != nil { return errors.WithStack(err) } for _, def := range attributes { a, err := newAttribute(def, &model) if err != nil { return err } if err := model.addAttribute(a); err != nil { return err } } // Add a default UUID, if no custom ID is provided model.addID() if err := model.generateModelFile(); err != nil { return err } sm, found := opts["skipMigration"].(bool) if found && sm { return nil } p, found := opts["path"].(string) if !found { return errors.New("path option is required") } migrationT, found := opts["migrationType"].(string) if !found { return errors.New("migrationType option is required") } switch migrationT { case "sql": env, found := opts["env"].(string) if !found { return errors.New("env option is required") } err = model.generateSQL(p, env) default: err = model.generateFizz(p) } return err }
go
func Model(name string, opts map[string]interface{}, attributes []string) error { if strings.TrimSpace(name) == "" { return errors.New("model name can't be empty") } mt, found := opts["marshalType"].(string) if !found { return errors.New("marshalType option is required") } pp, found := opts["modelPath"].(string) if !found { return errors.New("modelPath option is required") } model, err := newModel(name, mt, pp) if err != nil { return errors.WithStack(err) } for _, def := range attributes { a, err := newAttribute(def, &model) if err != nil { return err } if err := model.addAttribute(a); err != nil { return err } } // Add a default UUID, if no custom ID is provided model.addID() if err := model.generateModelFile(); err != nil { return err } sm, found := opts["skipMigration"].(bool) if found && sm { return nil } p, found := opts["path"].(string) if !found { return errors.New("path option is required") } migrationT, found := opts["migrationType"].(string) if !found { return errors.New("migrationType option is required") } switch migrationT { case "sql": env, found := opts["env"].(string) if !found { return errors.New("env option is required") } err = model.generateSQL(p, env) default: err = model.generateFizz(p) } return err }
[ "func", "Model", "(", "name", "string", ",", "opts", "map", "[", "string", "]", "interface", "{", "}", ",", "attributes", "[", "]", "string", ")", "error", "{", "if", "strings", ".", "TrimSpace", "(", "name", ")", "==", "\"", "\"", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "mt", ",", "found", ":=", "opts", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "if", "!", "found", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "pp", ",", "found", ":=", "opts", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "if", "!", "found", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "model", ",", "err", ":=", "newModel", "(", "name", ",", "mt", ",", "pp", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "for", "_", ",", "def", ":=", "range", "attributes", "{", "a", ",", "err", ":=", "newAttribute", "(", "def", ",", "&", "model", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", ":=", "model", ".", "addAttribute", "(", "a", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Add a default UUID, if no custom ID is provided", "model", ".", "addID", "(", ")", "\n\n", "if", "err", ":=", "model", ".", "generateModelFile", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "sm", ",", "found", ":=", "opts", "[", "\"", "\"", "]", ".", "(", "bool", ")", "\n", "if", "found", "&&", "sm", "{", "return", "nil", "\n", "}", "\n\n", "p", ",", "found", ":=", "opts", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "if", "!", "found", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "migrationT", ",", "found", ":=", "opts", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "if", "!", "found", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "switch", "migrationT", "{", "case", "\"", "\"", ":", "env", ",", "found", ":=", "opts", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "if", "!", "found", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "err", "=", "model", ".", "generateSQL", "(", "p", ",", "env", ")", "\n", "default", ":", "err", "=", "model", ".", "generateFizz", "(", "p", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// Model generates new model files to work with pop.
[ "Model", "generates", "new", "model", "files", "to", "work", "with", "pop", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/soda/cmd/generate/model_cmd.go#L49-L110
train
gobuffalo/pop
genny/config/config.go
New
func New(opts *Options) (*genny.Generator, error) { g := genny.New() if err := opts.Validate(); err != nil { return g, errors.WithStack(err) } f, err := templates.Open(opts.Dialect + ".yml.tmpl") if err != nil { return g, errors.Errorf("unable to find database.yml template for dialect %s", opts.Dialect) } name := filepath.Join(opts.Root, opts.FileName+".tmpl") gf := genny.NewFile(name, f) g.File(gf) data := map[string]interface{}{ "opts": opts, } t := gogen.TemplateTransformer(data, gogen.TemplateHelpers) g.Transformer(t) g.Transformer(genny.Dot()) return g, nil }
go
func New(opts *Options) (*genny.Generator, error) { g := genny.New() if err := opts.Validate(); err != nil { return g, errors.WithStack(err) } f, err := templates.Open(opts.Dialect + ".yml.tmpl") if err != nil { return g, errors.Errorf("unable to find database.yml template for dialect %s", opts.Dialect) } name := filepath.Join(opts.Root, opts.FileName+".tmpl") gf := genny.NewFile(name, f) g.File(gf) data := map[string]interface{}{ "opts": opts, } t := gogen.TemplateTransformer(data, gogen.TemplateHelpers) g.Transformer(t) g.Transformer(genny.Dot()) return g, nil }
[ "func", "New", "(", "opts", "*", "Options", ")", "(", "*", "genny", ".", "Generator", ",", "error", ")", "{", "g", ":=", "genny", ".", "New", "(", ")", "\n", "if", "err", ":=", "opts", ".", "Validate", "(", ")", ";", "err", "!=", "nil", "{", "return", "g", ",", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n\n", "f", ",", "err", ":=", "templates", ".", "Open", "(", "opts", ".", "Dialect", "+", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "g", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "opts", ".", "Dialect", ")", "\n", "}", "\n\n", "name", ":=", "filepath", ".", "Join", "(", "opts", ".", "Root", ",", "opts", ".", "FileName", "+", "\"", "\"", ")", "\n", "gf", ":=", "genny", ".", "NewFile", "(", "name", ",", "f", ")", "\n", "g", ".", "File", "(", "gf", ")", "\n\n", "data", ":=", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "opts", ",", "}", "\n\n", "t", ":=", "gogen", ".", "TemplateTransformer", "(", "data", ",", "gogen", ".", "TemplateHelpers", ")", "\n", "g", ".", "Transformer", "(", "t", ")", "\n", "g", ".", "Transformer", "(", "genny", ".", "Dot", "(", ")", ")", "\n\n", "return", "g", ",", "nil", "\n", "}" ]
// New generator to create a database.yml file
[ "New", "generator", "to", "create", "a", "database", ".", "yml", "file" ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/genny/config/config.go#L15-L39
train
gobuffalo/pop
query_groups.go
GroupBy
func (q *Query) GroupBy(field string, fields ...string) *Query { if q.RawSQL.Fragment != "" { log(logging.Warn, "Query is setup to use raw SQL") return q } q.groupClauses = append(q.groupClauses, GroupClause{field}) if len(fields) > 0 { for i := range fields { q.groupClauses = append(q.groupClauses, GroupClause{fields[i]}) } } return q }
go
func (q *Query) GroupBy(field string, fields ...string) *Query { if q.RawSQL.Fragment != "" { log(logging.Warn, "Query is setup to use raw SQL") return q } q.groupClauses = append(q.groupClauses, GroupClause{field}) if len(fields) > 0 { for i := range fields { q.groupClauses = append(q.groupClauses, GroupClause{fields[i]}) } } return q }
[ "func", "(", "q", "*", "Query", ")", "GroupBy", "(", "field", "string", ",", "fields", "...", "string", ")", "*", "Query", "{", "if", "q", ".", "RawSQL", ".", "Fragment", "!=", "\"", "\"", "{", "log", "(", "logging", ".", "Warn", ",", "\"", "\"", ")", "\n", "return", "q", "\n", "}", "\n", "q", ".", "groupClauses", "=", "append", "(", "q", ".", "groupClauses", ",", "GroupClause", "{", "field", "}", ")", "\n", "if", "len", "(", "fields", ")", ">", "0", "{", "for", "i", ":=", "range", "fields", "{", "q", ".", "groupClauses", "=", "append", "(", "q", ".", "groupClauses", ",", "GroupClause", "{", "fields", "[", "i", "]", "}", ")", "\n", "}", "\n", "}", "\n", "return", "q", "\n", "}" ]
// 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", "{", "}", "{", "h", ".", "ownerID", "}", "\n", "}" ]
// 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", "(", ")", "==", "reflect", ".", "Ptr", "{", "return", "m", ".", "Interface", "(", ")", "\n", "}", "\n", "if", "IsZeroOfUnderlyingType", "(", "m", ".", "Interface", "(", ")", ")", "{", "return", "nil", "\n", "}", "\n\n", "return", "m", ".", "Addr", "(", ")", ".", "Interface", "(", ")", "\n", "}" ]
// 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", "[", "string", "]", "*", "Connection", "{", "}", "\n", "log", "(", "logging", ".", "Debug", ",", "\"", "\"", ",", "path", ")", "\n", "f", ",", "err", ":=", "os", ".", "Open", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "LoadFrom", "(", "f", ")", "\n", "}" ]
// 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", ",", "d", ":=", "range", "deets", "{", "con", ",", "err", ":=", "NewConnection", "(", "d", ")", "\n", "if", "err", "!=", "nil", "{", "log", "(", "logging", ".", "Warn", ",", "\"", "\"", ",", "n", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "Connections", "[", "n", "]", "=", "con", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// LoadFrom reads a configuration from the reader and sets up the connections
[ "LoadFrom", "reads", "a", "configuration", "from", "the", "reader", "and", "sets", "up", "the", "connections" ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/config.go#L76-L91
train
gobuffalo/pop
config.go
ParseConfig
func ParseConfig(r io.Reader) (map[string]*ConnectionDetails, error) { tmpl := template.New("test") tmpl.Funcs(map[string]interface{}{ "envOr": func(s1, s2 string) string { return envy.Get(s1, s2) }, "env": func(s1 string) string { return envy.Get(s1, "") }, }) b, err := ioutil.ReadAll(r) if err != nil { return nil, errors.WithStack(err) } t, err := tmpl.Parse(string(b)) if err != nil { return nil, errors.Wrap(err, "couldn't parse config template") } var bb bytes.Buffer err = t.Execute(&bb, nil) if err != nil { return nil, errors.Wrap(err, "couldn't execute config template") } deets := map[string]*ConnectionDetails{} err = yaml.Unmarshal(bb.Bytes(), &deets) return deets, errors.Wrap(err, "couldn't unmarshal config to yaml") }
go
func ParseConfig(r io.Reader) (map[string]*ConnectionDetails, error) { tmpl := template.New("test") tmpl.Funcs(map[string]interface{}{ "envOr": func(s1, s2 string) string { return envy.Get(s1, s2) }, "env": func(s1 string) string { return envy.Get(s1, "") }, }) b, err := ioutil.ReadAll(r) if err != nil { return nil, errors.WithStack(err) } t, err := tmpl.Parse(string(b)) if err != nil { return nil, errors.Wrap(err, "couldn't parse config template") } var bb bytes.Buffer err = t.Execute(&bb, nil) if err != nil { return nil, errors.Wrap(err, "couldn't execute config template") } deets := map[string]*ConnectionDetails{} err = yaml.Unmarshal(bb.Bytes(), &deets) return deets, errors.Wrap(err, "couldn't unmarshal config to yaml") }
[ "func", "ParseConfig", "(", "r", "io", ".", "Reader", ")", "(", "map", "[", "string", "]", "*", "ConnectionDetails", ",", "error", ")", "{", "tmpl", ":=", "template", ".", "New", "(", "\"", "\"", ")", "\n", "tmpl", ".", "Funcs", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "func", "(", "s1", ",", "s2", "string", ")", "string", "{", "return", "envy", ".", "Get", "(", "s1", ",", "s2", ")", "\n", "}", ",", "\"", "\"", ":", "func", "(", "s1", "string", ")", "string", "{", "return", "envy", ".", "Get", "(", "s1", ",", "\"", "\"", ")", "\n", "}", ",", "}", ")", "\n", "b", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "t", ",", "err", ":=", "tmpl", ".", "Parse", "(", "string", "(", "b", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "var", "bb", "bytes", ".", "Buffer", "\n", "err", "=", "t", ".", "Execute", "(", "&", "bb", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "deets", ":=", "map", "[", "string", "]", "*", "ConnectionDetails", "{", "}", "\n", "err", "=", "yaml", ".", "Unmarshal", "(", "bb", ".", "Bytes", "(", ")", ",", "&", "deets", ")", "\n", "return", "deets", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}" ]
// 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", "[", "i", "]", ".", "(", "AssociationBeforeCreatable", ")", ";", "ok", "{", "before", "=", "append", "(", "before", ",", "a", "[", "i", "]", ".", "(", "AssociationBeforeCreatable", ")", ")", "\n", "}", "\n", "}", "\n", "return", "before", "\n", "}" ]
// 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", "[", "i", "]", ".", "(", "AssociationAfterCreatable", ")", ";", "ok", "{", "after", "=", "append", "(", "after", ",", "a", "[", "i", "]", ".", "(", "AssociationAfterCreatable", ")", ")", "\n", "}", "\n", "}", "\n", "return", "after", "\n", "}" ]
// 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", ":=", "a", "[", "i", "]", ".", "(", "AssociationCreatableStatement", ")", ";", "ok", "{", "stm", "=", "append", "(", "stm", ",", "a", "[", "i", "]", ".", "(", "AssociationCreatableStatement", ")", ")", "\n", "}", "\n", "}", "\n", "return", "stm", "\n", "}" ]
// 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", "}", "\n", "if", "f", ".", "Kind", "(", ")", "==", "reflect", ".", "Interface", "||", "f", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "return", "f", ".", "IsNil", "(", ")", "\n", "}", "\n", "return", "f", ".", "Interface", "(", ")", "==", "nil", "\n", "}" ]
// fieldIsNil validates if a field has a nil reference. Also // it validates if a field implements nullable interface and // it has a nil value.
[ "fieldIsNil", "validates", "if", "a", "field", "has", "a", "nil", "reference", ".", "Also", "it", "validates", "if", "a", "field", "implements", "nullable", "interface", "and", "it", "has", "a", "nil", "value", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/associations/association.go#L151-L159
train
gobuffalo/pop
connection.go
NewConnection
func NewConnection(deets *ConnectionDetails) (*Connection, error) { err := deets.Finalize() if err != nil { return nil, errors.WithStack(err) } c := &Connection{ ID: randx.String(30), } if nc, ok := newConnection[deets.Dialect]; ok { c.Dialect, err = nc(deets) if err != nil { return c, errors.Wrap(err, "could not create new connection") } return c, nil } return nil, errors.Errorf("could not found connection creator for %v", deets.Dialect) }
go
func NewConnection(deets *ConnectionDetails) (*Connection, error) { err := deets.Finalize() if err != nil { return nil, errors.WithStack(err) } c := &Connection{ ID: randx.String(30), } if nc, ok := newConnection[deets.Dialect]; ok { c.Dialect, err = nc(deets) if err != nil { return c, errors.Wrap(err, "could not create new connection") } return c, nil } return nil, errors.Errorf("could not found connection creator for %v", deets.Dialect) }
[ "func", "NewConnection", "(", "deets", "*", "ConnectionDetails", ")", "(", "*", "Connection", ",", "error", ")", "{", "err", ":=", "deets", ".", "Finalize", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "c", ":=", "&", "Connection", "{", "ID", ":", "randx", ".", "String", "(", "30", ")", ",", "}", "\n\n", "if", "nc", ",", "ok", ":=", "newConnection", "[", "deets", ".", "Dialect", "]", ";", "ok", "{", "c", ".", "Dialect", ",", "err", "=", "nc", "(", "deets", ")", "\n", "if", "err", "!=", "nil", "{", "return", "c", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "c", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "deets", ".", "Dialect", ")", "\n", "}" ]
// NewConnection creates a new connection, and sets it's `Dialect` // appropriately based on the `ConnectionDetails` passed into it.
[ "NewConnection", "creates", "a", "new", "connection", "and", "sets", "it", "s", "Dialect", "appropriately", "based", "on", "the", "ConnectionDetails", "passed", "into", "it", "." ]
9eeaaa184b5e2f2d98ba1a306447621f64bc1826
https://github.com/gobuffalo/pop/blob/9eeaaa184b5e2f2d98ba1a306447621f64bc1826/connection.go#L48-L65
train
gobuffalo/pop
connection.go
Connect
func Connect(e string) (*Connection, error) { if len(Connections) == 0 { err := LoadConfigFile() if err != nil { return nil, errors.WithStack(err) } } e = defaults.String(e, "development") c := Connections[e] if c == nil { return c, errors.Errorf("could not find connection named %s", e) } err := c.Open() return c, errors.Wrapf(err, "couldn't open connection for %s", e) }
go
func Connect(e string) (*Connection, error) { if len(Connections) == 0 { err := LoadConfigFile() if err != nil { return nil, errors.WithStack(err) } } e = defaults.String(e, "development") c := Connections[e] if c == nil { return c, errors.Errorf("could not find connection named %s", e) } err := c.Open() return c, errors.Wrapf(err, "couldn't open connection for %s", e) }
[ "func", "Connect", "(", "e", "string", ")", "(", "*", "Connection", ",", "error", ")", "{", "if", "len", "(", "Connections", ")", "==", "0", "{", "err", ":=", "LoadConfigFile", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "}", "\n", "e", "=", "defaults", ".", "String", "(", "e", ",", "\"", "\"", ")", "\n", "c", ":=", "Connections", "[", "e", "]", "\n", "if", "c", "==", "nil", "{", "return", "c", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "e", ")", "\n", "}", "\n", "err", ":=", "c", ".", "Open", "(", ")", "\n", "return", "c", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "e", ")", "\n", "}" ]
// Connect takes the name of a connection, default is "development", and will // return that connection from the available `Connections`. If a connection with // that name can not be found an error will be returned. If a connection is // found, and it has yet to open a connection with its underlying datastore, // a connection to that store will be opened.
[ "Connect", "takes", "the", "name", "of", "a", "connection", "default", "is", "development", "and", "will", "return", "that", "connection", "from", "the", "available", "Connections", ".", "If", "a", "connection", "with", "that", "name", "can", "not", "be", "found", "an", "error", "will", "be", "returned", ".", "If", "a", "connection", "is", "found", "and", "it", "has", "yet", "to", "open", "a", "connection", "with", "its", "underlying", "datastore", "a", "connection", "to", "that", "store", "will", "be", "opened", "." ]
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") } db.SetMaxOpenConns(details.Pool) db.SetMaxIdleConns(details.IdlePool) c.Store = &dB{db} if d, ok := c.Dialect.(afterOpenable); ok { err = d.AfterOpen(c) if err != nil { c.Store = 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") } db.SetMaxOpenConns(details.Pool) db.SetMaxIdleConns(details.IdlePool) c.Store = &dB{db} if d, ok := c.Dialect.(afterOpenable); ok { err = d.AfterOpen(c) if err != nil { c.Store = 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", "(", "\"", "\"", ")", "\n", "}", "\n", "details", ":=", "c", ".", "Dialect", ".", "Details", "(", ")", "\n", "db", ",", "err", ":=", "sqlx", ".", "Open", "(", "details", ".", "Dialect", ",", "c", ".", "Dialect", ".", "URL", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "db", ".", "SetMaxOpenConns", "(", "details", ".", "Pool", ")", "\n", "db", ".", "SetMaxIdleConns", "(", "details", ".", "IdlePool", ")", "\n", "c", ".", "Store", "=", "&", "dB", "{", "db", "}", "\n\n", "if", "d", ",", "ok", ":=", "c", ".", "Dialect", ".", "(", "afterOpenable", ")", ";", "ok", "{", "err", "=", "d", ".", "AfterOpen", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "c", ".", "Store", "=", "nil", "\n", "}", "\n", "}", "\n", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}" ]
// 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 { return errors.WithStack(err) } return errors.Wrap(dberr, "error committing or rolling back transaction") }) }
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 { return errors.WithStack(err) } return errors.Wrap(dberr, "error committing or rolling back transaction") }) }
[ "func", "(", "c", "*", "Connection", ")", "Transaction", "(", "fn", "func", "(", "tx", "*", "Connection", ")", "error", ")", "error", "{", "return", "c", ".", "Dialect", ".", "Lock", "(", "func", "(", ")", "error", "{", "var", "dberr", "error", "\n", "cn", ",", "err", ":=", "c", ".", "NewTransaction", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "fn", "(", "cn", ")", "\n", "if", "err", "!=", "nil", "{", "dberr", "=", "cn", ".", "TX", ".", "Rollback", "(", ")", "\n", "}", "else", "{", "dberr", "=", "cn", ".", "TX", ".", "Commit", "(", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "WithStack", "(", "err", ")", "\n", "}", "\n", "return", "errors", ".", "Wrap", "(", "dberr", ",", "\"", "\"", ")", "\n", "}", ")", "\n\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", "automatically", "commit", "at", "the", "end", "." ]
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", "}", "\n", "fn", "(", "cn", ")", "\n", "return", "cn", ".", "TX", ".", "Rollback", "(", ")", "\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: tx, } } else { cn = c } return cn, nil }
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: tx, } } else { cn = c } return cn, nil }
[ "func", "(", "c", "*", "Connection", ")", "NewTransaction", "(", ")", "(", "*", "Connection", ",", "error", ")", "{", "var", "cn", "*", "Connection", "\n", "if", "c", ".", "TX", "==", "nil", "{", "tx", ",", "err", ":=", "c", ".", "Store", ".", "Transaction", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "cn", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "cn", "=", "&", "Connection", "{", "ID", ":", "randx", ".", "String", "(", "30", ")", ",", "Store", ":", "tx", ",", "Dialect", ":", "c", ".", "Dialect", ",", "TX", ":", "tx", ",", "}", "\n", "}", "else", "{", "cn", "=", "c", "\n", "}", "\n", "return", "cn", ",", "nil", "\n", "}" ]
// 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", "{", "}", "\n", "}" ]
// 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", ".", "Tag", ".", "Get", "(", "tag", ")", ";", "valTag", "!=", "\"", "\"", "{", "pTags", "=", "append", "(", "pTags", ",", "Tag", "{", "valTag", ",", "tag", "}", ")", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "pTags", ")", "==", "0", "{", "pTags", "=", "append", "(", "pTags", ",", "Tag", "{", "field", ".", "Name", ",", "\"", "\"", "}", ")", "\n", "}", "\n", "return", "pTags", "\n", "}" ]
// 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", "(", "ss", ")", "\n", "return", "err", "\n", "}" ]
// 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", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "*", "s", "=", "String", "(", "ss", ")", "\n", "return", "nil", "\n", "}" ]
// 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", "for", "{", "record", ",", "err", ":=", "r", ".", "Read", "(", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "break", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "words", "=", "append", "(", "words", ",", "record", "...", ")", "\n", "}", "\n\n", "*", "s", "=", "String", "(", "words", ")", "\n", "return", "nil", "\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", ",", "packageName", ":", "pkg", ",", "}", "\n", "return", "p", ".", "parseTemplate", "(", ")", "\n", "}" ]
// 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", "package", "name", "." ]
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", "=", "&", "htmlEscapeWriter", "{", "}", "\n", "v", "=", "qw", "\n", "}", "\n", "qw", ":=", "v", ".", "(", "*", "Writer", ")", "\n", "qw", ".", "e", ".", "w", ".", "(", "*", "htmlEscapeWriter", ")", ".", "w", "=", "w", "\n", "qw", ".", "n", ".", "w", "=", "w", "\n", "return", "qw", "\n", "}" ]
// 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", ".", "w", "=", "hw", "\n\n", "qw", ".", "n", ".", "Reset", "(", ")", "\n\n", "writerPool", ".", "Put", "(", "qw", ")", "\n", "}" ]
// 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", ",", "int64", "(", "n", ")", ",", "10", ")", "\n", "}", "else", "{", "w", ".", "b", "=", "strconv", ".", "AppendInt", "(", "w", ".", "b", "[", ":", "0", "]", ",", "int64", "(", "n", ")", ",", "10", ")", "\n", "w", ".", "Write", "(", "w", ".", "b", ")", "\n", "}", "\n", "}" ]
// 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", "}", "\n\n", "// Slow path.", "w", ".", "FPrec", "(", "f", ",", "-", "1", ")", "\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", ".", "AppendFloat", "(", "bb", ".", "B", ",", "f", ",", "'f'", ",", "prec", ",", "64", ")", "\n", "}", "else", "{", "w", ".", "b", "=", "strconv", ".", "AppendFloat", "(", "w", ".", "b", "[", ":", "0", "]", ",", "f", ",", "'f'", ",", "prec", ",", "64", ")", "\n", "w", ".", "Write", "(", "w", ".", "b", ")", "\n", "}", "\n", "}" ]
// 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", ")", "\n", "}", "else", "{", "w", ".", "b", "=", "appendURLEncode", "(", "w", ".", "b", "[", ":", "0", "]", ",", "s", ")", "\n", "w", ".", "Write", "(", "w", ".", "b", ")", "\n", "}", "\n", "}" ]
// 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 = v case int, int32, int64: val := reflect.ValueOf(v).Convert(reflect.TypeOf(param)).Int() // if param is negative casting to uint64 will wrap around and // give you the hugest thread limit ever. Let's be sensible, here if val > 0 { limit = uint64(val) } else { limit = min } case uint, uint32: limit = reflect.ValueOf(v).Convert(reflect.TypeOf(param)).Uint() case nil: // use the default default: return 0, fmt.Errorf("invalid value '%#v'", param) } if limit < min { return min, nil } return limit, nil }
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 = v case int, int32, int64: val := reflect.ValueOf(v).Convert(reflect.TypeOf(param)).Int() // if param is negative casting to uint64 will wrap around and // give you the hugest thread limit ever. Let's be sensible, here if val > 0 { limit = uint64(val) } else { limit = min } case uint, uint32: limit = reflect.ValueOf(v).Convert(reflect.TypeOf(param)).Uint() case nil: // use the default default: return 0, fmt.Errorf("invalid value '%#v'", param) } if limit < min { return min, nil } return limit, nil }
[ "func", "GetLimitFromParameter", "(", "param", "interface", "{", "}", ",", "min", ",", "def", "uint64", ")", "(", "uint64", ",", "error", ")", "{", "limit", ":=", "def", "\n\n", "switch", "v", ":=", "param", ".", "(", "type", ")", "{", "case", "string", ":", "var", "err", "error", "\n", "if", "limit", ",", "err", "=", "strconv", ".", "ParseUint", "(", "v", ",", "0", ",", "64", ")", ";", "err", "!=", "nil", "{", "return", "limit", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "param", ")", "\n", "}", "\n", "case", "uint64", ":", "limit", "=", "v", "\n", "case", "int", ",", "int32", ",", "int64", ":", "val", ":=", "reflect", ".", "ValueOf", "(", "v", ")", ".", "Convert", "(", "reflect", ".", "TypeOf", "(", "param", ")", ")", ".", "Int", "(", ")", "\n", "// if param is negative casting to uint64 will wrap around and", "// give you the hugest thread limit ever. Let's be sensible, here", "if", "val", ">", "0", "{", "limit", "=", "uint64", "(", "val", ")", "\n", "}", "else", "{", "limit", "=", "min", "\n", "}", "\n", "case", "uint", ",", "uint32", ":", "limit", "=", "reflect", ".", "ValueOf", "(", "v", ")", ".", "Convert", "(", "reflect", ".", "TypeOf", "(", "param", ")", ")", ".", "Uint", "(", ")", "\n", "case", "nil", ":", "// use the default", "default", ":", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "param", ")", "\n", "}", "\n\n", "if", "limit", "<", "min", "{", "return", "min", ",", "nil", "\n", "}", "\n\n", "return", "limit", ",", "nil", "\n", "}" ]
// 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", "default", ".", "If", "the", "parameter", "supplied", "is", "of", "an", "invalid", "type", "this", "returns", "an", "error", "." ]
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 &regulator{ StorageDriver: driver, Cond: sync.NewCond(&sync.Mutex{}), available: limit, } }
go
func NewRegulator(driver storagedriver.StorageDriver, limit uint64) storagedriver.StorageDriver { return &regulator{ 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", "(", "&", "sync", ".", "Mutex", "{", "}", ")", ",", "available", ":", "limit", ",", "}", "\n", "}" ]
// 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", "drivers", "that", "would", "otherwise", "create", "an", "unbounded", "number", "of", "OS", "threads", "if", "allowed", "to", "be", "called", "unregulated", "." ]
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", "other", "information", "here", "." ]
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", "r", ".", "exit", "(", ")", "\n\n", "return", "r", ".", "StorageDriver", ".", "Writer", "(", "ctx", ",", "path", ",", "append", ")", "\n", "}" ]
// 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", "offset", ".", "The", "offset", "must", "be", "no", "larger", "than", "the", "CurrentSize", "for", "this", "path", "." ]
3226863cbcba6dbc2f6c83a37b28126c934af3f8
https://github.com/docker/distribution/blob/3226863cbcba6dbc2f6c83a37b28126c934af3f8/registry/storage/driver/base/regulator.go#L131-L136
train