repo
stringlengths
5
67
sha
stringlengths
40
40
path
stringlengths
4
234
url
stringlengths
85
339
language
stringclasses
6 values
split
stringclasses
3 values
doc
stringlengths
3
51.2k
sign
stringlengths
5
8.01k
problem
stringlengths
13
51.2k
output
stringlengths
0
3.87M
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/sqlite3/authgrouppermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/sqlite3/authgrouppermission.xo.go#L101-L128
go
train
// Delete deletes the AuthGroupPermission from the database.
func (agp *AuthGroupPermission) Delete(db XODB) error
// Delete deletes the AuthGroupPermission from the database. func (agp *AuthGroupPermission) Delete(db XODB) error
{ var err error // if doesn't exist, bail if !agp._exists { return nil } // if deleted, bail if agp._deleted { return nil } // sql query const sqlstr = `DELETE FROM auth_group_permissions WHERE id = ?` // run query XOLog(sqlstr, agp.ID) _, err = db.Exec(sqlstr, agp.ID) if err != nil { return err...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/authuser.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authuser.xo.go#L42-L68
go
train
// Insert inserts the AuthUser to the database.
func (au *AuthUser) Insert(db XODB) error
// Insert inserts the AuthUser to the database. func (au *AuthUser) Insert(db XODB) error
{ var err error // if already exist, bail if au._exists { return errors.New("insert failed: already exists") } // sql insert query, primary key provided by sequence const sqlstr = `INSERT INTO public.auth_user (` + `password, last_login, is_superuser, username, first_name, last_name, email, is_staff, is_ac...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/authuser.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authuser.xo.go#L200-L234
go
train
// AuthUsersByUsername retrieves a row from 'public.auth_user' as a AuthUser. // // Generated from index 'auth_user_username_6821ab7c_like'.
func AuthUsersByUsername(db XODB, username string) ([]*AuthUser, error)
// AuthUsersByUsername retrieves a row from 'public.auth_user' as a AuthUser. // // Generated from index 'auth_user_username_6821ab7c_like'. func AuthUsersByUsername(db XODB, username string) ([]*AuthUser, error)
{ var err error // sql query const sqlstr = `SELECT ` + `id, password, last_login, is_superuser, username, first_name, last_name, email, is_staff, is_active, date_joined ` + `FROM public.auth_user ` + `WHERE username = $1` // run query XOLog(sqlstr, username) q, err := db.Query(sqlstr, username) if err ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L67-L73
go
train
// NthParam satisifies Loader's NthParam.
func (tl TypeLoader) NthParam(i int) string
// NthParam satisifies Loader's NthParam. func (tl TypeLoader) NthParam(i int) string
{ if tl.ParamN != nil { return tl.ParamN(i) } return fmt.Sprintf("$%d", i+1) }
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L85-L91
go
train
// Escape escapes the provided identifier based on the EscType.
func (tl TypeLoader) Escape(typ EscType, s string) string
// Escape escapes the provided identifier based on the EscType. func (tl TypeLoader) Escape(typ EscType, s string) string
{ if e, ok := tl.Esc[typ]; ok && e != nil { return e(s) } return `"` + s + `"` }
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L94-L100
go
train
// Relkind satisfies Loader's Relkind.
func (tl TypeLoader) Relkind(rt RelType) string
// Relkind satisfies Loader's Relkind. func (tl TypeLoader) Relkind(rt RelType) string
{ if tl.ProcessRelkind != nil { return tl.ProcessRelkind(rt) } return rt.String() }
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L103-L109
go
train
// SchemaName returns the active schema name.
func (tl TypeLoader) SchemaName(args *ArgType) (string, error)
// SchemaName returns the active schema name. func (tl TypeLoader) SchemaName(args *ArgType) (string, error)
{ if tl.Schema != nil { return tl.Schema(args) } return "", nil }
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L112-L244
go
train
// ParseQuery satisfies Loader's ParseQuery.
func (tl TypeLoader) ParseQuery(args *ArgType) error
// ParseQuery satisfies Loader's ParseQuery. func (tl TypeLoader) ParseQuery(args *ArgType) error
{ var err error // parse supplied query queryStr, params := args.ParseQuery(tl.Mask(), true) inspectStr, _ := args.ParseQuery("NULL", false) // split up query and inspect based on lines query := strings.Split(queryStr, "\n") inspect := strings.Split(inspectStr, "\n") // query comment placeholder queryComme...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L247-L292
go
train
// LoadSchema loads schema definitions.
func (tl TypeLoader) LoadSchema(args *ArgType) error
// LoadSchema loads schema definitions. func (tl TypeLoader) LoadSchema(args *ArgType) error
{ var err error // load enums _, err = tl.LoadEnums(args) if err != nil { return err } // load procs _, err = tl.LoadProcs(args) if err != nil { return err } // load tables tableMap, err := tl.LoadRelkind(args, Table) if err != nil { return err } // load views viewMap, err := tl.LoadRelkind(ar...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L295-L338
go
train
// LoadEnums loads schema enums.
func (tl TypeLoader) LoadEnums(args *ArgType) (map[string]*Enum, error)
// LoadEnums loads schema enums. func (tl TypeLoader) LoadEnums(args *ArgType) (map[string]*Enum, error)
{ var err error // not supplied, so bail if tl.EnumList == nil { return nil, nil } // load enums enumList, err := tl.EnumList(args.DB, args.Schema) if err != nil { return nil, err } // process enums enumMap := map[string]*Enum{} for _, e := range enumList { enumTpl := &Enum{ Name: S...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L341-L368
go
train
// LoadEnumValues loads schema enum values.
func (tl TypeLoader) LoadEnumValues(args *ArgType, enumTpl *Enum) error
// LoadEnumValues loads schema enum values. func (tl TypeLoader) LoadEnumValues(args *ArgType, enumTpl *Enum) error
{ var err error // load enum values enumValues, err := tl.EnumValueList(args.DB, args.Schema, enumTpl.Enum.EnumName) if err != nil { return err } // process enum values for _, ev := range enumValues { // chop off redundant enum name if applicable name := snaker.SnakeToCamelIdentifier(ev.EnumValue) if ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L371-L425
go
train
// LoadProcs loads schema stored procedures definitions.
func (tl TypeLoader) LoadProcs(args *ArgType) (map[string]*Proc, error)
// LoadProcs loads schema stored procedures definitions. func (tl TypeLoader) LoadProcs(args *ArgType) (map[string]*Proc, error)
{ var err error // not supplied, so bail if tl.ProcList == nil { return nil, nil } // load procs procList, err := tl.ProcList(args.DB, args.Schema) if err != nil { return nil, err } // process procs procMap := map[string]*Proc{} for _, p := range procList { // fix the name if it starts with one or ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L428-L457
go
train
// LoadProcParams loads schema stored procedure parameters.
func (tl TypeLoader) LoadProcParams(args *ArgType, procTpl *Proc) error
// LoadProcParams loads schema stored procedure parameters. func (tl TypeLoader) LoadProcParams(args *ArgType, procTpl *Proc) error
{ var err error // load proc params paramList, err := tl.ProcParamList(args.DB, args.Schema, procTpl.Proc.ProcName) if err != nil { return err } // process params for i, p := range paramList { // TODO: some databases support named parameters in procs (MySQL) paramTpl := &Field{ Name: fmt.Sprintf("v%d...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L460-L499
go
train
// LoadRelkind loads a schema table/view definition.
func (tl TypeLoader) LoadRelkind(args *ArgType, relType RelType) (map[string]*Type, error)
// LoadRelkind loads a schema table/view definition. func (tl TypeLoader) LoadRelkind(args *ArgType, relType RelType) (map[string]*Type, error)
{ var err error // load tables tableList, err := tl.TableList(args.DB, args.Schema, tl.Relkind(relType)) if err != nil { return nil, err } // tables tableMap := make(map[string]*Type) for _, ti := range tableList { // create template typeTpl := &Type{ Name: SingularizeIdentifier(ti.TableName), ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L502-L550
go
train
// LoadColumns loads schema table/view columns.
func (tl TypeLoader) LoadColumns(args *ArgType, typeTpl *Type) error
// LoadColumns loads schema table/view columns. func (tl TypeLoader) LoadColumns(args *ArgType, typeTpl *Type) error
{ var err error // load columns columnList, err := tl.ColumnList(args.DB, args.Schema, typeTpl.Table.TableName) if err != nil { return err } // process columns for _, c := range columnList { ignore := false for _, ignoreField := range args.IgnoreFields { if ignoreField == c.ColumnName { // Skip ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L553-L579
go
train
// LoadForeignKeys loads foreign keys.
func (tl TypeLoader) LoadForeignKeys(args *ArgType, tableMap map[string]*Type) (map[string]*ForeignKey, error)
// LoadForeignKeys loads foreign keys. func (tl TypeLoader) LoadForeignKeys(args *ArgType, tableMap map[string]*Type) (map[string]*ForeignKey, error)
{ var err error fkMap := map[string]*ForeignKey{} for _, t := range tableMap { // load keys per table err = tl.LoadTableForeignKeys(args, tableMap, t, fkMap) if err != nil { return nil, err } } // determine foreign key names for _, fk := range fkMap { fk.Name = args.ForeignKeyName(fkMap, fk) } ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L582-L650
go
train
// LoadTableForeignKeys loads schema foreign key definitions per table.
func (tl TypeLoader) LoadTableForeignKeys(args *ArgType, tableMap map[string]*Type, typeTpl *Type, fkMap map[string]*ForeignKey) error
// LoadTableForeignKeys loads schema foreign key definitions per table. func (tl TypeLoader) LoadTableForeignKeys(args *ArgType, tableMap map[string]*Type, typeTpl *Type, fkMap map[string]*ForeignKey) error
{ var err error // load foreign keys foreignKeyList, err := tl.ForeignKeyList(args.DB, args.Schema, typeTpl.Table.TableName) if err != nil { return err } // loop over foreign keys for table for _, fk := range foreignKeyList { var refTpl *Type var col, refCol *Field colLoop: // find column for _, f...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L653-L674
go
train
// LoadIndexes loads schema index definitions.
func (tl TypeLoader) LoadIndexes(args *ArgType, tableMap map[string]*Type) (map[string]*Index, error)
// LoadIndexes loads schema index definitions. func (tl TypeLoader) LoadIndexes(args *ArgType, tableMap map[string]*Type) (map[string]*Index, error)
{ var err error ixMap := map[string]*Index{} for _, t := range tableMap { // load table indexes err = tl.LoadTableIndexes(args, t, ixMap) if err != nil { return nil, err } } // generate templates for _, ix := range ixMap { err = args.ExecuteTemplate(IndexTemplate, ix.Type.Name, ix.Index.IndexName,...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L677-L742
go
train
// LoadTableIndexes loads schema index definitions per table.
func (tl TypeLoader) LoadTableIndexes(args *ArgType, typeTpl *Type, ixMap map[string]*Index) error
// LoadTableIndexes loads schema index definitions per table. func (tl TypeLoader) LoadTableIndexes(args *ArgType, typeTpl *Type, ixMap map[string]*Index) error
{ var err error var priIxLoaded bool // load indexes indexList, err := tl.IndexList(args.DB, args.Schema, typeTpl.Table.TableName) if err != nil { return err } // process indexes for _, ix := range indexList { // save whether or not the primary key index was processed priIxLoaded = priIxLoaded || ix.Is...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/loader.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L745-L775
go
train
// LoadIndexColumns loads the index column information.
func (tl TypeLoader) LoadIndexColumns(args *ArgType, ixTpl *Index) error
// LoadIndexColumns loads the index column information. func (tl TypeLoader) LoadIndexColumns(args *ArgType, ixTpl *Index) error
{ var err error // load index columns indexCols, err := tl.IndexColumnList(args.DB, args.Schema, ixTpl.Type.Table.TableName, ixTpl.Index.IndexName) if err != nil { return err } // process index columns for _, ic := range indexCols { var field *Field fieldLoop: // find field for _, f := range ixTpl.T...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/pgcatalog/ischema/sp_pgexpandarray.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/pgcatalog/ischema/sp_pgexpandarray.xo.go#L9-L24
go
train
// Code generated by xo. DO NOT EDIT. // PgExpandarray calls the stored procedure 'information_schema._pg_expandarray(anyarray) SETOF record' on db.
func PgExpandarray(db XODB, v0 pgtypes.Anyarray) ([]pgtypes.Record, error)
// Code generated by xo. DO NOT EDIT. // PgExpandarray calls the stored procedure 'information_schema._pg_expandarray(anyarray) SETOF record' on db. func PgExpandarray(db XODB, v0 pgtypes.Anyarray) ([]pgtypes.Record, error)
{ var err error // sql query const sqlstr = `SELECT information_schema._pg_expandarray($1)` // run query var ret []pgtypes.Record XOLog(sqlstr, v0) err = db.QueryRow(sqlstr, v0).Scan(&ret) if err != nil { return nil, err } return ret, nil }
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/authpermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authpermission.xo.go#L32-L58
go
train
// Insert inserts the AuthPermission to the database.
func (ap *AuthPermission) Insert(db XODB) error
// Insert inserts the AuthPermission to the database. func (ap *AuthPermission) Insert(db XODB) error
{ var err error // if already exist, bail if ap._exists { return errors.New("insert failed: already exists") } // sql insert query, primary key provided by sequence const sqlstr = `INSERT INTO public.auth_permission (` + `name, content_type_id, codename` + `) VALUES (` + `$1, $2, $3` + `) RETURNING i...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/authpermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authpermission.xo.go#L99-L129
go
train
// Upsert performs an upsert for AuthPermission. // // NOTE: PostgreSQL 9.5+ only
func (ap *AuthPermission) Upsert(db XODB) error
// Upsert performs an upsert for AuthPermission. // // NOTE: PostgreSQL 9.5+ only func (ap *AuthPermission) Upsert(db XODB) error
{ var err error // if already exist, bail if ap._exists { return errors.New("insert failed: already exists") } // sql query const sqlstr = `INSERT INTO public.auth_permission (` + `id, name, content_type_id, codename` + `) VALUES (` + `$1, $2, $3, $4` + `) ON CONFLICT (id) DO UPDATE SET (` + `id, n...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/authpermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authpermission.xo.go#L210-L231
go
train
// AuthPermissionByContentTypeIDCodename retrieves a row from 'public.auth_permission' as a AuthPermission. // // Generated from index 'auth_permission_content_type_id_01ab375a_uniq'.
func AuthPermissionByContentTypeIDCodename(db XODB, contentTypeID int, codename string) (*AuthPermission, error)
// AuthPermissionByContentTypeIDCodename retrieves a row from 'public.auth_permission' as a AuthPermission. // // Generated from index 'auth_permission_content_type_id_01ab375a_uniq'. func AuthPermissionByContentTypeIDCodename(db XODB, contentTypeID int, codename string) (*AuthPermission, error)
{ var err error // sql query const sqlstr = `SELECT ` + `id, name, content_type_id, codename ` + `FROM public.auth_permission ` + `WHERE content_type_id = $1 AND codename = $2` // run query XOLog(sqlstr, contentTypeID, codename) ap := AuthPermission{ _exists: true, } err = db.QueryRow(sqlstr, conten...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/authpermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authpermission.xo.go#L236-L257
go
train
// AuthPermissionByID retrieves a row from 'public.auth_permission' as a AuthPermission. // // Generated from index 'auth_permission_pkey'.
func AuthPermissionByID(db XODB, id int) (*AuthPermission, error)
// AuthPermissionByID retrieves a row from 'public.auth_permission' as a AuthPermission. // // Generated from index 'auth_permission_pkey'. func AuthPermissionByID(db XODB, id int) (*AuthPermission, error)
{ var err error // sql query const sqlstr = `SELECT ` + `id, name, content_type_id, codename ` + `FROM public.auth_permission ` + `WHERE id = $1` // run query XOLog(sqlstr, id) ap := AuthPermission{ _exists: true, } err = db.QueryRow(sqlstr, id).Scan(&ap.ID, &ap.Name, &ap.ContentTypeID, &ap.Codename...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
models/sequence.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/sequence.xo.go#L12-L47
go
train
// PgSequences runs a custom query, returning results as Sequence.
func PgSequences(db XODB, schema string) ([]*Sequence, error)
// PgSequences runs a custom query, returning results as Sequence. func PgSequences(db XODB, schema string) ([]*Sequence, error)
{ var err error // sql query const sqlstr = `SELECT ` + `t.relname ` + // ::varchar AS table_name `FROM pg_class s ` + `JOIN pg_depend d ON d.objid = s.oid ` + `JOIN pg_class t ON d.objid = s.oid AND d.refobjid = t.oid ` + `JOIN pg_namespace n ON n.oid = s.relnamespace ` + `WHERE n.nspname = $1 AND s.r...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
models/sqcolumn.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/sqcolumn.xo.go#L21-L50
go
train
// SqTableColumns runs a custom query, returning results as SqColumn.
func SqTableColumns(db XODB, table string) ([]*SqColumn, error)
// SqTableColumns runs a custom query, returning results as SqColumn. func SqTableColumns(db XODB, table string) ([]*SqColumn, error)
{ var err error // sql query var sqlstr = `PRAGMA table_info(` + table + `)` // run query XOLog(sqlstr) q, err := db.Query(sqlstr, table) if err != nil { return nil, err } defer q.Close() // load results res := []*SqColumn{} for q.Next() { sc := SqColumn{} // scan err = q.Scan(&sc.FieldOrdinal,...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/authuseruserpermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authuseruserpermission.xo.go#L90-L96
go
train
// Save saves the AuthUserUserPermission to the database.
func (auup *AuthUserUserPermission) Save(db XODB) error
// Save saves the AuthUserUserPermission to the database. func (auup *AuthUserUserPermission) Save(db XODB) error
{ if auup.Exists() { return auup.Update(db) } return auup.Insert(db) }
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/authuseruserpermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authuseruserpermission.xo.go#L131-L133
go
train
// AuthPermission returns the AuthPermission associated with the AuthUserUserPermission's PermissionID (permission_id). // // Generated from foreign key 'd86aa2ae91c20ae0c7ed11fa07e6da'.
func (auup *AuthUserUserPermission) AuthPermission(db XODB) (*AuthPermission, error)
// AuthPermission returns the AuthPermission associated with the AuthUserUserPermission's PermissionID (permission_id). // // Generated from foreign key 'd86aa2ae91c20ae0c7ed11fa07e6da'. func (auup *AuthUserUserPermission) AuthPermission(db XODB) (*AuthPermission, error)
{ return AuthPermissionByID(db, auup.PermissionID) }
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/authuseruserpermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authuseruserpermission.xo.go#L138-L140
go
train
// AuthUser returns the AuthUser associated with the AuthUserUserPermission's UserID (user_id). // // Generated from foreign key 'd9da0966de759042d839a70a2bd885'.
func (auup *AuthUserUserPermission) AuthUser(db XODB) (*AuthUser, error)
// AuthUser returns the AuthUser associated with the AuthUserUserPermission's UserID (user_id). // // Generated from foreign key 'd9da0966de759042d839a70a2bd885'. func (auup *AuthUserUserPermission) AuthUser(db XODB) (*AuthUser, error)
{ return AuthUserByID(db, auup.UserID) }
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/authuseruserpermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authuseruserpermission.xo.go#L145-L166
go
train
// AuthUserUserPermissionByUserIDPermissionID retrieves a row from 'django.auth_user_user_permissions' as a AuthUserUserPermission. // // Generated from index 'auth_use_user_id_14a6b632_uniq'.
func AuthUserUserPermissionByUserIDPermissionID(db XODB, userID float64, permissionID float64) (*AuthUserUserPermission, error)
// AuthUserUserPermissionByUserIDPermissionID retrieves a row from 'django.auth_user_user_permissions' as a AuthUserUserPermission. // // Generated from index 'auth_use_user_id_14a6b632_uniq'. func AuthUserUserPermissionByUserIDPermissionID(db XODB, userID float64, permissionID float64) (*AuthUserUserPermission, error)
{ var err error // sql query const sqlstr = `SELECT ` + `id, user_id, permission_id ` + `FROM django.auth_user_user_permissions ` + `WHERE user_id = :1 AND permission_id = :2` // run query XOLog(sqlstr, userID, permissionID) auup := AuthUserUserPermission{ _exists: true, } err = db.QueryRow(sqlstr, ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/authuseruserpermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authuseruserpermission.xo.go#L171-L205
go
train
// AuthUserUserPermissionsByUserID retrieves a row from 'django.auth_user_user_permissions' as a AuthUserUserPermission. // // Generated from index 'auth_user_user_permissions1cca'.
func AuthUserUserPermissionsByUserID(db XODB, userID float64) ([]*AuthUserUserPermission, error)
// AuthUserUserPermissionsByUserID retrieves a row from 'django.auth_user_user_permissions' as a AuthUserUserPermission. // // Generated from index 'auth_user_user_permissions1cca'. func AuthUserUserPermissionsByUserID(db XODB, userID float64) ([]*AuthUserUserPermission, error)
{ var err error // sql query const sqlstr = `SELECT ` + `id, user_id, permission_id ` + `FROM django.auth_user_user_permissions ` + `WHERE user_id = :1` // run query XOLog(sqlstr, userID) q, err := db.Query(sqlstr, userID) if err != nil { return nil, err } defer q.Close() // load results res := [...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/sqlite3/djangomigration.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/sqlite3/djangomigration.xo.go#L94-L100
go
train
// Save saves the DjangoMigration to the database.
func (dm *DjangoMigration) Save(db XODB) error
// Save saves the DjangoMigration to the database. func (dm *DjangoMigration) Save(db XODB) error
{ if dm.Exists() { return dm.Update(db) } return dm.Insert(db) }
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
loaders/mysql.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/mysql.go#L35-L51
go
train
// MySchema retrieves the name of the current schema.
func MySchema(args *internal.ArgType) (string, error)
// MySchema retrieves the name of the current schema. func MySchema(args *internal.ArgType) (string, error)
{ var err error // sql query const sqlstr = `SELECT SCHEMA()` var schema string // run query models.XOLog(sqlstr) err = args.DB.QueryRow(sqlstr).Scan(&schema) if err != nil { return "", err } return schema, nil }
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
loaders/mysql.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/mysql.go#L69-L218
go
train
// MyParseType parse a mysql type into a Go type based on the column // definition.
func MyParseType(args *internal.ArgType, dt string, nullable bool) (int, string, string)
// MyParseType parse a mysql type into a Go type based on the column // definition. func MyParseType(args *internal.ArgType, dt string, nullable bool) (int, string, string)
{ precision := 0 nilVal := "nil" unsigned := false // extract unsigned if strings.HasSuffix(dt, " unsigned") { unsigned = true dt = dt[:len(dt)-len(" unsigned")] } // extract precision dt, precision, _ = args.ParsePrecision(dt) var typ string switchDT: switch dt { case "bit": nilVal = "0" if pre...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
loaders/mysql.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/mysql.go#L221-L240
go
train
// MyEnumValues loads the enum values.
func MyEnumValues(db models.XODB, schema string, enum string) ([]*models.EnumValue, error)
// MyEnumValues loads the enum values. func MyEnumValues(db models.XODB, schema string, enum string) ([]*models.EnumValue, error)
{ var err error // load enum vals res, err := models.MyEnumValues(db, schema, enum) if err != nil { return nil, err } // process enum vals enumVals := []*models.EnumValue{} for i, ev := range strings.Split(res.EnumValues[1:len(res.EnumValues)-1], "','") { enumVals = append(enumVals, &models.EnumValue{ ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
loaders/mysql.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/mysql.go#L244-L278
go
train
// MyTables returns the MySql tables with the manual PK information added. // ManualPk is true when the table's primary key is not autoincrement.
func MyTables(db models.XODB, schema string, relkind string) ([]*models.Table, error)
// MyTables returns the MySql tables with the manual PK information added. // ManualPk is true when the table's primary key is not autoincrement. func MyTables(db models.XODB, schema string, relkind string) ([]*models.Table, error)
{ var err error // get the tables rows, err := models.MyTables(db, schema, relkind) if err != nil { return nil, err } // get the tables that have Autoincrementing included autoIncrements, err := models.MyAutoIncrements(db, schema) if err != nil { // Set it to an empty set on error. autoIncrements = []*...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
loaders/mysql.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/mysql.go#L281-L303
go
train
// MyQueryColumns parses the query and generates a type for it.
func MyQueryColumns(args *internal.ArgType, inspect []string) ([]*models.Column, error)
// MyQueryColumns parses the query and generates a type for it. func MyQueryColumns(args *internal.ArgType, inspect []string) ([]*models.Column, error)
{ var err error // create temporary view xoid xoid := "_xo_" + internal.GenRandomID() viewq := `CREATE VIEW ` + xoid + ` AS (` + strings.Join(inspect, "\n") + `)` models.XOLog(viewq) _, err = args.DB.Exec(viewq) if err != nil { return nil, err } // load columns cols, err := models.MyTableColumns(args.DB,...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/argtype.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/argtype.go#L156-L210
go
train
// NewDefaultArgs returns the default arguments.
func NewDefaultArgs() *ArgType
// NewDefaultArgs returns the default arguments. func NewDefaultArgs() *ArgType
{ fkMode := FkModeSmart return &ArgType{ Suffix: ".xo.go", Int32Type: "int", Uint32Type: "uint", ForeignKeyMode: &fkMode, QueryParamDelimiter: "%%", NameConflictSuffix: "Val", // KnownTypeMap is the collection of known Go types. KnownTypeMap: map[string]bool{ ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
models/msidentity.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/msidentity.xo.go#L12-L44
go
train
// MsIdentities runs a custom query, returning results as MsIdentity.
func MsIdentities(db XODB, schema string) ([]*MsIdentity, error)
// MsIdentities runs a custom query, returning results as MsIdentity. func MsIdentities(db XODB, schema string) ([]*MsIdentity, error)
{ var err error // sql query const sqlstr = `SELECT o.name as table_name ` + `FROM sys.objects o inner join sys.columns c on o.object_id = c.object_id ` + `WHERE c.is_identity = 1 ` + `AND schema_name(o.schema_id) = $1 AND o.type = 'U'` // run query XOLog(sqlstr, schema) q, err := db.Query(sqlstr, schema...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
loaders/postgres.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/postgres.go#L39-L50
go
train
// PgRelkind returns the postgres string representation for RelType.
func PgRelkind(relType internal.RelType) string
// PgRelkind returns the postgres string representation for RelType. func PgRelkind(relType internal.RelType) string
{ var s string switch relType { case internal.Table: s = "r" case internal.View: s = "v" default: panic("unsupported RelType") } return s }
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
loaders/postgres.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/postgres.go#L54-L211
go
train
// PgParseType parse a postgres type into a Go type based on the column // definition.
func PgParseType(args *internal.ArgType, dt string, nullable bool) (int, string, string)
// PgParseType parse a postgres type into a Go type based on the column // definition. func PgParseType(args *internal.ArgType, dt string, nullable bool) (int, string, string)
{ precision := 0 nilVal := "nil" asSlice := false // handle SETOF if strings.HasPrefix(dt, "SETOF ") { _, _, t := PgParseType(args, dt[len("SETOF "):], false) return 0, "nil", "[]" + t } // determine if it's a slice if strings.HasSuffix(dt, "[]") { dt = dt[:len(dt)-2] asSlice = true } // extract p...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
loaders/postgres.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/postgres.go#L219-L229
go
train
// PgQueryStrip strips stuff.
func PgQueryStrip(query []string, queryComments []string)
// PgQueryStrip strips stuff. func PgQueryStrip(query []string, queryComments []string)
{ for i, l := range query { pos := pgQueryStripRE.FindStringIndex(l) if pos != nil { query[i] = l[:pos[0]] + l[pos[1]:] queryComments[i+1] = l[pos[0]:pos[1]] } else { queryComments[i+1] = "" } } }
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
loaders/postgres.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/postgres.go#L233-L267
go
train
// PgTables returns the Postgres tables with the manual PK information added. // ManualPk is true when the table does not have a sequence defined.
func PgTables(db models.XODB, schema string, relkind string) ([]*models.Table, error)
// PgTables returns the Postgres tables with the manual PK information added. // ManualPk is true when the table does not have a sequence defined. func PgTables(db models.XODB, schema string, relkind string) ([]*models.Table, error)
{ var err error // get the tables rows, err := models.PgTables(db, schema, relkind) if err != nil { return nil, err } // Get the tables that have a sequence defined. sequences, err := models.PgSequences(db, schema) if err != nil { // Set it to an empty set on error. sequences = []*models.Sequence{} } ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
loaders/postgres.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/postgres.go#L270-L298
go
train
// PgQueryColumns parses the query and generates a type for it.
func PgQueryColumns(args *internal.ArgType, inspect []string) ([]*models.Column, error)
// PgQueryColumns parses the query and generates a type for it. func PgQueryColumns(args *internal.ArgType, inspect []string) ([]*models.Column, error)
{ var err error // create temporary view xoid xoid := "_xo_" + internal.GenRandomID() viewq := `CREATE TEMPORARY VIEW ` + xoid + ` AS (` + strings.Join(inspect, "\n") + `)` models.XOLog(viewq) _, err = args.DB.Exec(viewq) if err != nil { return nil, err } // query to determine schema name where temporary ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
loaders/postgres.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/postgres.go#L301-L350
go
train
// PgIndexColumns returns the column list for an index.
func PgIndexColumns(db models.XODB, schema string, table string, index string) ([]*models.IndexColumn, error)
// PgIndexColumns returns the column list for an index. func PgIndexColumns(db models.XODB, schema string, table string, index string) ([]*models.IndexColumn, error)
{ var err error // load columns cols, err := models.PgIndexColumns(db, schema, index) if err != nil { return nil, err } // load col order colOrd, err := models.PgGetColOrder(db, schema, index) if err != nil { return nil, err } // build schema name used in errors s := schema if s != "" { s = s + "....
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/djangocontenttype.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/djangocontenttype.xo.go#L32-L65
go
train
// Insert inserts the DjangoContentType to the database.
func (dct *DjangoContentType) Insert(db XODB) error
// Insert inserts the DjangoContentType to the database. func (dct *DjangoContentType) Insert(db XODB) error
{ var err error // if already exist, bail if dct._exists { return errors.New("insert failed: already exists") } // sql query const sqlstr = `INSERT INTO django.django_content_type (` + `app_label, model` + `) VALUES (` + `:1, :2` + `) RETURNING id /*lastInsertId*/ INTO :pk` // run query XOLog(sqls...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/djangocontenttype.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/djangocontenttype.xo.go#L31-L57
go
train
// Insert inserts the DjangoContentType to the database.
func (dct *DjangoContentType) Insert(db XODB) error
// Insert inserts the DjangoContentType to the database. func (dct *DjangoContentType) Insert(db XODB) error
{ var err error // if already exist, bail if dct._exists { return errors.New("insert failed: already exists") } // sql insert query, primary key provided by sequence const sqlstr = `INSERT INTO public.django_content_type (` + `app_label, model` + `) VALUES (` + `$1, $2` + `) RETURNING id` // run qu...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/djangocontenttype.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/djangocontenttype.xo.go#L60-L84
go
train
// Update updates the DjangoContentType in the database.
func (dct *DjangoContentType) Update(db XODB) error
// Update updates the DjangoContentType in the database. func (dct *DjangoContentType) Update(db XODB) error
{ var err error // if doesn't exist, bail if !dct._exists { return errors.New("update failed: does not exist") } // if deleted, bail if dct._deleted { return errors.New("update failed: marked for deletion") } // sql query const sqlstr = `UPDATE public.django_content_type SET (` + `app_label, model` +...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/djangocontenttype.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/djangocontenttype.xo.go#L98-L128
go
train
// Upsert performs an upsert for DjangoContentType. // // NOTE: PostgreSQL 9.5+ only
func (dct *DjangoContentType) Upsert(db XODB) error
// Upsert performs an upsert for DjangoContentType. // // NOTE: PostgreSQL 9.5+ only func (dct *DjangoContentType) Upsert(db XODB) error
{ var err error // if already exist, bail if dct._exists { return errors.New("insert failed: already exists") } // sql query const sqlstr = `INSERT INTO public.django_content_type (` + `id, app_label, model` + `) VALUES (` + `$1, $2, $3` + `) ON CONFLICT (id) DO UPDATE SET (` + `id, app_label, mode...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/djangocontenttype.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/djangocontenttype.xo.go#L131-L158
go
train
// Delete deletes the DjangoContentType from the database.
func (dct *DjangoContentType) Delete(db XODB) error
// Delete deletes the DjangoContentType from the database. func (dct *DjangoContentType) Delete(db XODB) error
{ var err error // if doesn't exist, bail if !dct._exists { return nil } // if deleted, bail if dct._deleted { return nil } // sql query const sqlstr = `DELETE FROM public.django_content_type WHERE id = $1` // run query XOLog(sqlstr, dct.ID) _, err = db.Exec(sqlstr, dct.ID) if err != nil { retur...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/authgrouppermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authgrouppermission.xo.go#L145-L166
go
train
// AuthGroupPermissionByGroupIDPermissionID retrieves a row from 'django.auth_group_permissions' as a AuthGroupPermission. // // Generated from index 'auth_gr_group_id_0cd325b0_uniq'.
func AuthGroupPermissionByGroupIDPermissionID(db XODB, groupID float64, permissionID float64) (*AuthGroupPermission, error)
// AuthGroupPermissionByGroupIDPermissionID retrieves a row from 'django.auth_group_permissions' as a AuthGroupPermission. // // Generated from index 'auth_gr_group_id_0cd325b0_uniq'. func AuthGroupPermissionByGroupIDPermissionID(db XODB, groupID float64, permissionID float64) (*AuthGroupPermission, error)
{ var err error // sql query const sqlstr = `SELECT ` + `id, group_id, permission_id ` + `FROM django.auth_group_permissions ` + `WHERE group_id = :1 AND permission_id = :2` // run query XOLog(sqlstr, groupID, permissionID) agp := AuthGroupPermission{ _exists: true, } err = db.QueryRow(sqlstr, group...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
models/procparam.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/procparam.xo.go#L12-L45
go
train
// PgProcParams runs a custom query, returning results as ProcParam.
func PgProcParams(db XODB, schema string, proc string) ([]*ProcParam, error)
// PgProcParams runs a custom query, returning results as ProcParam. func PgProcParams(db XODB, schema string, proc string) ([]*ProcParam, error)
{ var err error // sql query const sqlstr = `SELECT ` + `UNNEST(STRING_TO_ARRAY(oidvectortypes(p.proargtypes), ', ')) ` + // ::varchar AS param_type `FROM pg_proc p ` + `JOIN ONLY pg_namespace n ON p.pronamespace = n.oid ` + `WHERE n.nspname = $1 AND p.proname = $2` // run query XOLog(sqlstr, schema, pr...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/mysql/authusergroup.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/mysql/authusergroup.xo.go#L147-L181
go
train
// AuthUserGroupsByGroupID retrieves a row from 'django.auth_user_groups' as a AuthUserGroup. // // Generated from index 'auth_user_groups_group_id_97559544_fk_auth_group_id'.
func AuthUserGroupsByGroupID(db XODB, groupID int) ([]*AuthUserGroup, error)
// AuthUserGroupsByGroupID retrieves a row from 'django.auth_user_groups' as a AuthUserGroup. // // Generated from index 'auth_user_groups_group_id_97559544_fk_auth_group_id'. func AuthUserGroupsByGroupID(db XODB, groupID int) ([]*AuthUserGroup, error)
{ var err error // sql query const sqlstr = `SELECT ` + `id, user_id, group_id ` + `FROM django.auth_user_groups ` + `WHERE group_id = ?` // run query XOLog(sqlstr, groupID) q, err := db.Query(sqlstr, groupID) if err != nil { return nil, err } defer q.Close() // load results res := []*AuthUserGro...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/mysql/authusergroup.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/mysql/authusergroup.xo.go#L186-L207
go
train
// AuthUserGroupByID retrieves a row from 'django.auth_user_groups' as a AuthUserGroup. // // Generated from index 'auth_user_groups_id_pkey'.
func AuthUserGroupByID(db XODB, id int) (*AuthUserGroup, error)
// AuthUserGroupByID retrieves a row from 'django.auth_user_groups' as a AuthUserGroup. // // Generated from index 'auth_user_groups_id_pkey'. func AuthUserGroupByID(db XODB, id int) (*AuthUserGroup, error)
{ var err error // sql query const sqlstr = `SELECT ` + `id, user_id, group_id ` + `FROM django.auth_user_groups ` + `WHERE id = ?` // run query XOLog(sqlstr, id) aug := AuthUserGroup{ _exists: true, } err = db.QueryRow(sqlstr, id).Scan(&aug.ID, &aug.UserID, &aug.GroupID) if err != nil { return n...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
loaders/mssql.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/mssql.go#L68-L182
go
train
// MsParseType parse a mssql type into a Go type based on the column // definition.
func MsParseType(args *internal.ArgType, dt string, nullable bool) (int, string, string)
// MsParseType parse a mssql type into a Go type based on the column // definition. func MsParseType(args *internal.ArgType, dt string, nullable bool) (int, string, string)
{ precision := 0 nilVal := "nil" // extract precision dt, precision, _ = args.ParsePrecision(dt) var typ string switch dt { case "tinyint", "bit": nilVal = "false" typ = "bool" if nullable { nilVal = "sql.NullBool{}" typ = "sql.NullBool" } case "char", "varchar", "text", "nchar", "nvarchar", "...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
loaders/mssql.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/mssql.go#L185-L215
go
train
// MsQueryColumns parses the query and generates a type for it.
func MsQueryColumns(args *internal.ArgType, inspect []string) ([]*models.Column, error)
// MsQueryColumns parses the query and generates a type for it. func MsQueryColumns(args *internal.ArgType, inspect []string) ([]*models.Column, error)
{ var err error // process inspect -- cannot have 'order by' in a CREATE VIEW ins := []string{} for _, l := range inspect { if !strings.HasPrefix(strings.ToUpper(l), "ORDER BY ") { ins = append(ins, l) } } // create temporary view xoid xoid := "_xo_" + internal.GenRandomID() viewq := `CREATE VIEW ` + ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
loaders/mssql.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/mssql.go#L219-L253
go
train
// MsTables returns the MsSQL tables with the manual PK information added. // ManualPk is true when the table's primary key is not an identity.
func MsTables(db models.XODB, schema string, relkind string) ([]*models.Table, error)
// MsTables returns the MsSQL tables with the manual PK information added. // ManualPk is true when the table's primary key is not an identity. func MsTables(db models.XODB, schema string, relkind string) ([]*models.Table, error)
{ var err error // get the tables rows, err := models.MsTables(db, schema, relkind) if err != nil { return nil, err } // get the tables that have Identity included identities, err := models.MsIdentities(db, schema) if err != nil { // Set it to an empty set on error. identities = []*models.MsIdentity{} ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/mysql/djangoadminlog.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/mysql/djangoadminlog.xo.go#L108-L135
go
train
// Delete deletes the DjangoAdminLog from the database.
func (dal *DjangoAdminLog) Delete(db XODB) error
// Delete deletes the DjangoAdminLog from the database. func (dal *DjangoAdminLog) Delete(db XODB) error
{ var err error // if doesn't exist, bail if !dal._exists { return nil } // if deleted, bail if dal._deleted { return nil } // sql query const sqlstr = `DELETE FROM django.django_admin_log WHERE id = ?` // run query XOLog(sqlstr, dal.ID) _, err = db.Exec(sqlstr, dal.ID) if err != nil { return er...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/djangomigration.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/djangomigration.xo.go#L33-L59
go
train
// Insert inserts the DjangoMigration to the database.
func (dm *DjangoMigration) Insert(db XODB) error
// Insert inserts the DjangoMigration to the database. func (dm *DjangoMigration) Insert(db XODB) error
{ var err error // if already exist, bail if dm._exists { return errors.New("insert failed: already exists") } // sql insert query, primary key provided by sequence const sqlstr = `INSERT INTO public.django_migrations (` + `app, name, applied` + `) VALUES (` + `$1, $2, $3` + `) RETURNING id` // run...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/djangomigration.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/djangomigration.xo.go#L100-L130
go
train
// Upsert performs an upsert for DjangoMigration. // // NOTE: PostgreSQL 9.5+ only
func (dm *DjangoMigration) Upsert(db XODB) error
// Upsert performs an upsert for DjangoMigration. // // NOTE: PostgreSQL 9.5+ only func (dm *DjangoMigration) Upsert(db XODB) error
{ var err error // if already exist, bail if dm._exists { return errors.New("insert failed: already exists") } // sql query const sqlstr = `INSERT INTO public.django_migrations (` + `id, app, name, applied` + `) VALUES (` + `$1, $2, $3, $4` + `) ON CONFLICT (id) DO UPDATE SET (` + `id, app, name, a...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/mysql/djangosession.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/mysql/djangosession.xo.go#L127-L161
go
train
// DjangoSessionsByExpireDate retrieves a row from 'django.django_session' as a DjangoSession. // // Generated from index 'django_session_de54fa62'.
func DjangoSessionsByExpireDate(db XODB, expireDate *time.Time) ([]*DjangoSession, error)
// DjangoSessionsByExpireDate retrieves a row from 'django.django_session' as a DjangoSession. // // Generated from index 'django_session_de54fa62'. func DjangoSessionsByExpireDate(db XODB, expireDate *time.Time) ([]*DjangoSession, error)
{ var err error // sql query const sqlstr = `SELECT ` + `session_key, session_data, expire_date ` + `FROM django.django_session ` + `WHERE expire_date = ?` // run query XOLog(sqlstr, expireDate) q, err := db.Query(sqlstr, expireDate) if err != nil { return nil, err } defer q.Close() // load result...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/mysql/djangosession.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/mysql/djangosession.xo.go#L166-L187
go
train
// DjangoSessionBySessionKey retrieves a row from 'django.django_session' as a DjangoSession. // // Generated from index 'django_session_session_key_pkey'.
func DjangoSessionBySessionKey(db XODB, sessionKey string) (*DjangoSession, error)
// DjangoSessionBySessionKey retrieves a row from 'django.django_session' as a DjangoSession. // // Generated from index 'django_session_session_key_pkey'. func DjangoSessionBySessionKey(db XODB, sessionKey string) (*DjangoSession, error)
{ var err error // sql query const sqlstr = `SELECT ` + `session_key, session_data, expire_date ` + `FROM django.django_session ` + `WHERE session_key = ?` // run query XOLog(sqlstr, sessionKey) ds := DjangoSession{ _exists: true, } err = db.QueryRow(sqlstr, sessionKey).Scan(&ds.SessionKey, &ds.Sess...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/mysql/authuseruserpermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/mysql/authuseruserpermission.xo.go#L31-L64
go
train
// Insert inserts the AuthUserUserPermission to the database.
func (auup *AuthUserUserPermission) Insert(db XODB) error
// Insert inserts the AuthUserUserPermission to the database. func (auup *AuthUserUserPermission) Insert(db XODB) error
{ var err error // if already exist, bail if auup._exists { return errors.New("insert failed: already exists") } // sql insert query, primary key provided by autoincrement const sqlstr = `INSERT INTO django.auth_user_user_permissions (` + `user_id, permission_id` + `) VALUES (` + `?, ?` + `)` // ru...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/mysql/authuseruserpermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/mysql/authuseruserpermission.xo.go#L67-L89
go
train
// Update updates the AuthUserUserPermission in the database.
func (auup *AuthUserUserPermission) Update(db XODB) error
// Update updates the AuthUserUserPermission in the database. func (auup *AuthUserUserPermission) Update(db XODB) error
{ var err error // if doesn't exist, bail if !auup._exists { return errors.New("update failed: does not exist") } // if deleted, bail if auup._deleted { return errors.New("update failed: marked for deletion") } // sql query const sqlstr = `UPDATE django.auth_user_user_permissions SET ` + `user_id = ?...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/djangomigration.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/djangomigration.xo.go#L34-L67
go
train
// Insert inserts the DjangoMigration to the database.
func (dm *DjangoMigration) Insert(db XODB) error
// Insert inserts the DjangoMigration to the database. func (dm *DjangoMigration) Insert(db XODB) error
{ var err error // if already exist, bail if dm._exists { return errors.New("insert failed: already exists") } // sql query const sqlstr = `INSERT INTO django.django_migrations (` + `app, name, applied` + `) VALUES (` + `:1, :2, :3` + `) RETURNING id /*lastInsertId*/ INTO :pk` // run query XOLog(s...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/djangomigration.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/djangomigration.xo.go#L70-L92
go
train
// Update updates the DjangoMigration in the database.
func (dm *DjangoMigration) Update(db XODB) error
// Update updates the DjangoMigration in the database. func (dm *DjangoMigration) Update(db XODB) error
{ var err error // if doesn't exist, bail if !dm._exists { return errors.New("update failed: does not exist") } // if deleted, bail if dm._deleted { return errors.New("update failed: marked for deletion") } // sql query const sqlstr = `UPDATE django.django_migrations SET ` + `app = :1, name = :2, app...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/djangomigration.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/djangomigration.xo.go#L104-L131
go
train
// Delete deletes the DjangoMigration from the database.
func (dm *DjangoMigration) Delete(db XODB) error
// Delete deletes the DjangoMigration from the database. func (dm *DjangoMigration) Delete(db XODB) error
{ var err error // if doesn't exist, bail if !dm._exists { return nil } // if deleted, bail if dm._deleted { return nil } // sql query const sqlstr = `DELETE FROM django.django_migrations WHERE id = :1` // run query XOLog(sqlstr, dm.ID) _, err = db.Exec(sqlstr, dm.ID) if err != nil { return err ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/djangomigration.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/djangomigration.xo.go#L136-L157
go
train
// DjangoMigrationByID retrieves a row from 'django.django_migrations' as a DjangoMigration. // // Generated from index 'sys_c004953'.
func DjangoMigrationByID(db XODB, id float64) (*DjangoMigration, error)
// DjangoMigrationByID retrieves a row from 'django.django_migrations' as a DjangoMigration. // // Generated from index 'sys_c004953'. func DjangoMigrationByID(db XODB, id float64) (*DjangoMigration, error)
{ var err error // sql query const sqlstr = `SELECT ` + `id, app, name, applied ` + `FROM django.django_migrations ` + `WHERE id = :1` // run query XOLog(sqlstr, id) dm := DjangoMigration{ _exists: true, } err = db.QueryRow(sqlstr, id).Scan(&dm.ID, &dm.App, &dm.Name, &dm.Applied) if err != nil { ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/sqlite3/djangocontenttype.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/sqlite3/djangocontenttype.xo.go#L159-L180
go
train
// DjangoContentTypeByID retrieves a row from 'django_content_type' as a DjangoContentType. // // Generated from index 'django_content_type_id_pkey'.
func DjangoContentTypeByID(db XODB, id int) (*DjangoContentType, error)
// DjangoContentTypeByID retrieves a row from 'django_content_type' as a DjangoContentType. // // Generated from index 'django_content_type_id_pkey'. func DjangoContentTypeByID(db XODB, id int) (*DjangoContentType, error)
{ var err error // sql query const sqlstr = `SELECT ` + `id, app_label, model ` + `FROM django_content_type ` + `WHERE id = ?` // run query XOLog(sqlstr, id) dct := DjangoContentType{ _exists: true, } err = db.QueryRow(sqlstr, id).Scan(&dct.ID, &dct.AppLabel, &dct.Model) if err != nil { return ni...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/djangoadminlog.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/djangoadminlog.xo.go#L38-L64
go
train
// Insert inserts the DjangoAdminLog to the database.
func (dal *DjangoAdminLog) Insert(db XODB) error
// Insert inserts the DjangoAdminLog to the database. func (dal *DjangoAdminLog) Insert(db XODB) error
{ var err error // if already exist, bail if dal._exists { return errors.New("insert failed: already exists") } // sql insert query, primary key provided by sequence const sqlstr = `INSERT INTO public.django_admin_log (` + `action_time, object_id, object_repr, action_flag, change_message, content_type_id, ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/djangoadminlog.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/djangoadminlog.xo.go#L67-L91
go
train
// Update updates the DjangoAdminLog in the database.
func (dal *DjangoAdminLog) Update(db XODB) error
// Update updates the DjangoAdminLog in the database. func (dal *DjangoAdminLog) Update(db XODB) error
{ var err error // if doesn't exist, bail if !dal._exists { return errors.New("update failed: does not exist") } // if deleted, bail if dal._deleted { return errors.New("update failed: marked for deletion") } // sql query const sqlstr = `UPDATE public.django_admin_log SET (` + `action_time, object_id...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/djangoadminlog.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/djangoadminlog.xo.go#L184-L218
go
train
// DjangoAdminLogsByContentTypeID retrieves a row from 'public.django_admin_log' as a DjangoAdminLog. // // Generated from index 'django_admin_log_417f1b1c'.
func DjangoAdminLogsByContentTypeID(db XODB, contentTypeID sql.NullInt64) ([]*DjangoAdminLog, error)
// DjangoAdminLogsByContentTypeID retrieves a row from 'public.django_admin_log' as a DjangoAdminLog. // // Generated from index 'django_admin_log_417f1b1c'. func DjangoAdminLogsByContentTypeID(db XODB, contentTypeID sql.NullInt64) ([]*DjangoAdminLog, error)
{ var err error // sql query const sqlstr = `SELECT ` + `id, action_time, object_id, object_repr, action_flag, change_message, content_type_id, user_id ` + `FROM public.django_admin_log ` + `WHERE content_type_id = $1` // run query XOLog(sqlstr, contentTypeID) q, err := db.Query(sqlstr, contentTypeID) i...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
models/proc.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/proc.xo.go#L13-L47
go
train
// PgProcs runs a custom query, returning results as Proc.
func PgProcs(db XODB, schema string) ([]*Proc, error)
// PgProcs runs a custom query, returning results as Proc. func PgProcs(db XODB, schema string) ([]*Proc, error)
{ var err error // sql query const sqlstr = `SELECT ` + `p.proname, ` + // ::varchar AS proc_name `pg_get_function_result(p.oid) ` + // ::varchar AS return_type `FROM pg_proc p ` + `JOIN ONLY pg_namespace n ON p.pronamespace = n.oid ` + `WHERE n.nspname = $1` // run query XOLog(sqlstr, schema) q, err...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/authgroup.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authgroup.xo.go#L31-L64
go
train
// Insert inserts the AuthGroup to the database.
func (ag *AuthGroup) Insert(db XODB) error
// Insert inserts the AuthGroup to the database. func (ag *AuthGroup) Insert(db XODB) error
{ var err error // if already exist, bail if ag._exists { return errors.New("insert failed: already exists") } // sql query const sqlstr = `INSERT INTO django.auth_group (` + `name` + `) VALUES (` + `:1` + `) RETURNING id /*lastInsertId*/ INTO :pk` // run query XOLog(sqlstr, ag.Name, nil) res, er...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/authgroup.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authgroup.xo.go#L101-L128
go
train
// Delete deletes the AuthGroup from the database.
func (ag *AuthGroup) Delete(db XODB) error
// Delete deletes the AuthGroup from the database. func (ag *AuthGroup) Delete(db XODB) error
{ var err error // if doesn't exist, bail if !ag._exists { return nil } // if deleted, bail if ag._deleted { return nil } // sql query const sqlstr = `DELETE FROM django.auth_group WHERE id = :1` // run query XOLog(sqlstr, ag.ID) _, err = db.Exec(sqlstr, ag.ID) if err != nil { return err } //...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/sqlite3/authgroup.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/sqlite3/authgroup.xo.go#L66-L88
go
train
// Update updates the AuthGroup in the database.
func (ag *AuthGroup) Update(db XODB) error
// Update updates the AuthGroup in the database. func (ag *AuthGroup) Update(db XODB) error
{ var err error // if doesn't exist, bail if !ag._exists { return errors.New("update failed: does not exist") } // if deleted, bail if ag._deleted { return errors.New("update failed: marked for deletion") } // sql query const sqlstr = `UPDATE auth_group SET ` + `name = ?` + ` WHERE id = ?` // run...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/authuser.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authuser.xo.go#L111-L138
go
train
// Delete deletes the AuthUser from the database.
func (au *AuthUser) Delete(db XODB) error
// Delete deletes the AuthUser from the database. func (au *AuthUser) Delete(db XODB) error
{ var err error // if doesn't exist, bail if !au._exists { return nil } // if deleted, bail if au._deleted { return nil } // sql query const sqlstr = `DELETE FROM django.auth_user WHERE id = :1` // run query XOLog(sqlstr, au.ID) _, err = db.Exec(sqlstr, au.ID) if err != nil { return err } // ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/authuser.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authuser.xo.go#L169-L190
go
train
// AuthUserByUsername retrieves a row from 'django.auth_user' as a AuthUser. // // Generated from index 'sys_c004977'.
func AuthUserByUsername(db XODB, username sql.NullString) (*AuthUser, error)
// AuthUserByUsername retrieves a row from 'django.auth_user' as a AuthUser. // // Generated from index 'sys_c004977'. func AuthUserByUsername(db XODB, username sql.NullString) (*AuthUser, error)
{ var err error // sql query const sqlstr = `SELECT ` + `id, password, last_login, is_superuser, username, first_name, last_name, email, is_staff, is_active, date_joined ` + `FROM django.auth_user ` + `WHERE username = :1` // run query XOLog(sqlstr, username) au := AuthUser{ _exists: true, } err = d...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/fkmode.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/fkmode.go#L44-L60
go
train
// UnmarshalText unmarshals FkMode from text.
func (f *FkMode) UnmarshalText(text []byte) error
// UnmarshalText unmarshals FkMode from text. func (f *FkMode) UnmarshalText(text []byte) error
{ switch strings.ToLower(string(text)) { case "smart", "default": *f = FkModeSmart case "parent": *f = FkModeParent case "field": *f = FkModeField case "key": *f = FkModeKey default: return errors.New("invalid FkMode") } return nil }
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/fkmode.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/fkmode.go#L79-L99
go
train
// fkName returns the name for the foreign key.
func fkName(mode FkMode, fkMap map[string]*ForeignKey, fk *ForeignKey) string
// fkName returns the name for the foreign key. func fkName(mode FkMode, fkMap map[string]*ForeignKey, fk *ForeignKey) string
{ switch mode { case FkModeParent: return fk.RefType.Name case FkModeField: return fk.RefType.Name + "By" + fk.Field.Name case FkModeKey: return fk.RefType.Name + "By" + snaker.SnakeToCamelIdentifier(fk.ForeignKey.ForeignKeyName) } // mode is FkModeSmart // inspect all foreign keys and use FkModeField if...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
internal/fkmode.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/fkmode.go#L102-L104
go
train
// ForeignKeyName returns the foreign key name for the passed type.
func (a *ArgType) ForeignKeyName(fkMap map[string]*ForeignKey, fk *ForeignKey) string
// ForeignKeyName returns the foreign key name for the passed type. func (a *ArgType) ForeignKeyName(fkMap map[string]*ForeignKey, fk *ForeignKey) string
{ return fkName(*a.ForeignKeyMode, fkMap, fk) }
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/authuseruserpermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authuseruserpermission.xo.go#L31-L57
go
train
// Insert inserts the AuthUserUserPermission to the database.
func (auup *AuthUserUserPermission) Insert(db XODB) error
// Insert inserts the AuthUserUserPermission to the database. func (auup *AuthUserUserPermission) Insert(db XODB) error
{ var err error // if already exist, bail if auup._exists { return errors.New("insert failed: already exists") } // sql insert query, primary key provided by sequence const sqlstr = `INSERT INTO public.auth_user_user_permissions (` + `user_id, permission_id` + `) VALUES (` + `$1, $2` + `) RETURNING i...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/authuseruserpermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authuseruserpermission.xo.go#L98-L128
go
train
// Upsert performs an upsert for AuthUserUserPermission. // // NOTE: PostgreSQL 9.5+ only
func (auup *AuthUserUserPermission) Upsert(db XODB) error
// Upsert performs an upsert for AuthUserUserPermission. // // NOTE: PostgreSQL 9.5+ only func (auup *AuthUserUserPermission) Upsert(db XODB) error
{ var err error // if already exist, bail if auup._exists { return errors.New("insert failed: already exists") } // sql query const sqlstr = `INSERT INTO public.auth_user_user_permissions (` + `id, user_id, permission_id` + `) VALUES (` + `$1, $2, $3` + `) ON CONFLICT (id) DO UPDATE SET (` + `id, u...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/authuseruserpermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authuseruserpermission.xo.go#L131-L158
go
train
// Delete deletes the AuthUserUserPermission from the database.
func (auup *AuthUserUserPermission) Delete(db XODB) error
// Delete deletes the AuthUserUserPermission from the database. func (auup *AuthUserUserPermission) Delete(db XODB) error
{ var err error // if doesn't exist, bail if !auup._exists { return nil } // if deleted, bail if auup._deleted { return nil } // sql query const sqlstr = `DELETE FROM public.auth_user_user_permissions WHERE id = $1` // run query XOLog(sqlstr, auup.ID) _, err = db.Exec(sqlstr, auup.ID) if err != ni...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/authuseruserpermission.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authuseruserpermission.xo.go#L255-L276
go
train
// AuthUserUserPermissionByID retrieves a row from 'public.auth_user_user_permissions' as a AuthUserUserPermission. // // Generated from index 'auth_user_user_permissions_pkey'.
func AuthUserUserPermissionByID(db XODB, id int) (*AuthUserUserPermission, error)
// AuthUserUserPermissionByID retrieves a row from 'public.auth_user_user_permissions' as a AuthUserUserPermission. // // Generated from index 'auth_user_user_permissions_pkey'. func AuthUserUserPermissionByID(db XODB, id int) (*AuthUserUserPermission, error)
{ var err error // sql query const sqlstr = `SELECT ` + `id, user_id, permission_id ` + `FROM public.auth_user_user_permissions ` + `WHERE id = $1` // run query XOLog(sqlstr, id) auup := AuthUserUserPermission{ _exists: true, } err = db.QueryRow(sqlstr, id).Scan(&auup.ID, &auup.UserID, &auup.Permiss...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/authusergroup.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authusergroup.xo.go#L29-L62
go
train
// Insert inserts the AuthUserGroup to the database.
func (aug *AuthUserGroup) Insert(db XODB) error
// Insert inserts the AuthUserGroup to the database. func (aug *AuthUserGroup) Insert(db XODB) error
{ var err error // if already exist, bail if aug._exists { return errors.New("insert failed: already exists") } // sql query const sqlstr = `INSERT INTO django.auth_user_groups (` + `user_id, group_id` + `) VALUES (` + `:1, :2` + `) RETURNING id /*lastInsertId*/ INTO :pk` // run query XOLog(sqlstr...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/oracle/authusergroup.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authusergroup.xo.go#L99-L126
go
train
// Delete deletes the AuthUserGroup from the database.
func (aug *AuthUserGroup) Delete(db XODB) error
// Delete deletes the AuthUserGroup from the database. func (aug *AuthUserGroup) Delete(db XODB) error
{ var err error // if doesn't exist, bail if !aug._exists { return nil } // if deleted, bail if aug._deleted { return nil } // sql query const sqlstr = `DELETE FROM django.auth_user_groups WHERE id = :1` // run query XOLog(sqlstr, aug.ID) _, err = db.Exec(sqlstr, aug.ID) if err != nil { return e...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/pgcatalog/ischema/sp_pgtruetypid.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/pgcatalog/ischema/sp_pgtruetypid.xo.go#L9-L24
go
train
// Code generated by xo. DO NOT EDIT. // PgTruetypid calls the stored procedure 'information_schema._pg_truetypid(pg_attribute, pg_type) oid' on db.
func PgTruetypid(db XODB, v0 pgtypes.PgAttribute, v1 pgtypes.PgType) (pgtypes.Oid, error)
// Code generated by xo. DO NOT EDIT. // PgTruetypid calls the stored procedure 'information_schema._pg_truetypid(pg_attribute, pg_type) oid' on db. func PgTruetypid(db XODB, v0 pgtypes.PgAttribute, v1 pgtypes.PgType) (pgtypes.Oid, error)
{ var err error // sql query const sqlstr = `SELECT information_schema._pg_truetypid($1, $2)` // run query var ret pgtypes.Oid XOLog(sqlstr, v0, v1) err = db.QueryRow(sqlstr, v0, v1).Scan(&ret) if err != nil { return pgtypes.Oid{}, err } return ret, nil }
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
models/myenumvalue.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/myenumvalue.xo.go#L12-L30
go
train
// MyEnumValues runs a custom query, returning results as MyEnumValue.
func MyEnumValues(db XODB, schema string, enum string) (*MyEnumValue, error)
// MyEnumValues runs a custom query, returning results as MyEnumValue. func MyEnumValues(db XODB, schema string, enum string) (*MyEnumValue, error)
{ var err error // sql query const sqlstr = `SELECT ` + `SUBSTRING(column_type, 6, CHAR_LENGTH(column_type) - 6) AS enum_values ` + `FROM information_schema.columns ` + `WHERE data_type = 'enum' AND table_schema = ? AND column_name = ?` // run query XOLog(sqlstr, schema, enum) var mev MyEnumValue err = ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/authusergroup.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authusergroup.xo.go#L31-L57
go
train
// Insert inserts the AuthUserGroup to the database.
func (aug *AuthUserGroup) Insert(db XODB) error
// Insert inserts the AuthUserGroup to the database. func (aug *AuthUserGroup) Insert(db XODB) error
{ var err error // if already exist, bail if aug._exists { return errors.New("insert failed: already exists") } // sql insert query, primary key provided by sequence const sqlstr = `INSERT INTO public.auth_user_groups (` + `user_id, group_id` + `) VALUES (` + `$1, $2` + `) RETURNING id` // run quer...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/authusergroup.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authusergroup.xo.go#L60-L84
go
train
// Update updates the AuthUserGroup in the database.
func (aug *AuthUserGroup) Update(db XODB) error
// Update updates the AuthUserGroup in the database. func (aug *AuthUserGroup) Update(db XODB) error
{ var err error // if doesn't exist, bail if !aug._exists { return errors.New("update failed: does not exist") } // if deleted, bail if aug._deleted { return errors.New("update failed: marked for deletion") } // sql query const sqlstr = `UPDATE public.auth_user_groups SET (` + `user_id, group_id` + ...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
examples/django/postgres/authusergroup.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authusergroup.xo.go#L98-L128
go
train
// Upsert performs an upsert for AuthUserGroup. // // NOTE: PostgreSQL 9.5+ only
func (aug *AuthUserGroup) Upsert(db XODB) error
// Upsert performs an upsert for AuthUserGroup. // // NOTE: PostgreSQL 9.5+ only func (aug *AuthUserGroup) Upsert(db XODB) error
{ var err error // if already exist, bail if aug._exists { return errors.New("insert failed: already exists") } // sql query const sqlstr = `INSERT INTO public.auth_user_groups (` + `id, user_id, group_id` + `) VALUES (` + `$1, $2, $3` + `) ON CONFLICT (id) DO UPDATE SET (` + `id, user_id, group_id...
xo/xo
1a94fa516029cb306cce6d379d086e4d5b5bb232
models/column.xo.go
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/column.xo.go#L66-L104
go
train
// MyTableColumns runs a custom query, returning results as Column.
func MyTableColumns(db XODB, schema string, table string) ([]*Column, error)
// MyTableColumns runs a custom query, returning results as Column. func MyTableColumns(db XODB, schema string, table string) ([]*Column, error)
{ var err error // sql query const sqlstr = `SELECT ` + `ordinal_position AS field_ordinal, ` + `column_name, ` + `IF(data_type = 'enum', column_name, column_type) AS data_type, ` + `IF(is_nullable = 'YES', false, true) AS not_null, ` + `column_default AS default_value, ` + `IF(column_key = 'PRI', true...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/methods.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/methods.go#L48-L56
go
train
// CheckAndSetDefaults checks and sets defaults
func (a *AuthenticateUserRequest) CheckAndSetDefaults() error
// CheckAndSetDefaults checks and sets defaults func (a *AuthenticateUserRequest) CheckAndSetDefaults() error
{ if a.Username == "" { return trace.BadParameter("missing parameter 'username'") } if a.Pass == nil && a.U2F == nil && a.OTP == nil && a.Session == nil { return trace.BadParameter("at least one authentication method is required") } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/methods.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/methods.go#L85-L102
go
train
// AuthenticateUser authenticates user based on the request type
func (s *AuthServer) AuthenticateUser(req AuthenticateUserRequest) error
// AuthenticateUser authenticates user based on the request type func (s *AuthServer) AuthenticateUser(req AuthenticateUserRequest) error
{ err := s.authenticateUser(req) if err != nil { s.EmitAuditEvent(events.UserLocalLoginFailure, events.EventFields{ events.EventUser: req.Username, events.LoginMethod: events.LoginMethodLocal, events.AuthAttemptSuccess: false, events.AuthAttemptErr: err.Error(), }) } else { s.E...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/methods.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/methods.go#L165-L188
go
train
// AuthenticateWebUser authenticates web user, creates and returns web session // in case if authentication is successful. In case if existing session id // is used to authenticate, returns session associated with the existing session id // instead of creating the new one
func (s *AuthServer) AuthenticateWebUser(req AuthenticateUserRequest) (services.WebSession, error)
// AuthenticateWebUser authenticates web user, creates and returns web session // in case if authentication is successful. In case if existing session id // is used to authenticate, returns session associated with the existing session id // instead of creating the new one func (s *AuthServer) AuthenticateWebUser(req A...
{ if req.Session != nil { session, err := s.GetWebSession(req.Username, req.Session.ID) if err != nil { return nil, trace.AccessDenied("session is invalid or has expired") } return session, nil } if err := s.AuthenticateUser(req); err != nil { return nil, trace.Wrap(err) } sess, err := s.NewWebSessio...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/methods.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/methods.go#L203-L216
go
train
// CheckAndSetDefaults checks and sets default certificate values
func (a *AuthenticateSSHRequest) CheckAndSetDefaults() error
// CheckAndSetDefaults checks and sets default certificate values func (a *AuthenticateSSHRequest) CheckAndSetDefaults() error
{ if err := a.AuthenticateUserRequest.CheckAndSetDefaults(); err != nil { return trace.Wrap(err) } if len(a.PublicKey) == 0 { return trace.BadParameter("missing parameter 'public_key'") } certificateFormat, err := utils.CheckCertificateFormatFlag(a.CompatibilityMode) if err != nil { return trace.Wrap(err) ...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/methods.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/methods.go#L247-L257
go
train
// SSHCertPublicKeys returns a list of trusted host SSH certificate authority public keys
func (c *TrustedCerts) SSHCertPublicKeys() ([]ssh.PublicKey, error)
// SSHCertPublicKeys returns a list of trusted host SSH certificate authority public keys func (c *TrustedCerts) SSHCertPublicKeys() ([]ssh.PublicKey, error)
{ out := make([]ssh.PublicKey, 0, len(c.HostCertificates)) for _, keyBytes := range c.HostCertificates { publicKey, _, _, _, err := ssh.ParseAuthorizedKey(keyBytes) if err != nil { return nil, trace.Wrap(err) } out = append(out, publicKey) } return out, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/methods.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/methods.go#L260-L270
go
train
// AuthoritiesToTrustedCerts serializes authorities to TrustedCerts data structure
func AuthoritiesToTrustedCerts(authorities []services.CertAuthority) []TrustedCerts
// AuthoritiesToTrustedCerts serializes authorities to TrustedCerts data structure func AuthoritiesToTrustedCerts(authorities []services.CertAuthority) []TrustedCerts
{ out := make([]TrustedCerts, len(authorities)) for i, ca := range authorities { out[i] = TrustedCerts{ ClusterName: ca.GetClusterName(), HostCertificates: ca.GetCheckingKeys(), TLSCertificates: services.TLSCerts(ca), } } return out }