id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
|---|---|---|---|---|---|---|---|---|---|---|---|
22,800
|
xo/xo
|
examples/pgcatalog/pgcatalog/pgcatalog.xo.go
|
PgTsTemplateByTmplnameTmplnamespace
|
func PgTsTemplateByTmplnameTmplnamespace(db XODB, tmplname pgtypes.Name, tmplnamespace pgtypes.Oid) (*PgTsTemplate, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`tableoid, cmax, xmax, cmin, xmin, oid, ctid, tmplname, tmplnamespace, tmplinit, tmpllexize ` +
`FROM pg_catalog.pg_ts_template ` +
`WHERE tmplname = $1 AND tmplnamespace = $2`
// run query
XOLog(sqlstr, tmplname, tmplnamespace)
ptt := PgTsTemplate{}
err = db.QueryRow(sqlstr, tmplname, tmplnamespace).Scan(&ptt.Tableoid, &ptt.Cmax, &ptt.Xmax, &ptt.Cmin, &ptt.Xmin, &ptt.Oid, &ptt.Ctid, &ptt.Tmplname, &ptt.Tmplnamespace, &ptt.Tmplinit, &ptt.Tmpllexize)
if err != nil {
return nil, err
}
return &ptt, nil
}
|
go
|
func PgTsTemplateByTmplnameTmplnamespace(db XODB, tmplname pgtypes.Name, tmplnamespace pgtypes.Oid) (*PgTsTemplate, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`tableoid, cmax, xmax, cmin, xmin, oid, ctid, tmplname, tmplnamespace, tmplinit, tmpllexize ` +
`FROM pg_catalog.pg_ts_template ` +
`WHERE tmplname = $1 AND tmplnamespace = $2`
// run query
XOLog(sqlstr, tmplname, tmplnamespace)
ptt := PgTsTemplate{}
err = db.QueryRow(sqlstr, tmplname, tmplnamespace).Scan(&ptt.Tableoid, &ptt.Cmax, &ptt.Xmax, &ptt.Cmin, &ptt.Xmin, &ptt.Oid, &ptt.Ctid, &ptt.Tmplname, &ptt.Tmplnamespace, &ptt.Tmplinit, &ptt.Tmpllexize)
if err != nil {
return nil, err
}
return &ptt, nil
}
|
[
"func",
"PgTsTemplateByTmplnameTmplnamespace",
"(",
"db",
"XODB",
",",
"tmplname",
"pgtypes",
".",
"Name",
",",
"tmplnamespace",
"pgtypes",
".",
"Oid",
")",
"(",
"*",
"PgTsTemplate",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`tableoid, cmax, xmax, cmin, xmin, oid, ctid, tmplname, tmplnamespace, tmplinit, tmpllexize `",
"+",
"`FROM pg_catalog.pg_ts_template `",
"+",
"`WHERE tmplname = $1 AND tmplnamespace = $2`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"tmplname",
",",
"tmplnamespace",
")",
"\n",
"ptt",
":=",
"PgTsTemplate",
"{",
"}",
"\n\n",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"sqlstr",
",",
"tmplname",
",",
"tmplnamespace",
")",
".",
"Scan",
"(",
"&",
"ptt",
".",
"Tableoid",
",",
"&",
"ptt",
".",
"Cmax",
",",
"&",
"ptt",
".",
"Xmax",
",",
"&",
"ptt",
".",
"Cmin",
",",
"&",
"ptt",
".",
"Xmin",
",",
"&",
"ptt",
".",
"Oid",
",",
"&",
"ptt",
".",
"Ctid",
",",
"&",
"ptt",
".",
"Tmplname",
",",
"&",
"ptt",
".",
"Tmplnamespace",
",",
"&",
"ptt",
".",
"Tmplinit",
",",
"&",
"ptt",
".",
"Tmpllexize",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"ptt",
",",
"nil",
"\n",
"}"
] |
// PgTsTemplateByTmplnameTmplnamespace retrieves a row from 'pg_catalog.pg_ts_template' as a PgTsTemplate.
//
// Generated from index 'pg_ts_template_tmplname_index'.
|
[
"PgTsTemplateByTmplnameTmplnamespace",
"retrieves",
"a",
"row",
"from",
"pg_catalog",
".",
"pg_ts_template",
"as",
"a",
"PgTsTemplate",
".",
"Generated",
"from",
"index",
"pg_ts_template_tmplname_index",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/pgcatalog/pgcatalog/pgcatalog.xo.go#L44215-L44234
|
22,801
|
xo/xo
|
examples/pgcatalog/pgcatalog/pgcatalog.xo.go
|
PgTypeByOid
|
func PgTypeByOid(db XODB, oid pgtypes.Oid) (*PgType, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`tableoid, cmax, xmax, cmin, xmin, oid, ctid, typname, typnamespace, typowner, typlen, typbyval, typtype, typcategory, typispreferred, typisdefined, typdelim, typrelid, typelem, typarray, typinput, typoutput, typreceive, typsend, typmodin, typmodout, typanalyze, typalign, typstorage, typnotnull, typbasetype, typtypmod, typndims, typcollation, typdefaultbin, typdefault, typacl ` +
`FROM pg_catalog.pg_type ` +
`WHERE oid = $1`
// run query
XOLog(sqlstr, oid)
pt := PgType{}
err = db.QueryRow(sqlstr, oid).Scan(&pt.Tableoid, &pt.Cmax, &pt.Xmax, &pt.Cmin, &pt.Xmin, &pt.Oid, &pt.Ctid, &pt.Typname, &pt.Typnamespace, &pt.Typowner, &pt.Typlen, &pt.Typbyval, &pt.Typtype, &pt.Typcategory, &pt.Typispreferred, &pt.Typisdefined, &pt.Typdelim, &pt.Typrelid, &pt.Typelem, &pt.Typarray, &pt.Typinput, &pt.Typoutput, &pt.Typreceive, &pt.Typsend, &pt.Typmodin, &pt.Typmodout, &pt.Typanalyze, &pt.Typalign, &pt.Typstorage, &pt.Typnotnull, &pt.Typbasetype, &pt.Typtypmod, &pt.Typndims, &pt.Typcollation, &pt.Typdefaultbin, &pt.Typdefault, &pt.Typacl)
if err != nil {
return nil, err
}
return &pt, nil
}
|
go
|
func PgTypeByOid(db XODB, oid pgtypes.Oid) (*PgType, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`tableoid, cmax, xmax, cmin, xmin, oid, ctid, typname, typnamespace, typowner, typlen, typbyval, typtype, typcategory, typispreferred, typisdefined, typdelim, typrelid, typelem, typarray, typinput, typoutput, typreceive, typsend, typmodin, typmodout, typanalyze, typalign, typstorage, typnotnull, typbasetype, typtypmod, typndims, typcollation, typdefaultbin, typdefault, typacl ` +
`FROM pg_catalog.pg_type ` +
`WHERE oid = $1`
// run query
XOLog(sqlstr, oid)
pt := PgType{}
err = db.QueryRow(sqlstr, oid).Scan(&pt.Tableoid, &pt.Cmax, &pt.Xmax, &pt.Cmin, &pt.Xmin, &pt.Oid, &pt.Ctid, &pt.Typname, &pt.Typnamespace, &pt.Typowner, &pt.Typlen, &pt.Typbyval, &pt.Typtype, &pt.Typcategory, &pt.Typispreferred, &pt.Typisdefined, &pt.Typdelim, &pt.Typrelid, &pt.Typelem, &pt.Typarray, &pt.Typinput, &pt.Typoutput, &pt.Typreceive, &pt.Typsend, &pt.Typmodin, &pt.Typmodout, &pt.Typanalyze, &pt.Typalign, &pt.Typstorage, &pt.Typnotnull, &pt.Typbasetype, &pt.Typtypmod, &pt.Typndims, &pt.Typcollation, &pt.Typdefaultbin, &pt.Typdefault, &pt.Typacl)
if err != nil {
return nil, err
}
return &pt, nil
}
|
[
"func",
"PgTypeByOid",
"(",
"db",
"XODB",
",",
"oid",
"pgtypes",
".",
"Oid",
")",
"(",
"*",
"PgType",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`tableoid, cmax, xmax, cmin, xmin, oid, ctid, typname, typnamespace, typowner, typlen, typbyval, typtype, typcategory, typispreferred, typisdefined, typdelim, typrelid, typelem, typarray, typinput, typoutput, typreceive, typsend, typmodin, typmodout, typanalyze, typalign, typstorage, typnotnull, typbasetype, typtypmod, typndims, typcollation, typdefaultbin, typdefault, typacl `",
"+",
"`FROM pg_catalog.pg_type `",
"+",
"`WHERE oid = $1`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"oid",
")",
"\n",
"pt",
":=",
"PgType",
"{",
"}",
"\n\n",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"sqlstr",
",",
"oid",
")",
".",
"Scan",
"(",
"&",
"pt",
".",
"Tableoid",
",",
"&",
"pt",
".",
"Cmax",
",",
"&",
"pt",
".",
"Xmax",
",",
"&",
"pt",
".",
"Cmin",
",",
"&",
"pt",
".",
"Xmin",
",",
"&",
"pt",
".",
"Oid",
",",
"&",
"pt",
".",
"Ctid",
",",
"&",
"pt",
".",
"Typname",
",",
"&",
"pt",
".",
"Typnamespace",
",",
"&",
"pt",
".",
"Typowner",
",",
"&",
"pt",
".",
"Typlen",
",",
"&",
"pt",
".",
"Typbyval",
",",
"&",
"pt",
".",
"Typtype",
",",
"&",
"pt",
".",
"Typcategory",
",",
"&",
"pt",
".",
"Typispreferred",
",",
"&",
"pt",
".",
"Typisdefined",
",",
"&",
"pt",
".",
"Typdelim",
",",
"&",
"pt",
".",
"Typrelid",
",",
"&",
"pt",
".",
"Typelem",
",",
"&",
"pt",
".",
"Typarray",
",",
"&",
"pt",
".",
"Typinput",
",",
"&",
"pt",
".",
"Typoutput",
",",
"&",
"pt",
".",
"Typreceive",
",",
"&",
"pt",
".",
"Typsend",
",",
"&",
"pt",
".",
"Typmodin",
",",
"&",
"pt",
".",
"Typmodout",
",",
"&",
"pt",
".",
"Typanalyze",
",",
"&",
"pt",
".",
"Typalign",
",",
"&",
"pt",
".",
"Typstorage",
",",
"&",
"pt",
".",
"Typnotnull",
",",
"&",
"pt",
".",
"Typbasetype",
",",
"&",
"pt",
".",
"Typtypmod",
",",
"&",
"pt",
".",
"Typndims",
",",
"&",
"pt",
".",
"Typcollation",
",",
"&",
"pt",
".",
"Typdefaultbin",
",",
"&",
"pt",
".",
"Typdefault",
",",
"&",
"pt",
".",
"Typacl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"pt",
",",
"nil",
"\n",
"}"
] |
// PgTypeByOid retrieves a row from 'pg_catalog.pg_type' as a PgType.
//
// Generated from index 'pg_type_oid_index'.
|
[
"PgTypeByOid",
"retrieves",
"a",
"row",
"from",
"pg_catalog",
".",
"pg_type",
"as",
"a",
"PgType",
".",
"Generated",
"from",
"index",
"pg_type_oid_index",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/pgcatalog/pgcatalog/pgcatalog.xo.go#L44239-L44258
|
22,802
|
xo/xo
|
examples/pgcatalog/pgcatalog/pgcatalog.xo.go
|
PgUserMappingByOid
|
func PgUserMappingByOid(db XODB, oid pgtypes.Oid) (*PgUserMapping, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`tableoid, cmax, xmax, cmin, xmin, oid, ctid, umuser, umserver, umoptions ` +
`FROM pg_catalog.pg_user_mapping ` +
`WHERE oid = $1`
// run query
XOLog(sqlstr, oid)
pum := PgUserMapping{}
err = db.QueryRow(sqlstr, oid).Scan(&pum.Tableoid, &pum.Cmax, &pum.Xmax, &pum.Cmin, &pum.Xmin, &pum.Oid, &pum.Ctid, &pum.Umuser, &pum.Umserver, &pum.Umoptions)
if err != nil {
return nil, err
}
return &pum, nil
}
|
go
|
func PgUserMappingByOid(db XODB, oid pgtypes.Oid) (*PgUserMapping, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`tableoid, cmax, xmax, cmin, xmin, oid, ctid, umuser, umserver, umoptions ` +
`FROM pg_catalog.pg_user_mapping ` +
`WHERE oid = $1`
// run query
XOLog(sqlstr, oid)
pum := PgUserMapping{}
err = db.QueryRow(sqlstr, oid).Scan(&pum.Tableoid, &pum.Cmax, &pum.Xmax, &pum.Cmin, &pum.Xmin, &pum.Oid, &pum.Ctid, &pum.Umuser, &pum.Umserver, &pum.Umoptions)
if err != nil {
return nil, err
}
return &pum, nil
}
|
[
"func",
"PgUserMappingByOid",
"(",
"db",
"XODB",
",",
"oid",
"pgtypes",
".",
"Oid",
")",
"(",
"*",
"PgUserMapping",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`tableoid, cmax, xmax, cmin, xmin, oid, ctid, umuser, umserver, umoptions `",
"+",
"`FROM pg_catalog.pg_user_mapping `",
"+",
"`WHERE oid = $1`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"oid",
")",
"\n",
"pum",
":=",
"PgUserMapping",
"{",
"}",
"\n\n",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"sqlstr",
",",
"oid",
")",
".",
"Scan",
"(",
"&",
"pum",
".",
"Tableoid",
",",
"&",
"pum",
".",
"Cmax",
",",
"&",
"pum",
".",
"Xmax",
",",
"&",
"pum",
".",
"Cmin",
",",
"&",
"pum",
".",
"Xmin",
",",
"&",
"pum",
".",
"Oid",
",",
"&",
"pum",
".",
"Ctid",
",",
"&",
"pum",
".",
"Umuser",
",",
"&",
"pum",
".",
"Umserver",
",",
"&",
"pum",
".",
"Umoptions",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"pum",
",",
"nil",
"\n",
"}"
] |
// PgUserMappingByOid retrieves a row from 'pg_catalog.pg_user_mapping' as a PgUserMapping.
//
// Generated from index 'pg_user_mapping_oid_index'.
|
[
"PgUserMappingByOid",
"retrieves",
"a",
"row",
"from",
"pg_catalog",
".",
"pg_user_mapping",
"as",
"a",
"PgUserMapping",
".",
"Generated",
"from",
"index",
"pg_user_mapping_oid_index",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/pgcatalog/pgcatalog/pgcatalog.xo.go#L44287-L44306
|
22,803
|
xo/xo
|
examples/pgcatalog/pgcatalog/pgcatalog.xo.go
|
Scan
|
func (ss *StringSlice) Scan(src interface{}) error {
buf, ok := src.([]byte)
if !ok {
return errors.New("invalid StringSlice")
}
// change quote escapes for csv parser
str := quoteEscapeRegex.ReplaceAllString(string(buf), `$1""`)
str = strings.Replace(str, `\\`, `\`, -1)
// remove braces
str = str[1 : len(str)-1]
// bail if only one
if len(str) == 0 {
*ss = StringSlice([]string{})
return nil
}
// parse with csv reader
cr := csv.NewReader(strings.NewReader(str))
slice, err := cr.Read()
if err != nil {
fmt.Printf("exiting!: %v\n", err)
return err
}
*ss = StringSlice(slice)
return nil
}
|
go
|
func (ss *StringSlice) Scan(src interface{}) error {
buf, ok := src.([]byte)
if !ok {
return errors.New("invalid StringSlice")
}
// change quote escapes for csv parser
str := quoteEscapeRegex.ReplaceAllString(string(buf), `$1""`)
str = strings.Replace(str, `\\`, `\`, -1)
// remove braces
str = str[1 : len(str)-1]
// bail if only one
if len(str) == 0 {
*ss = StringSlice([]string{})
return nil
}
// parse with csv reader
cr := csv.NewReader(strings.NewReader(str))
slice, err := cr.Read()
if err != nil {
fmt.Printf("exiting!: %v\n", err)
return err
}
*ss = StringSlice(slice)
return nil
}
|
[
"func",
"(",
"ss",
"*",
"StringSlice",
")",
"Scan",
"(",
"src",
"interface",
"{",
"}",
")",
"error",
"{",
"buf",
",",
"ok",
":=",
"src",
".",
"(",
"[",
"]",
"byte",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// change quote escapes for csv parser",
"str",
":=",
"quoteEscapeRegex",
".",
"ReplaceAllString",
"(",
"string",
"(",
"buf",
")",
",",
"`$1\"\"`",
")",
"\n",
"str",
"=",
"strings",
".",
"Replace",
"(",
"str",
",",
"`\\\\`",
",",
"`\\`",
",",
"-",
"1",
")",
"\n\n",
"// remove braces",
"str",
"=",
"str",
"[",
"1",
":",
"len",
"(",
"str",
")",
"-",
"1",
"]",
"\n\n",
"// bail if only one",
"if",
"len",
"(",
"str",
")",
"==",
"0",
"{",
"*",
"ss",
"=",
"StringSlice",
"(",
"[",
"]",
"string",
"{",
"}",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"// parse with csv reader",
"cr",
":=",
"csv",
".",
"NewReader",
"(",
"strings",
".",
"NewReader",
"(",
"str",
")",
")",
"\n",
"slice",
",",
"err",
":=",
"cr",
".",
"Read",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"*",
"ss",
"=",
"StringSlice",
"(",
"slice",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Scan satisfies the sql.Scanner interface for StringSlice.
|
[
"Scan",
"satisfies",
"the",
"sql",
".",
"Scanner",
"interface",
"for",
"StringSlice",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/pgcatalog/pgcatalog/pgcatalog.xo.go#L44359-L44389
|
22,804
|
xo/xo
|
examples/pgcatalog/pgcatalog/pgcatalog.xo.go
|
Value
|
func (ss StringSlice) Value() (driver.Value, error) {
v := make([]string, len(ss))
for i, s := range ss {
v[i] = `"` + strings.Replace(strings.Replace(s, `\`, `\\\`, -1), `"`, `\"`, -1) + `"`
}
return "{" + strings.Join(v, ",") + "}", nil
}
|
go
|
func (ss StringSlice) Value() (driver.Value, error) {
v := make([]string, len(ss))
for i, s := range ss {
v[i] = `"` + strings.Replace(strings.Replace(s, `\`, `\\\`, -1), `"`, `\"`, -1) + `"`
}
return "{" + strings.Join(v, ",") + "}", nil
}
|
[
"func",
"(",
"ss",
"StringSlice",
")",
"Value",
"(",
")",
"(",
"driver",
".",
"Value",
",",
"error",
")",
"{",
"v",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"ss",
")",
")",
"\n",
"for",
"i",
",",
"s",
":=",
"range",
"ss",
"{",
"v",
"[",
"i",
"]",
"=",
"`\"`",
"+",
"strings",
".",
"Replace",
"(",
"strings",
".",
"Replace",
"(",
"s",
",",
"`\\`",
",",
"`\\\\\\`",
",",
"-",
"1",
")",
",",
"`\"`",
",",
"`\\\"`",
",",
"-",
"1",
")",
"+",
"`\"`",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"+",
"strings",
".",
"Join",
"(",
"v",
",",
"\"",
"\"",
")",
"+",
"\"",
"\"",
",",
"nil",
"\n",
"}"
] |
// Value satisfies the driver.Valuer interface for StringSlice.
|
[
"Value",
"satisfies",
"the",
"driver",
".",
"Valuer",
"interface",
"for",
"StringSlice",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/pgcatalog/pgcatalog/pgcatalog.xo.go#L44392-L44398
|
22,805
|
xo/xo
|
examples/django/mysql/djangocontenttype.xo.go
|
Save
|
func (dct *DjangoContentType) Save(db XODB) error {
if dct.Exists() {
return dct.Update(db)
}
return dct.Insert(db)
}
|
go
|
func (dct *DjangoContentType) Save(db XODB) error {
if dct.Exists() {
return dct.Update(db)
}
return dct.Insert(db)
}
|
[
"func",
"(",
"dct",
"*",
"DjangoContentType",
")",
"Save",
"(",
"db",
"XODB",
")",
"error",
"{",
"if",
"dct",
".",
"Exists",
"(",
")",
"{",
"return",
"dct",
".",
"Update",
"(",
"db",
")",
"\n",
"}",
"\n\n",
"return",
"dct",
".",
"Insert",
"(",
"db",
")",
"\n",
"}"
] |
// Save saves the DjangoContentType to the database.
|
[
"Save",
"saves",
"the",
"DjangoContentType",
"to",
"the",
"database",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/mysql/djangocontenttype.xo.go#L92-L98
|
22,806
|
xo/xo
|
examples/django/mysql/djangocontenttype.xo.go
|
DjangoContentTypeByAppLabelModel
|
func DjangoContentTypeByAppLabelModel(db XODB, appLabel string, model string) (*DjangoContentType, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, app_label, model ` +
`FROM django.django_content_type ` +
`WHERE app_label = ? AND model = ?`
// run query
XOLog(sqlstr, appLabel, model)
dct := DjangoContentType{
_exists: true,
}
err = db.QueryRow(sqlstr, appLabel, model).Scan(&dct.ID, &dct.AppLabel, &dct.Model)
if err != nil {
return nil, err
}
return &dct, nil
}
|
go
|
func DjangoContentTypeByAppLabelModel(db XODB, appLabel string, model string) (*DjangoContentType, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, app_label, model ` +
`FROM django.django_content_type ` +
`WHERE app_label = ? AND model = ?`
// run query
XOLog(sqlstr, appLabel, model)
dct := DjangoContentType{
_exists: true,
}
err = db.QueryRow(sqlstr, appLabel, model).Scan(&dct.ID, &dct.AppLabel, &dct.Model)
if err != nil {
return nil, err
}
return &dct, nil
}
|
[
"func",
"DjangoContentTypeByAppLabelModel",
"(",
"db",
"XODB",
",",
"appLabel",
"string",
",",
"model",
"string",
")",
"(",
"*",
"DjangoContentType",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`id, app_label, model `",
"+",
"`FROM django.django_content_type `",
"+",
"`WHERE app_label = ? AND model = ?`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"appLabel",
",",
"model",
")",
"\n",
"dct",
":=",
"DjangoContentType",
"{",
"_exists",
":",
"true",
",",
"}",
"\n\n",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"sqlstr",
",",
"appLabel",
",",
"model",
")",
".",
"Scan",
"(",
"&",
"dct",
".",
"ID",
",",
"&",
"dct",
".",
"AppLabel",
",",
"&",
"dct",
".",
"Model",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"dct",
",",
"nil",
"\n",
"}"
] |
// DjangoContentTypeByAppLabelModel retrieves a row from 'django.django_content_type' as a DjangoContentType.
//
// Generated from index 'django_content_type_app_label_76bd3d3b_uniq'.
|
[
"DjangoContentTypeByAppLabelModel",
"retrieves",
"a",
"row",
"from",
"django",
".",
"django_content_type",
"as",
"a",
"DjangoContentType",
".",
"Generated",
"from",
"index",
"django_content_type_app_label_76bd3d3b_uniq",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/mysql/djangocontenttype.xo.go#L133-L154
|
22,807
|
xo/xo
|
examples/django/mysql/authgroup.xo.go
|
Save
|
func (ag *AuthGroup) Save(db XODB) error {
if ag.Exists() {
return ag.Update(db)
}
return ag.Insert(db)
}
|
go
|
func (ag *AuthGroup) Save(db XODB) error {
if ag.Exists() {
return ag.Update(db)
}
return ag.Insert(db)
}
|
[
"func",
"(",
"ag",
"*",
"AuthGroup",
")",
"Save",
"(",
"db",
"XODB",
")",
"error",
"{",
"if",
"ag",
".",
"Exists",
"(",
")",
"{",
"return",
"ag",
".",
"Update",
"(",
"db",
")",
"\n",
"}",
"\n\n",
"return",
"ag",
".",
"Insert",
"(",
"db",
")",
"\n",
"}"
] |
// Save saves the AuthGroup to the database.
|
[
"Save",
"saves",
"the",
"AuthGroup",
"to",
"the",
"database",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/mysql/authgroup.xo.go#L91-L97
|
22,808
|
xo/xo
|
examples/django/mysql/authgroup.xo.go
|
AuthGroupByID
|
func AuthGroupByID(db XODB, id int) (*AuthGroup, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, name ` +
`FROM django.auth_group ` +
`WHERE id = ?`
// run query
XOLog(sqlstr, id)
ag := AuthGroup{
_exists: true,
}
err = db.QueryRow(sqlstr, id).Scan(&ag.ID, &ag.Name)
if err != nil {
return nil, err
}
return &ag, nil
}
|
go
|
func AuthGroupByID(db XODB, id int) (*AuthGroup, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, name ` +
`FROM django.auth_group ` +
`WHERE id = ?`
// run query
XOLog(sqlstr, id)
ag := AuthGroup{
_exists: true,
}
err = db.QueryRow(sqlstr, id).Scan(&ag.ID, &ag.Name)
if err != nil {
return nil, err
}
return &ag, nil
}
|
[
"func",
"AuthGroupByID",
"(",
"db",
"XODB",
",",
"id",
"int",
")",
"(",
"*",
"AuthGroup",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`id, name `",
"+",
"`FROM django.auth_group `",
"+",
"`WHERE id = ?`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"id",
")",
"\n",
"ag",
":=",
"AuthGroup",
"{",
"_exists",
":",
"true",
",",
"}",
"\n\n",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"sqlstr",
",",
"id",
")",
".",
"Scan",
"(",
"&",
"ag",
".",
"ID",
",",
"&",
"ag",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"ag",
",",
"nil",
"\n",
"}"
] |
// AuthGroupByID retrieves a row from 'django.auth_group' as a AuthGroup.
//
// Generated from index 'auth_group_id_pkey'.
|
[
"AuthGroupByID",
"retrieves",
"a",
"row",
"from",
"django",
".",
"auth_group",
"as",
"a",
"AuthGroup",
".",
"Generated",
"from",
"index",
"auth_group_id_pkey",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/mysql/authgroup.xo.go#L132-L153
|
22,809
|
xo/xo
|
examples/django/oracle/djangosession.xo.go
|
Save
|
func (ds *DjangoSession) Save(db XODB) error {
if ds.Exists() {
return ds.Update(db)
}
return ds.Insert(db)
}
|
go
|
func (ds *DjangoSession) Save(db XODB) error {
if ds.Exists() {
return ds.Update(db)
}
return ds.Insert(db)
}
|
[
"func",
"(",
"ds",
"*",
"DjangoSession",
")",
"Save",
"(",
"db",
"XODB",
")",
"error",
"{",
"if",
"ds",
".",
"Exists",
"(",
")",
"{",
"return",
"ds",
".",
"Update",
"(",
"db",
")",
"\n",
"}",
"\n\n",
"return",
"ds",
".",
"Insert",
"(",
"db",
")",
"\n",
"}"
] |
// Save saves the DjangoSession to the database.
|
[
"Save",
"saves",
"the",
"DjangoSession",
"to",
"the",
"database",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/djangosession.xo.go#L94-L100
|
22,810
|
xo/xo
|
examples/django/oracle/djangosession.xo.go
|
Delete
|
func (ds *DjangoSession) Delete(db XODB) error {
var err error
// if doesn't exist, bail
if !ds._exists {
return nil
}
// if deleted, bail
if ds._deleted {
return nil
}
// sql query
const sqlstr = `DELETE FROM django.django_session WHERE session_key = :1`
// run query
XOLog(sqlstr, ds.SessionKey)
_, err = db.Exec(sqlstr, ds.SessionKey)
if err != nil {
return err
}
// set deleted
ds._deleted = true
return nil
}
|
go
|
func (ds *DjangoSession) Delete(db XODB) error {
var err error
// if doesn't exist, bail
if !ds._exists {
return nil
}
// if deleted, bail
if ds._deleted {
return nil
}
// sql query
const sqlstr = `DELETE FROM django.django_session WHERE session_key = :1`
// run query
XOLog(sqlstr, ds.SessionKey)
_, err = db.Exec(sqlstr, ds.SessionKey)
if err != nil {
return err
}
// set deleted
ds._deleted = true
return nil
}
|
[
"func",
"(",
"ds",
"*",
"DjangoSession",
")",
"Delete",
"(",
"db",
"XODB",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"// if doesn't exist, bail",
"if",
"!",
"ds",
".",
"_exists",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// if deleted, bail",
"if",
"ds",
".",
"_deleted",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`DELETE FROM django.django_session WHERE session_key = :1`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"ds",
".",
"SessionKey",
")",
"\n",
"_",
",",
"err",
"=",
"db",
".",
"Exec",
"(",
"sqlstr",
",",
"ds",
".",
"SessionKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// set deleted",
"ds",
".",
"_deleted",
"=",
"true",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Delete deletes the DjangoSession from the database.
|
[
"Delete",
"deletes",
"the",
"DjangoSession",
"from",
"the",
"database",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/djangosession.xo.go#L103-L130
|
22,811
|
xo/xo
|
examples/django/oracle/authpermission.xo.go
|
Save
|
func (ap *AuthPermission) Save(db XODB) error {
if ap.Exists() {
return ap.Update(db)
}
return ap.Insert(db)
}
|
go
|
func (ap *AuthPermission) Save(db XODB) error {
if ap.Exists() {
return ap.Update(db)
}
return ap.Insert(db)
}
|
[
"func",
"(",
"ap",
"*",
"AuthPermission",
")",
"Save",
"(",
"db",
"XODB",
")",
"error",
"{",
"if",
"ap",
".",
"Exists",
"(",
")",
"{",
"return",
"ap",
".",
"Update",
"(",
"db",
")",
"\n",
"}",
"\n\n",
"return",
"ap",
".",
"Insert",
"(",
"db",
")",
"\n",
"}"
] |
// Save saves the AuthPermission to the database.
|
[
"Save",
"saves",
"the",
"AuthPermission",
"to",
"the",
"database",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authpermission.xo.go#L94-L100
|
22,812
|
xo/xo
|
examples/django/oracle/authpermission.xo.go
|
AuthPermissionsByContentTypeID
|
func AuthPermissionsByContentTypeID(db XODB, contentTypeID float64) ([]*AuthPermission, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, name, content_type_id, codename ` +
`FROM django.auth_permission ` +
`WHERE content_type_id = :1`
// run query
XOLog(sqlstr, contentTypeID)
q, err := db.Query(sqlstr, contentTypeID)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*AuthPermission{}
for q.Next() {
ap := AuthPermission{
_exists: true,
}
// scan
err = q.Scan(&ap.ID, &ap.Name, &ap.ContentTypeID, &ap.Codename)
if err != nil {
return nil, err
}
res = append(res, &ap)
}
return res, nil
}
|
go
|
func AuthPermissionsByContentTypeID(db XODB, contentTypeID float64) ([]*AuthPermission, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, name, content_type_id, codename ` +
`FROM django.auth_permission ` +
`WHERE content_type_id = :1`
// run query
XOLog(sqlstr, contentTypeID)
q, err := db.Query(sqlstr, contentTypeID)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*AuthPermission{}
for q.Next() {
ap := AuthPermission{
_exists: true,
}
// scan
err = q.Scan(&ap.ID, &ap.Name, &ap.ContentTypeID, &ap.Codename)
if err != nil {
return nil, err
}
res = append(res, &ap)
}
return res, nil
}
|
[
"func",
"AuthPermissionsByContentTypeID",
"(",
"db",
"XODB",
",",
"contentTypeID",
"float64",
")",
"(",
"[",
"]",
"*",
"AuthPermission",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`id, name, content_type_id, codename `",
"+",
"`FROM django.auth_permission `",
"+",
"`WHERE content_type_id = :1`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"contentTypeID",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"contentTypeID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"AuthPermission",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"ap",
":=",
"AuthPermission",
"{",
"_exists",
":",
"true",
",",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"ap",
".",
"ID",
",",
"&",
"ap",
".",
"Name",
",",
"&",
"ap",
".",
"ContentTypeID",
",",
"&",
"ap",
".",
"Codename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"ap",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// AuthPermissionsByContentTypeID retrieves a row from 'django.auth_permission' as a AuthPermission.
//
// Generated from index 'auth_permission_417f1b1c'.
|
[
"AuthPermissionsByContentTypeID",
"retrieves",
"a",
"row",
"from",
"django",
".",
"auth_permission",
"as",
"a",
"AuthPermission",
".",
"Generated",
"from",
"index",
"auth_permission_417f1b1c",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authpermission.xo.go#L142-L176
|
22,813
|
xo/xo
|
models/pgcolorder.xo.go
|
PgGetColOrder
|
func PgGetColOrder(db XODB, schema string, index string) (*PgColOrder, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`i.indkey ` + // ::varchar AS ord
`FROM pg_index i ` +
`JOIN ONLY pg_class c ON c.oid = i.indrelid ` +
`JOIN ONLY pg_namespace n ON n.oid = c.relnamespace ` +
`JOIN ONLY pg_class ic ON ic.oid = i.indexrelid ` +
`WHERE n.nspname = $1 AND ic.relname = $2`
// run query
XOLog(sqlstr, schema, index)
var pco PgColOrder
err = db.QueryRow(sqlstr, schema, index).Scan(&pco.Ord)
if err != nil {
return nil, err
}
return &pco, nil
}
|
go
|
func PgGetColOrder(db XODB, schema string, index string) (*PgColOrder, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`i.indkey ` + // ::varchar AS ord
`FROM pg_index i ` +
`JOIN ONLY pg_class c ON c.oid = i.indrelid ` +
`JOIN ONLY pg_namespace n ON n.oid = c.relnamespace ` +
`JOIN ONLY pg_class ic ON ic.oid = i.indexrelid ` +
`WHERE n.nspname = $1 AND ic.relname = $2`
// run query
XOLog(sqlstr, schema, index)
var pco PgColOrder
err = db.QueryRow(sqlstr, schema, index).Scan(&pco.Ord)
if err != nil {
return nil, err
}
return &pco, nil
}
|
[
"func",
"PgGetColOrder",
"(",
"db",
"XODB",
",",
"schema",
"string",
",",
"index",
"string",
")",
"(",
"*",
"PgColOrder",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`i.indkey `",
"+",
"// ::varchar AS ord",
"`FROM pg_index i `",
"+",
"`JOIN ONLY pg_class c ON c.oid = i.indrelid `",
"+",
"`JOIN ONLY pg_namespace n ON n.oid = c.relnamespace `",
"+",
"`JOIN ONLY pg_class ic ON ic.oid = i.indexrelid `",
"+",
"`WHERE n.nspname = $1 AND ic.relname = $2`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"schema",
",",
"index",
")",
"\n",
"var",
"pco",
"PgColOrder",
"\n",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"sqlstr",
",",
"schema",
",",
"index",
")",
".",
"Scan",
"(",
"&",
"pco",
".",
"Ord",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"pco",
",",
"nil",
"\n",
"}"
] |
// PgGetColOrder runs a custom query, returning results as PgColOrder.
|
[
"PgGetColOrder",
"runs",
"a",
"custom",
"query",
"returning",
"results",
"as",
"PgColOrder",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/pgcolorder.xo.go#L12-L33
|
22,814
|
xo/xo
|
internal/funcs.go
|
NewTemplateFuncs
|
func (a *ArgType) NewTemplateFuncs() template.FuncMap {
return template.FuncMap{
"colcount": a.colcount,
"colnames": a.colnames,
"colnamesmulti": a.colnamesmulti,
"colnamesquery": a.colnamesquery,
"colnamesquerymulti": a.colnamesquerymulti,
"colprefixnames": a.colprefixnames,
"colvals": a.colvals,
"colvalsmulti": a.colvalsmulti,
"fieldnames": a.fieldnames,
"fieldnamesmulti": a.fieldnamesmulti,
"goparamlist": a.goparamlist,
"reniltype": a.reniltype,
"retype": a.retype,
"shortname": a.shortname,
"convext": a.convext,
"schema": a.schemafn,
"colname": a.colname,
"hascolumn": a.hascolumn,
"hasfield": a.hasfield,
"getstartcount": a.getstartcount,
}
}
|
go
|
func (a *ArgType) NewTemplateFuncs() template.FuncMap {
return template.FuncMap{
"colcount": a.colcount,
"colnames": a.colnames,
"colnamesmulti": a.colnamesmulti,
"colnamesquery": a.colnamesquery,
"colnamesquerymulti": a.colnamesquerymulti,
"colprefixnames": a.colprefixnames,
"colvals": a.colvals,
"colvalsmulti": a.colvalsmulti,
"fieldnames": a.fieldnames,
"fieldnamesmulti": a.fieldnamesmulti,
"goparamlist": a.goparamlist,
"reniltype": a.reniltype,
"retype": a.retype,
"shortname": a.shortname,
"convext": a.convext,
"schema": a.schemafn,
"colname": a.colname,
"hascolumn": a.hascolumn,
"hasfield": a.hasfield,
"getstartcount": a.getstartcount,
}
}
|
[
"func",
"(",
"a",
"*",
"ArgType",
")",
"NewTemplateFuncs",
"(",
")",
"template",
".",
"FuncMap",
"{",
"return",
"template",
".",
"FuncMap",
"{",
"\"",
"\"",
":",
"a",
".",
"colcount",
",",
"\"",
"\"",
":",
"a",
".",
"colnames",
",",
"\"",
"\"",
":",
"a",
".",
"colnamesmulti",
",",
"\"",
"\"",
":",
"a",
".",
"colnamesquery",
",",
"\"",
"\"",
":",
"a",
".",
"colnamesquerymulti",
",",
"\"",
"\"",
":",
"a",
".",
"colprefixnames",
",",
"\"",
"\"",
":",
"a",
".",
"colvals",
",",
"\"",
"\"",
":",
"a",
".",
"colvalsmulti",
",",
"\"",
"\"",
":",
"a",
".",
"fieldnames",
",",
"\"",
"\"",
":",
"a",
".",
"fieldnamesmulti",
",",
"\"",
"\"",
":",
"a",
".",
"goparamlist",
",",
"\"",
"\"",
":",
"a",
".",
"reniltype",
",",
"\"",
"\"",
":",
"a",
".",
"retype",
",",
"\"",
"\"",
":",
"a",
".",
"shortname",
",",
"\"",
"\"",
":",
"a",
".",
"convext",
",",
"\"",
"\"",
":",
"a",
".",
"schemafn",
",",
"\"",
"\"",
":",
"a",
".",
"colname",
",",
"\"",
"\"",
":",
"a",
".",
"hascolumn",
",",
"\"",
"\"",
":",
"a",
".",
"hasfield",
",",
"\"",
"\"",
":",
"a",
".",
"getstartcount",
",",
"}",
"\n",
"}"
] |
// NewTemplateFuncs returns a set of template funcs bound to the supplied args.
|
[
"NewTemplateFuncs",
"returns",
"a",
"set",
"of",
"template",
"funcs",
"bound",
"to",
"the",
"supplied",
"args",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/funcs.go#L14-L37
|
22,815
|
xo/xo
|
internal/funcs.go
|
colcount
|
func (a *ArgType) colcount(fields []*Field, ignoreNames ...string) int {
ignore := map[string]bool{}
for _, n := range ignoreNames {
ignore[n] = true
}
i := 1
for _, f := range fields {
if ignore[f.Name] {
continue
}
i++
}
return i
}
|
go
|
func (a *ArgType) colcount(fields []*Field, ignoreNames ...string) int {
ignore := map[string]bool{}
for _, n := range ignoreNames {
ignore[n] = true
}
i := 1
for _, f := range fields {
if ignore[f.Name] {
continue
}
i++
}
return i
}
|
[
"func",
"(",
"a",
"*",
"ArgType",
")",
"colcount",
"(",
"fields",
"[",
"]",
"*",
"Field",
",",
"ignoreNames",
"...",
"string",
")",
"int",
"{",
"ignore",
":=",
"map",
"[",
"string",
"]",
"bool",
"{",
"}",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"ignoreNames",
"{",
"ignore",
"[",
"n",
"]",
"=",
"true",
"\n",
"}",
"\n\n",
"i",
":=",
"1",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"fields",
"{",
"if",
"ignore",
"[",
"f",
".",
"Name",
"]",
"{",
"continue",
"\n",
"}",
"\n\n",
"i",
"++",
"\n",
"}",
"\n",
"return",
"i",
"\n",
"}"
] |
// colcount returns the 1-based count of fields, excluding any Field with Name
// contained in ignoreNames.
//
// Used to get the count of fields, and useful for specifying the last SQL
// parameter.
|
[
"colcount",
"returns",
"the",
"1",
"-",
"based",
"count",
"of",
"fields",
"excluding",
"any",
"Field",
"with",
"Name",
"contained",
"in",
"ignoreNames",
".",
"Used",
"to",
"get",
"the",
"count",
"of",
"fields",
"and",
"useful",
"for",
"specifying",
"the",
"last",
"SQL",
"parameter",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/funcs.go#L429-L444
|
22,816
|
xo/xo
|
internal/funcs.go
|
schemafn
|
func (a *ArgType) schemafn(s string, names ...string) string {
// escape table names
if a.EscapeTableNames {
for i, t := range names {
names[i] = a.Loader.Escape(TableEsc, t)
}
}
n := strings.Join(names, ".")
if s == "" && n == "" {
return ""
}
if s != "" && n != "" {
if a.EscapeSchemaName {
s = a.Loader.Escape(SchemaEsc, s)
}
s = s + "."
}
return s + n
}
|
go
|
func (a *ArgType) schemafn(s string, names ...string) string {
// escape table names
if a.EscapeTableNames {
for i, t := range names {
names[i] = a.Loader.Escape(TableEsc, t)
}
}
n := strings.Join(names, ".")
if s == "" && n == "" {
return ""
}
if s != "" && n != "" {
if a.EscapeSchemaName {
s = a.Loader.Escape(SchemaEsc, s)
}
s = s + "."
}
return s + n
}
|
[
"func",
"(",
"a",
"*",
"ArgType",
")",
"schemafn",
"(",
"s",
"string",
",",
"names",
"...",
"string",
")",
"string",
"{",
"// escape table names",
"if",
"a",
".",
"EscapeTableNames",
"{",
"for",
"i",
",",
"t",
":=",
"range",
"names",
"{",
"names",
"[",
"i",
"]",
"=",
"a",
".",
"Loader",
".",
"Escape",
"(",
"TableEsc",
",",
"t",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"n",
":=",
"strings",
".",
"Join",
"(",
"names",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"s",
"==",
"\"",
"\"",
"&&",
"n",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"s",
"!=",
"\"",
"\"",
"&&",
"n",
"!=",
"\"",
"\"",
"{",
"if",
"a",
".",
"EscapeSchemaName",
"{",
"s",
"=",
"a",
".",
"Loader",
".",
"Escape",
"(",
"SchemaEsc",
",",
"s",
")",
"\n",
"}",
"\n",
"s",
"=",
"s",
"+",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"s",
"+",
"n",
"\n",
"}"
] |
// schemafn takes a series of names and joins them with the schema name.
|
[
"schemafn",
"takes",
"a",
"series",
"of",
"names",
"and",
"joins",
"them",
"with",
"the",
"schema",
"name",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/funcs.go#L577-L599
|
22,817
|
xo/xo
|
internal/funcs.go
|
colname
|
func (a *ArgType) colname(col *models.Column) string {
if a.EscapeColumnNames {
return a.Loader.Escape(ColumnEsc, col.ColumnName)
}
return col.ColumnName
}
|
go
|
func (a *ArgType) colname(col *models.Column) string {
if a.EscapeColumnNames {
return a.Loader.Escape(ColumnEsc, col.ColumnName)
}
return col.ColumnName
}
|
[
"func",
"(",
"a",
"*",
"ArgType",
")",
"colname",
"(",
"col",
"*",
"models",
".",
"Column",
")",
"string",
"{",
"if",
"a",
".",
"EscapeColumnNames",
"{",
"return",
"a",
".",
"Loader",
".",
"Escape",
"(",
"ColumnEsc",
",",
"col",
".",
"ColumnName",
")",
"\n",
"}",
"\n\n",
"return",
"col",
".",
"ColumnName",
"\n",
"}"
] |
// colname returns the ColumnName of col, optionally escaping it if
// ArgType.EscapeColumnNames is toggled.
|
[
"colname",
"returns",
"the",
"ColumnName",
"of",
"col",
"optionally",
"escaping",
"it",
"if",
"ArgType",
".",
"EscapeColumnNames",
"is",
"toggled",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/funcs.go#L603-L609
|
22,818
|
xo/xo
|
internal/funcs.go
|
hascolumn
|
func (a *ArgType) hascolumn(fields []*Field, name string) bool {
for _, f := range fields {
if f.Col.ColumnName == name {
return true
}
}
return false
}
|
go
|
func (a *ArgType) hascolumn(fields []*Field, name string) bool {
for _, f := range fields {
if f.Col.ColumnName == name {
return true
}
}
return false
}
|
[
"func",
"(",
"a",
"*",
"ArgType",
")",
"hascolumn",
"(",
"fields",
"[",
"]",
"*",
"Field",
",",
"name",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"fields",
"{",
"if",
"f",
".",
"Col",
".",
"ColumnName",
"==",
"name",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// hascolumn takes a list of fields and determines if field with the specified
// column name is in the list.
|
[
"hascolumn",
"takes",
"a",
"list",
"of",
"fields",
"and",
"determines",
"if",
"field",
"with",
"the",
"specified",
"column",
"name",
"is",
"in",
"the",
"list",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/funcs.go#L613-L621
|
22,819
|
xo/xo
|
internal/funcs.go
|
hasfield
|
func (a *ArgType) hasfield(fields []*Field, name string) bool {
for _, f := range fields {
if f.Name == name {
return true
}
}
return false
}
|
go
|
func (a *ArgType) hasfield(fields []*Field, name string) bool {
for _, f := range fields {
if f.Name == name {
return true
}
}
return false
}
|
[
"func",
"(",
"a",
"*",
"ArgType",
")",
"hasfield",
"(",
"fields",
"[",
"]",
"*",
"Field",
",",
"name",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"fields",
"{",
"if",
"f",
".",
"Name",
"==",
"name",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// hasfield takes a list of fields and determines if field with the specified
// field name is in the list.
|
[
"hasfield",
"takes",
"a",
"list",
"of",
"fields",
"and",
"determines",
"if",
"field",
"with",
"the",
"specified",
"field",
"name",
"is",
"in",
"the",
"list",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/funcs.go#L625-L633
|
22,820
|
xo/xo
|
internal/funcs.go
|
getstartcount
|
func (a *ArgType) getstartcount(fields []*Field, pkFields []*Field) int {
return len(fields) - len(pkFields)
}
|
go
|
func (a *ArgType) getstartcount(fields []*Field, pkFields []*Field) int {
return len(fields) - len(pkFields)
}
|
[
"func",
"(",
"a",
"*",
"ArgType",
")",
"getstartcount",
"(",
"fields",
"[",
"]",
"*",
"Field",
",",
"pkFields",
"[",
"]",
"*",
"Field",
")",
"int",
"{",
"return",
"len",
"(",
"fields",
")",
"-",
"len",
"(",
"pkFields",
")",
"\n",
"}"
] |
// getstartcount returns a starting count for numbering columsn in queries
|
[
"getstartcount",
"returns",
"a",
"starting",
"count",
"for",
"numbering",
"columsn",
"in",
"queries"
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/funcs.go#L636-L638
|
22,821
|
xo/xo
|
models/enum.xo.go
|
PgEnums
|
func PgEnums(db XODB, schema string) ([]*Enum, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`t.typname ` + // ::varchar AS enum_name
`FROM pg_type t ` +
`JOIN ONLY pg_namespace n ON n.oid = t.typnamespace ` +
`JOIN ONLY pg_enum e ON t.oid = e.enumtypid ` +
`WHERE n.nspname = $1`
// run query
XOLog(sqlstr, schema)
q, err := db.Query(sqlstr, schema)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*Enum{}
for q.Next() {
e := Enum{}
// scan
err = q.Scan(&e.EnumName)
if err != nil {
return nil, err
}
res = append(res, &e)
}
return res, nil
}
|
go
|
func PgEnums(db XODB, schema string) ([]*Enum, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`t.typname ` + // ::varchar AS enum_name
`FROM pg_type t ` +
`JOIN ONLY pg_namespace n ON n.oid = t.typnamespace ` +
`JOIN ONLY pg_enum e ON t.oid = e.enumtypid ` +
`WHERE n.nspname = $1`
// run query
XOLog(sqlstr, schema)
q, err := db.Query(sqlstr, schema)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*Enum{}
for q.Next() {
e := Enum{}
// scan
err = q.Scan(&e.EnumName)
if err != nil {
return nil, err
}
res = append(res, &e)
}
return res, nil
}
|
[
"func",
"PgEnums",
"(",
"db",
"XODB",
",",
"schema",
"string",
")",
"(",
"[",
"]",
"*",
"Enum",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`t.typname `",
"+",
"// ::varchar AS enum_name",
"`FROM pg_type t `",
"+",
"`JOIN ONLY pg_namespace n ON n.oid = t.typnamespace `",
"+",
"`JOIN ONLY pg_enum e ON t.oid = e.enumtypid `",
"+",
"`WHERE n.nspname = $1`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"schema",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"schema",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"Enum",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"e",
":=",
"Enum",
"{",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"e",
".",
"EnumName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"e",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// PgEnums runs a custom query, returning results as Enum.
|
[
"PgEnums",
"runs",
"a",
"custom",
"query",
"returning",
"results",
"as",
"Enum",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/enum.xo.go#L12-L46
|
22,822
|
xo/xo
|
internal/types.go
|
String
|
func (tt TemplateType) String() string {
var s string
switch tt {
case XOTemplate:
s = "xo_db"
case EnumTemplate:
s = "enum"
case ProcTemplate:
s = "proc"
case TypeTemplate:
s = "type"
case ForeignKeyTemplate:
s = "foreignkey"
case IndexTemplate:
s = "index"
case QueryTypeTemplate:
s = "querytype"
case QueryTemplate:
s = "query"
default:
panic("unknown TemplateType")
}
return s
}
|
go
|
func (tt TemplateType) String() string {
var s string
switch tt {
case XOTemplate:
s = "xo_db"
case EnumTemplate:
s = "enum"
case ProcTemplate:
s = "proc"
case TypeTemplate:
s = "type"
case ForeignKeyTemplate:
s = "foreignkey"
case IndexTemplate:
s = "index"
case QueryTypeTemplate:
s = "querytype"
case QueryTemplate:
s = "query"
default:
panic("unknown TemplateType")
}
return s
}
|
[
"func",
"(",
"tt",
"TemplateType",
")",
"String",
"(",
")",
"string",
"{",
"var",
"s",
"string",
"\n",
"switch",
"tt",
"{",
"case",
"XOTemplate",
":",
"s",
"=",
"\"",
"\"",
"\n",
"case",
"EnumTemplate",
":",
"s",
"=",
"\"",
"\"",
"\n",
"case",
"ProcTemplate",
":",
"s",
"=",
"\"",
"\"",
"\n",
"case",
"TypeTemplate",
":",
"s",
"=",
"\"",
"\"",
"\n",
"case",
"ForeignKeyTemplate",
":",
"s",
"=",
"\"",
"\"",
"\n",
"case",
"IndexTemplate",
":",
"s",
"=",
"\"",
"\"",
"\n",
"case",
"QueryTypeTemplate",
":",
"s",
"=",
"\"",
"\"",
"\n",
"case",
"QueryTemplate",
":",
"s",
"=",
"\"",
"\"",
"\n",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] |
// String returns the name for the associated template type.
|
[
"String",
"returns",
"the",
"name",
"for",
"the",
"associated",
"template",
"type",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/types.go#L23-L46
|
22,823
|
xo/xo
|
internal/types.go
|
String
|
func (rt RelType) String() string {
var s string
switch rt {
case Table:
s = "TABLE"
case View:
s = "VIEW"
default:
panic("unknown RelType")
}
return s
}
|
go
|
func (rt RelType) String() string {
var s string
switch rt {
case Table:
s = "TABLE"
case View:
s = "VIEW"
default:
panic("unknown RelType")
}
return s
}
|
[
"func",
"(",
"rt",
"RelType",
")",
"String",
"(",
")",
"string",
"{",
"var",
"s",
"string",
"\n",
"switch",
"rt",
"{",
"case",
"Table",
":",
"s",
"=",
"\"",
"\"",
"\n",
"case",
"View",
":",
"s",
"=",
"\"",
"\"",
"\n",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] |
// String provides the string representation of RelType.
|
[
"String",
"provides",
"the",
"string",
"representation",
"of",
"RelType",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/types.go#L69-L80
|
22,824
|
xo/xo
|
examples/django/oracle/djangoadminlog.xo.go
|
Save
|
func (dal *DjangoAdminLog) Save(db XODB) error {
if dal.Exists() {
return dal.Update(db)
}
return dal.Insert(db)
}
|
go
|
func (dal *DjangoAdminLog) Save(db XODB) error {
if dal.Exists() {
return dal.Update(db)
}
return dal.Insert(db)
}
|
[
"func",
"(",
"dal",
"*",
"DjangoAdminLog",
")",
"Save",
"(",
"db",
"XODB",
")",
"error",
"{",
"if",
"dal",
".",
"Exists",
"(",
")",
"{",
"return",
"dal",
".",
"Update",
"(",
"db",
")",
"\n",
"}",
"\n\n",
"return",
"dal",
".",
"Insert",
"(",
"db",
")",
"\n",
"}"
] |
// Save saves the DjangoAdminLog to the database.
|
[
"Save",
"saves",
"the",
"DjangoAdminLog",
"to",
"the",
"database",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/djangoadminlog.xo.go#L99-L105
|
22,825
|
xo/xo
|
examples/django/oracle/djangoadminlog.xo.go
|
DjangoAdminLogsByUserID
|
func DjangoAdminLogsByUserID(db XODB, userID float64) ([]*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 django.django_admin_log ` +
`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 := []*DjangoAdminLog{}
for q.Next() {
dal := DjangoAdminLog{
_exists: true,
}
// scan
err = q.Scan(&dal.ID, &dal.ActionTime, &dal.ObjectID, &dal.ObjectRepr, &dal.ActionFlag, &dal.ChangeMessage, &dal.ContentTypeID, &dal.UserID)
if err != nil {
return nil, err
}
res = append(res, &dal)
}
return res, nil
}
|
go
|
func DjangoAdminLogsByUserID(db XODB, userID float64) ([]*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 django.django_admin_log ` +
`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 := []*DjangoAdminLog{}
for q.Next() {
dal := DjangoAdminLog{
_exists: true,
}
// scan
err = q.Scan(&dal.ID, &dal.ActionTime, &dal.ObjectID, &dal.ObjectRepr, &dal.ActionFlag, &dal.ChangeMessage, &dal.ContentTypeID, &dal.UserID)
if err != nil {
return nil, err
}
res = append(res, &dal)
}
return res, nil
}
|
[
"func",
"DjangoAdminLogsByUserID",
"(",
"db",
"XODB",
",",
"userID",
"float64",
")",
"(",
"[",
"]",
"*",
"DjangoAdminLog",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`id, action_time, object_id, object_repr, action_flag, change_message, content_type_id, user_id `",
"+",
"`FROM django.django_admin_log `",
"+",
"`WHERE user_id = :1`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"userID",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"userID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"DjangoAdminLog",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"dal",
":=",
"DjangoAdminLog",
"{",
"_exists",
":",
"true",
",",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"dal",
".",
"ID",
",",
"&",
"dal",
".",
"ActionTime",
",",
"&",
"dal",
".",
"ObjectID",
",",
"&",
"dal",
".",
"ObjectRepr",
",",
"&",
"dal",
".",
"ActionFlag",
",",
"&",
"dal",
".",
"ChangeMessage",
",",
"&",
"dal",
".",
"ContentTypeID",
",",
"&",
"dal",
".",
"UserID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"dal",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// DjangoAdminLogsByUserID retrieves a row from 'django.django_admin_log' as a DjangoAdminLog.
//
// Generated from index 'django_admin_log_e8701ad4'.
|
[
"DjangoAdminLogsByUserID",
"retrieves",
"a",
"row",
"from",
"django",
".",
"django_admin_log",
"as",
"a",
"DjangoAdminLog",
".",
"Generated",
"from",
"index",
"django_admin_log_e8701ad4",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/djangoadminlog.xo.go#L193-L227
|
22,826
|
xo/xo
|
examples/django/sqlite3/authuser.xo.go
|
Save
|
func (au *AuthUser) Save(db XODB) error {
if au.Exists() {
return au.Update(db)
}
return au.Insert(db)
}
|
go
|
func (au *AuthUser) Save(db XODB) error {
if au.Exists() {
return au.Update(db)
}
return au.Insert(db)
}
|
[
"func",
"(",
"au",
"*",
"AuthUser",
")",
"Save",
"(",
"db",
"XODB",
")",
"error",
"{",
"if",
"au",
".",
"Exists",
"(",
")",
"{",
"return",
"au",
".",
"Update",
"(",
"db",
")",
"\n",
"}",
"\n\n",
"return",
"au",
".",
"Insert",
"(",
"db",
")",
"\n",
"}"
] |
// Save saves the AuthUser to the database.
|
[
"Save",
"saves",
"the",
"AuthUser",
"to",
"the",
"database",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/sqlite3/authuser.xo.go#L101-L107
|
22,827
|
xo/xo
|
examples/django/sqlite3/djangoadminlog.xo.go
|
DjangoAdminLogByID
|
func DjangoAdminLogByID(db XODB, id int) (*DjangoAdminLog, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, object_id, object_repr, action_flag, change_message, content_type_id, user_id, action_time ` +
`FROM django_admin_log ` +
`WHERE id = ?`
// run query
XOLog(sqlstr, id)
dal := DjangoAdminLog{
_exists: true,
}
err = db.QueryRow(sqlstr, id).Scan(&dal.ID, &dal.ObjectID, &dal.ObjectRepr, &dal.ActionFlag, &dal.ChangeMessage, &dal.ContentTypeID, &dal.UserID, &dal.ActionTime)
if err != nil {
return nil, err
}
return &dal, nil
}
|
go
|
func DjangoAdminLogByID(db XODB, id int) (*DjangoAdminLog, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, object_id, object_repr, action_flag, change_message, content_type_id, user_id, action_time ` +
`FROM django_admin_log ` +
`WHERE id = ?`
// run query
XOLog(sqlstr, id)
dal := DjangoAdminLog{
_exists: true,
}
err = db.QueryRow(sqlstr, id).Scan(&dal.ID, &dal.ObjectID, &dal.ObjectRepr, &dal.ActionFlag, &dal.ChangeMessage, &dal.ContentTypeID, &dal.UserID, &dal.ActionTime)
if err != nil {
return nil, err
}
return &dal, nil
}
|
[
"func",
"DjangoAdminLogByID",
"(",
"db",
"XODB",
",",
"id",
"int",
")",
"(",
"*",
"DjangoAdminLog",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`id, object_id, object_repr, action_flag, change_message, content_type_id, user_id, action_time `",
"+",
"`FROM django_admin_log `",
"+",
"`WHERE id = ?`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"id",
")",
"\n",
"dal",
":=",
"DjangoAdminLog",
"{",
"_exists",
":",
"true",
",",
"}",
"\n\n",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"sqlstr",
",",
"id",
")",
".",
"Scan",
"(",
"&",
"dal",
".",
"ID",
",",
"&",
"dal",
".",
"ObjectID",
",",
"&",
"dal",
".",
"ObjectRepr",
",",
"&",
"dal",
".",
"ActionFlag",
",",
"&",
"dal",
".",
"ChangeMessage",
",",
"&",
"dal",
".",
"ContentTypeID",
",",
"&",
"dal",
".",
"UserID",
",",
"&",
"dal",
".",
"ActionTime",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"dal",
",",
"nil",
"\n",
"}"
] |
// DjangoAdminLogByID retrieves a row from 'django_admin_log' as a DjangoAdminLog.
//
// Generated from index 'django_admin_log_id_pkey'.
|
[
"DjangoAdminLogByID",
"retrieves",
"a",
"row",
"from",
"django_admin_log",
"as",
"a",
"DjangoAdminLog",
".",
"Generated",
"from",
"index",
"django_admin_log_id_pkey",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/sqlite3/djangoadminlog.xo.go#L232-L253
|
22,828
|
xo/xo
|
examples/django/postgres/authgroup.xo.go
|
AuthGroupsByName
|
func AuthGroupsByName(db XODB, name string) ([]*AuthGroup, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, name ` +
`FROM public.auth_group ` +
`WHERE name = $1`
// run query
XOLog(sqlstr, name)
q, err := db.Query(sqlstr, name)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*AuthGroup{}
for q.Next() {
ag := AuthGroup{
_exists: true,
}
// scan
err = q.Scan(&ag.ID, &ag.Name)
if err != nil {
return nil, err
}
res = append(res, &ag)
}
return res, nil
}
|
go
|
func AuthGroupsByName(db XODB, name string) ([]*AuthGroup, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, name ` +
`FROM public.auth_group ` +
`WHERE name = $1`
// run query
XOLog(sqlstr, name)
q, err := db.Query(sqlstr, name)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*AuthGroup{}
for q.Next() {
ag := AuthGroup{
_exists: true,
}
// scan
err = q.Scan(&ag.ID, &ag.Name)
if err != nil {
return nil, err
}
res = append(res, &ag)
}
return res, nil
}
|
[
"func",
"AuthGroupsByName",
"(",
"db",
"XODB",
",",
"name",
"string",
")",
"(",
"[",
"]",
"*",
"AuthGroup",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`id, name `",
"+",
"`FROM public.auth_group `",
"+",
"`WHERE name = $1`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"name",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"AuthGroup",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"ag",
":=",
"AuthGroup",
"{",
"_exists",
":",
"true",
",",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"ag",
".",
"ID",
",",
"&",
"ag",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"ag",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// AuthGroupsByName retrieves a row from 'public.auth_group' as a AuthGroup.
//
// Generated from index 'auth_group_name_a6ea08ec_like'.
|
[
"AuthGroupsByName",
"retrieves",
"a",
"row",
"from",
"public",
".",
"auth_group",
"as",
"a",
"AuthGroup",
".",
"Generated",
"from",
"index",
"auth_group_name_a6ea08ec_like",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authgroup.xo.go#L162-L196
|
22,829
|
xo/xo
|
examples/django/postgres/authgroup.xo.go
|
AuthGroupByName
|
func AuthGroupByName(db XODB, name string) (*AuthGroup, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, name ` +
`FROM public.auth_group ` +
`WHERE name = $1`
// run query
XOLog(sqlstr, name)
ag := AuthGroup{
_exists: true,
}
err = db.QueryRow(sqlstr, name).Scan(&ag.ID, &ag.Name)
if err != nil {
return nil, err
}
return &ag, nil
}
|
go
|
func AuthGroupByName(db XODB, name string) (*AuthGroup, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, name ` +
`FROM public.auth_group ` +
`WHERE name = $1`
// run query
XOLog(sqlstr, name)
ag := AuthGroup{
_exists: true,
}
err = db.QueryRow(sqlstr, name).Scan(&ag.ID, &ag.Name)
if err != nil {
return nil, err
}
return &ag, nil
}
|
[
"func",
"AuthGroupByName",
"(",
"db",
"XODB",
",",
"name",
"string",
")",
"(",
"*",
"AuthGroup",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`id, name `",
"+",
"`FROM public.auth_group `",
"+",
"`WHERE name = $1`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"name",
")",
"\n",
"ag",
":=",
"AuthGroup",
"{",
"_exists",
":",
"true",
",",
"}",
"\n\n",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"sqlstr",
",",
"name",
")",
".",
"Scan",
"(",
"&",
"ag",
".",
"ID",
",",
"&",
"ag",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"ag",
",",
"nil",
"\n",
"}"
] |
// AuthGroupByName retrieves a row from 'public.auth_group' as a AuthGroup.
//
// Generated from index 'auth_group_name_key'.
|
[
"AuthGroupByName",
"retrieves",
"a",
"row",
"from",
"public",
".",
"auth_group",
"as",
"a",
"AuthGroup",
".",
"Generated",
"from",
"index",
"auth_group_name_key",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authgroup.xo.go#L201-L222
|
22,830
|
xo/xo
|
models/index.xo.go
|
PgTableIndexes
|
func PgTableIndexes(db XODB, schema string, table string) ([]*Index, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`DISTINCT ic.relname, ` + // ::varchar AS index_name
`i.indisunique, ` + // ::boolean AS is_unique
`i.indisprimary, ` + // ::boolean AS is_primary
`0, ` + // ::integer AS seq_no
`'', ` + // ::varchar AS origin
`false ` + // ::boolean AS is_partial
`FROM pg_index i ` +
`JOIN ONLY pg_class c ON c.oid = i.indrelid ` +
`JOIN ONLY pg_namespace n ON n.oid = c.relnamespace ` +
`JOIN ONLY pg_class ic ON ic.oid = i.indexrelid ` +
`WHERE i.indkey <> '0' AND n.nspname = $1 AND c.relname = $2`
// run query
XOLog(sqlstr, schema, table)
q, err := db.Query(sqlstr, schema, table)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*Index{}
for q.Next() {
i := Index{}
// scan
err = q.Scan(&i.IndexName, &i.IsUnique, &i.IsPrimary, &i.SeqNo, &i.Origin, &i.IsPartial)
if err != nil {
return nil, err
}
res = append(res, &i)
}
return res, nil
}
|
go
|
func PgTableIndexes(db XODB, schema string, table string) ([]*Index, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`DISTINCT ic.relname, ` + // ::varchar AS index_name
`i.indisunique, ` + // ::boolean AS is_unique
`i.indisprimary, ` + // ::boolean AS is_primary
`0, ` + // ::integer AS seq_no
`'', ` + // ::varchar AS origin
`false ` + // ::boolean AS is_partial
`FROM pg_index i ` +
`JOIN ONLY pg_class c ON c.oid = i.indrelid ` +
`JOIN ONLY pg_namespace n ON n.oid = c.relnamespace ` +
`JOIN ONLY pg_class ic ON ic.oid = i.indexrelid ` +
`WHERE i.indkey <> '0' AND n.nspname = $1 AND c.relname = $2`
// run query
XOLog(sqlstr, schema, table)
q, err := db.Query(sqlstr, schema, table)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*Index{}
for q.Next() {
i := Index{}
// scan
err = q.Scan(&i.IndexName, &i.IsUnique, &i.IsPrimary, &i.SeqNo, &i.Origin, &i.IsPartial)
if err != nil {
return nil, err
}
res = append(res, &i)
}
return res, nil
}
|
[
"func",
"PgTableIndexes",
"(",
"db",
"XODB",
",",
"schema",
"string",
",",
"table",
"string",
")",
"(",
"[",
"]",
"*",
"Index",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`DISTINCT ic.relname, `",
"+",
"// ::varchar AS index_name",
"`i.indisunique, `",
"+",
"// ::boolean AS is_unique",
"`i.indisprimary, `",
"+",
"// ::boolean AS is_primary",
"`0, `",
"+",
"// ::integer AS seq_no",
"`'', `",
"+",
"// ::varchar AS origin",
"`false `",
"+",
"// ::boolean AS is_partial",
"`FROM pg_index i `",
"+",
"`JOIN ONLY pg_class c ON c.oid = i.indrelid `",
"+",
"`JOIN ONLY pg_namespace n ON n.oid = c.relnamespace `",
"+",
"`JOIN ONLY pg_class ic ON ic.oid = i.indexrelid `",
"+",
"`WHERE i.indkey <> '0' AND n.nspname = $1 AND c.relname = $2`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"schema",
",",
"table",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"schema",
",",
"table",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"Index",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"i",
":=",
"Index",
"{",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"i",
".",
"IndexName",
",",
"&",
"i",
".",
"IsUnique",
",",
"&",
"i",
".",
"IsPrimary",
",",
"&",
"i",
".",
"SeqNo",
",",
"&",
"i",
".",
"Origin",
",",
"&",
"i",
".",
"IsPartial",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"i",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// PgTableIndexes runs a custom query, returning results as Index.
|
[
"PgTableIndexes",
"runs",
"a",
"custom",
"query",
"returning",
"results",
"as",
"Index",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/index.xo.go#L17-L57
|
22,831
|
xo/xo
|
models/table.xo.go
|
MsTables
|
func MsTables(db XODB, schema string, relkind string) ([]*Table, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`xtype AS type, ` +
`name AS table_name ` +
`FROM sysobjects ` +
`WHERE SCHEMA_NAME(uid) = $1 AND xtype = $2`
// run query
XOLog(sqlstr, schema, relkind)
q, err := db.Query(sqlstr, schema, relkind)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*Table{}
for q.Next() {
t := Table{}
// scan
err = q.Scan(&t.Type, &t.TableName)
if err != nil {
return nil, err
}
res = append(res, &t)
}
return res, nil
}
|
go
|
func MsTables(db XODB, schema string, relkind string) ([]*Table, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`xtype AS type, ` +
`name AS table_name ` +
`FROM sysobjects ` +
`WHERE SCHEMA_NAME(uid) = $1 AND xtype = $2`
// run query
XOLog(sqlstr, schema, relkind)
q, err := db.Query(sqlstr, schema, relkind)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*Table{}
for q.Next() {
t := Table{}
// scan
err = q.Scan(&t.Type, &t.TableName)
if err != nil {
return nil, err
}
res = append(res, &t)
}
return res, nil
}
|
[
"func",
"MsTables",
"(",
"db",
"XODB",
",",
"schema",
"string",
",",
"relkind",
"string",
")",
"(",
"[",
"]",
"*",
"Table",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`xtype AS type, `",
"+",
"`name AS table_name `",
"+",
"`FROM sysobjects `",
"+",
"`WHERE SCHEMA_NAME(uid) = $1 AND xtype = $2`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"schema",
",",
"relkind",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"schema",
",",
"relkind",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"Table",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"t",
":=",
"Table",
"{",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"t",
".",
"Type",
",",
"&",
"t",
".",
"TableName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"t",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// MsTables runs a custom query, returning results as Table.
|
[
"MsTables",
"runs",
"a",
"custom",
"query",
"returning",
"results",
"as",
"Table",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/table.xo.go#L122-L155
|
22,832
|
xo/xo
|
models/enumvalue.xo.go
|
PgEnumValues
|
func PgEnumValues(db XODB, schema string, enum string) ([]*EnumValue, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`e.enumlabel, ` + // ::varchar AS enum_value
`e.enumsortorder ` + // ::integer AS const_value
`FROM pg_type t ` +
`JOIN ONLY pg_namespace n ON n.oid = t.typnamespace ` +
`LEFT JOIN pg_enum e ON t.oid = e.enumtypid ` +
`WHERE n.nspname = $1 AND t.typname = $2`
// run query
XOLog(sqlstr, schema, enum)
q, err := db.Query(sqlstr, schema, enum)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*EnumValue{}
for q.Next() {
ev := EnumValue{}
// scan
err = q.Scan(&ev.EnumValue, &ev.ConstValue)
if err != nil {
return nil, err
}
res = append(res, &ev)
}
return res, nil
}
|
go
|
func PgEnumValues(db XODB, schema string, enum string) ([]*EnumValue, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`e.enumlabel, ` + // ::varchar AS enum_value
`e.enumsortorder ` + // ::integer AS const_value
`FROM pg_type t ` +
`JOIN ONLY pg_namespace n ON n.oid = t.typnamespace ` +
`LEFT JOIN pg_enum e ON t.oid = e.enumtypid ` +
`WHERE n.nspname = $1 AND t.typname = $2`
// run query
XOLog(sqlstr, schema, enum)
q, err := db.Query(sqlstr, schema, enum)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*EnumValue{}
for q.Next() {
ev := EnumValue{}
// scan
err = q.Scan(&ev.EnumValue, &ev.ConstValue)
if err != nil {
return nil, err
}
res = append(res, &ev)
}
return res, nil
}
|
[
"func",
"PgEnumValues",
"(",
"db",
"XODB",
",",
"schema",
"string",
",",
"enum",
"string",
")",
"(",
"[",
"]",
"*",
"EnumValue",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`e.enumlabel, `",
"+",
"// ::varchar AS enum_value",
"`e.enumsortorder `",
"+",
"// ::integer AS const_value",
"`FROM pg_type t `",
"+",
"`JOIN ONLY pg_namespace n ON n.oid = t.typnamespace `",
"+",
"`LEFT JOIN pg_enum e ON t.oid = e.enumtypid `",
"+",
"`WHERE n.nspname = $1 AND t.typname = $2`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"schema",
",",
"enum",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"schema",
",",
"enum",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"EnumValue",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"ev",
":=",
"EnumValue",
"{",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"ev",
".",
"EnumValue",
",",
"&",
"ev",
".",
"ConstValue",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"ev",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// PgEnumValues runs a custom query, returning results as EnumValue.
|
[
"PgEnumValues",
"runs",
"a",
"custom",
"query",
"returning",
"results",
"as",
"EnumValue",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/enumvalue.xo.go#L13-L48
|
22,833
|
xo/xo
|
loaders/oracle.go
|
OrParseType
|
func OrParseType(args *internal.ArgType, dt string, nullable bool) (int, string, string) {
nilVal := "nil"
dt = strings.ToLower(dt)
// extract precision
dt, precision, scale := args.ParsePrecision(dt)
var typ string
// strip remaining length (on things like timestamp)
switch OrLenRE.ReplaceAllString(dt, "") {
case "char", "nchar", "varchar", "varchar2", "nvarchar2",
"long",
"clob", "nclob",
"rowid":
nilVal = `""`
typ = "string"
case "shortint":
nilVal = "0"
typ = "int16"
if nullable {
nilVal = "sql.NullInt64{}"
typ = "sql.NullInt64"
}
case "integer":
nilVal = "0"
typ = args.Int32Type
if nullable {
nilVal = "sql.NullInt64{}"
typ = "sql.NullInt64"
}
case "longinteger":
nilVal = "0"
typ = "int64"
if nullable {
nilVal = "sql.NullInt64{}"
typ = "sql.NullInt64"
}
case "float", "shortdecimal":
nilVal = "0.0"
typ = "float32"
if nullable {
nilVal = "sql.NullFloat64{}"
typ = "sql.NullFloat64"
}
case "number", "decimal":
nilVal = "0.0"
if 0 < precision && precision < 18 && scale > 0 {
typ = "float64"
if nullable {
nilVal = "sql.NullFloat64{}"
typ = "sql.NullFloat64"
}
} else if 0 < precision && precision <= 19 && scale == 0 {
typ = "int64"
if nullable {
nilVal = "sql.NullInt64{}"
typ = "sql.NullInt64"
}
} else {
nilVal = `""`
typ = "string"
}
case "blob", "long raw", "raw":
typ = "[]byte"
case "date", "timestamp", "timestamp with time zone":
typ = "time.Time"
nilVal = "time.Time{}"
default:
// bail
fmt.Fprintf(os.Stderr, "error: unknown type %q\n", dt)
os.Exit(1)
}
// special case for bool
if typ == "int" && precision == 1 {
nilVal = "false"
typ = "bool"
if nullable {
nilVal = "sql.NullBool{}"
typ = "sql.NullBool"
}
}
return precision, nilVal, typ
}
|
go
|
func OrParseType(args *internal.ArgType, dt string, nullable bool) (int, string, string) {
nilVal := "nil"
dt = strings.ToLower(dt)
// extract precision
dt, precision, scale := args.ParsePrecision(dt)
var typ string
// strip remaining length (on things like timestamp)
switch OrLenRE.ReplaceAllString(dt, "") {
case "char", "nchar", "varchar", "varchar2", "nvarchar2",
"long",
"clob", "nclob",
"rowid":
nilVal = `""`
typ = "string"
case "shortint":
nilVal = "0"
typ = "int16"
if nullable {
nilVal = "sql.NullInt64{}"
typ = "sql.NullInt64"
}
case "integer":
nilVal = "0"
typ = args.Int32Type
if nullable {
nilVal = "sql.NullInt64{}"
typ = "sql.NullInt64"
}
case "longinteger":
nilVal = "0"
typ = "int64"
if nullable {
nilVal = "sql.NullInt64{}"
typ = "sql.NullInt64"
}
case "float", "shortdecimal":
nilVal = "0.0"
typ = "float32"
if nullable {
nilVal = "sql.NullFloat64{}"
typ = "sql.NullFloat64"
}
case "number", "decimal":
nilVal = "0.0"
if 0 < precision && precision < 18 && scale > 0 {
typ = "float64"
if nullable {
nilVal = "sql.NullFloat64{}"
typ = "sql.NullFloat64"
}
} else if 0 < precision && precision <= 19 && scale == 0 {
typ = "int64"
if nullable {
nilVal = "sql.NullInt64{}"
typ = "sql.NullInt64"
}
} else {
nilVal = `""`
typ = "string"
}
case "blob", "long raw", "raw":
typ = "[]byte"
case "date", "timestamp", "timestamp with time zone":
typ = "time.Time"
nilVal = "time.Time{}"
default:
// bail
fmt.Fprintf(os.Stderr, "error: unknown type %q\n", dt)
os.Exit(1)
}
// special case for bool
if typ == "int" && precision == 1 {
nilVal = "false"
typ = "bool"
if nullable {
nilVal = "sql.NullBool{}"
typ = "sql.NullBool"
}
}
return precision, nilVal, typ
}
|
[
"func",
"OrParseType",
"(",
"args",
"*",
"internal",
".",
"ArgType",
",",
"dt",
"string",
",",
"nullable",
"bool",
")",
"(",
"int",
",",
"string",
",",
"string",
")",
"{",
"nilVal",
":=",
"\"",
"\"",
"\n\n",
"dt",
"=",
"strings",
".",
"ToLower",
"(",
"dt",
")",
"\n\n",
"// extract precision",
"dt",
",",
"precision",
",",
"scale",
":=",
"args",
".",
"ParsePrecision",
"(",
"dt",
")",
"\n\n",
"var",
"typ",
"string",
"\n",
"// strip remaining length (on things like timestamp)",
"switch",
"OrLenRE",
".",
"ReplaceAllString",
"(",
"dt",
",",
"\"",
"\"",
")",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"nilVal",
"=",
"`\"\"`",
"\n",
"typ",
"=",
"\"",
"\"",
"\n\n",
"case",
"\"",
"\"",
":",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"if",
"nullable",
"{",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"args",
".",
"Int32Type",
"\n",
"if",
"nullable",
"{",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"if",
"nullable",
"{",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"if",
"nullable",
"{",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"nilVal",
"=",
"\"",
"\"",
"\n",
"if",
"0",
"<",
"precision",
"&&",
"precision",
"<",
"18",
"&&",
"scale",
">",
"0",
"{",
"typ",
"=",
"\"",
"\"",
"\n",
"if",
"nullable",
"{",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"else",
"if",
"0",
"<",
"precision",
"&&",
"precision",
"<=",
"19",
"&&",
"scale",
"==",
"0",
"{",
"typ",
"=",
"\"",
"\"",
"\n",
"if",
"nullable",
"{",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"else",
"{",
"nilVal",
"=",
"`\"\"`",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"typ",
"=",
"\"",
"\"",
"\n\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"typ",
"=",
"\"",
"\"",
"\n",
"nilVal",
"=",
"\"",
"\"",
"\n\n",
"default",
":",
"// bail",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"dt",
")",
"\n",
"os",
".",
"Exit",
"(",
"1",
")",
"\n",
"}",
"\n\n",
"// special case for bool",
"if",
"typ",
"==",
"\"",
"\"",
"&&",
"precision",
"==",
"1",
"{",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"if",
"nullable",
"{",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"precision",
",",
"nilVal",
",",
"typ",
"\n",
"}"
] |
// OrParseType parse a oracle type into a Go type based on the column
// definition.
|
[
"OrParseType",
"parse",
"a",
"oracle",
"type",
"into",
"a",
"Go",
"type",
"based",
"on",
"the",
"column",
"definition",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/oracle.go#L75-L166
|
22,834
|
xo/xo
|
models/indexcolumn.xo.go
|
PgIndexColumns
|
func PgIndexColumns(db XODB, schema string, index string) ([]*IndexColumn, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`(row_number() over()), ` + // ::integer AS seq_no
`a.attnum, ` + // ::integer AS cid
`a.attname ` + // ::varchar AS column_name
`FROM pg_index i ` +
`JOIN ONLY pg_class c ON c.oid = i.indrelid ` +
`JOIN ONLY pg_namespace n ON n.oid = c.relnamespace ` +
`JOIN ONLY pg_class ic ON ic.oid = i.indexrelid ` +
`LEFT JOIN pg_attribute a ON i.indrelid = a.attrelid AND a.attnum = ANY(i.indkey) AND a.attisdropped = false ` +
`WHERE i.indkey <> '0' AND n.nspname = $1 AND ic.relname = $2`
// run query
XOLog(sqlstr, schema, index)
q, err := db.Query(sqlstr, schema, index)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*IndexColumn{}
for q.Next() {
ic := IndexColumn{}
// scan
err = q.Scan(&ic.SeqNo, &ic.Cid, &ic.ColumnName)
if err != nil {
return nil, err
}
res = append(res, &ic)
}
return res, nil
}
|
go
|
func PgIndexColumns(db XODB, schema string, index string) ([]*IndexColumn, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`(row_number() over()), ` + // ::integer AS seq_no
`a.attnum, ` + // ::integer AS cid
`a.attname ` + // ::varchar AS column_name
`FROM pg_index i ` +
`JOIN ONLY pg_class c ON c.oid = i.indrelid ` +
`JOIN ONLY pg_namespace n ON n.oid = c.relnamespace ` +
`JOIN ONLY pg_class ic ON ic.oid = i.indexrelid ` +
`LEFT JOIN pg_attribute a ON i.indrelid = a.attrelid AND a.attnum = ANY(i.indkey) AND a.attisdropped = false ` +
`WHERE i.indkey <> '0' AND n.nspname = $1 AND ic.relname = $2`
// run query
XOLog(sqlstr, schema, index)
q, err := db.Query(sqlstr, schema, index)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*IndexColumn{}
for q.Next() {
ic := IndexColumn{}
// scan
err = q.Scan(&ic.SeqNo, &ic.Cid, &ic.ColumnName)
if err != nil {
return nil, err
}
res = append(res, &ic)
}
return res, nil
}
|
[
"func",
"PgIndexColumns",
"(",
"db",
"XODB",
",",
"schema",
"string",
",",
"index",
"string",
")",
"(",
"[",
"]",
"*",
"IndexColumn",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`(row_number() over()), `",
"+",
"// ::integer AS seq_no",
"`a.attnum, `",
"+",
"// ::integer AS cid",
"`a.attname `",
"+",
"// ::varchar AS column_name",
"`FROM pg_index i `",
"+",
"`JOIN ONLY pg_class c ON c.oid = i.indrelid `",
"+",
"`JOIN ONLY pg_namespace n ON n.oid = c.relnamespace `",
"+",
"`JOIN ONLY pg_class ic ON ic.oid = i.indexrelid `",
"+",
"`LEFT JOIN pg_attribute a ON i.indrelid = a.attrelid AND a.attnum = ANY(i.indkey) AND a.attisdropped = false `",
"+",
"`WHERE i.indkey <> '0' AND n.nspname = $1 AND ic.relname = $2`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"schema",
",",
"index",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"schema",
",",
"index",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"IndexColumn",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"ic",
":=",
"IndexColumn",
"{",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"ic",
".",
"SeqNo",
",",
"&",
"ic",
".",
"Cid",
",",
"&",
"ic",
".",
"ColumnName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"ic",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// PgIndexColumns runs a custom query, returning results as IndexColumn.
|
[
"PgIndexColumns",
"runs",
"a",
"custom",
"query",
"returning",
"results",
"as",
"IndexColumn",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/indexcolumn.xo.go#L14-L52
|
22,835
|
xo/xo
|
models/foreignkey.xo.go
|
PgTableForeignKeys
|
func PgTableForeignKeys(db XODB, schema string, table string) ([]*ForeignKey, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`r.conname, ` + // ::varchar AS foreign_key_name
`b.attname, ` + // ::varchar AS column_name
`i.relname, ` + // ::varchar AS ref_index_name
`c.relname, ` + // ::varchar AS ref_table_name
`d.attname, ` + // ::varchar AS ref_column_name
`0, ` + // ::integer AS key_id
`0, ` + // ::integer AS seq_no
`'', ` + // ::varchar AS on_update
`'', ` + // ::varchar AS on_delete
`'' ` + // ::varchar AS match
`FROM pg_constraint r ` +
`JOIN ONLY pg_class a ON a.oid = r.conrelid ` +
`JOIN ONLY pg_attribute b ON b.attisdropped = false AND b.attnum = ANY(r.conkey) AND b.attrelid = r.conrelid ` +
`JOIN ONLY pg_class i on i.oid = r.conindid ` +
`JOIN ONLY pg_class c on c.oid = r.confrelid ` +
`JOIN ONLY pg_attribute d ON d.attisdropped = false AND d.attnum = ANY(r.confkey) AND d.attrelid = r.confrelid ` +
`JOIN ONLY pg_namespace n ON n.oid = r.connamespace ` +
`WHERE r.contype = 'f' AND n.nspname = $1 AND a.relname = $2 ` +
`ORDER BY r.conname, b.attname`
// run query
XOLog(sqlstr, schema, table)
q, err := db.Query(sqlstr, schema, table)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*ForeignKey{}
for q.Next() {
fk := ForeignKey{}
// scan
err = q.Scan(&fk.ForeignKeyName, &fk.ColumnName, &fk.RefIndexName, &fk.RefTableName, &fk.RefColumnName, &fk.KeyID, &fk.SeqNo, &fk.OnUpdate, &fk.OnDelete, &fk.Match)
if err != nil {
return nil, err
}
res = append(res, &fk)
}
return res, nil
}
|
go
|
func PgTableForeignKeys(db XODB, schema string, table string) ([]*ForeignKey, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`r.conname, ` + // ::varchar AS foreign_key_name
`b.attname, ` + // ::varchar AS column_name
`i.relname, ` + // ::varchar AS ref_index_name
`c.relname, ` + // ::varchar AS ref_table_name
`d.attname, ` + // ::varchar AS ref_column_name
`0, ` + // ::integer AS key_id
`0, ` + // ::integer AS seq_no
`'', ` + // ::varchar AS on_update
`'', ` + // ::varchar AS on_delete
`'' ` + // ::varchar AS match
`FROM pg_constraint r ` +
`JOIN ONLY pg_class a ON a.oid = r.conrelid ` +
`JOIN ONLY pg_attribute b ON b.attisdropped = false AND b.attnum = ANY(r.conkey) AND b.attrelid = r.conrelid ` +
`JOIN ONLY pg_class i on i.oid = r.conindid ` +
`JOIN ONLY pg_class c on c.oid = r.confrelid ` +
`JOIN ONLY pg_attribute d ON d.attisdropped = false AND d.attnum = ANY(r.confkey) AND d.attrelid = r.confrelid ` +
`JOIN ONLY pg_namespace n ON n.oid = r.connamespace ` +
`WHERE r.contype = 'f' AND n.nspname = $1 AND a.relname = $2 ` +
`ORDER BY r.conname, b.attname`
// run query
XOLog(sqlstr, schema, table)
q, err := db.Query(sqlstr, schema, table)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*ForeignKey{}
for q.Next() {
fk := ForeignKey{}
// scan
err = q.Scan(&fk.ForeignKeyName, &fk.ColumnName, &fk.RefIndexName, &fk.RefTableName, &fk.RefColumnName, &fk.KeyID, &fk.SeqNo, &fk.OnUpdate, &fk.OnDelete, &fk.Match)
if err != nil {
return nil, err
}
res = append(res, &fk)
}
return res, nil
}
|
[
"func",
"PgTableForeignKeys",
"(",
"db",
"XODB",
",",
"schema",
"string",
",",
"table",
"string",
")",
"(",
"[",
"]",
"*",
"ForeignKey",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`r.conname, `",
"+",
"// ::varchar AS foreign_key_name",
"`b.attname, `",
"+",
"// ::varchar AS column_name",
"`i.relname, `",
"+",
"// ::varchar AS ref_index_name",
"`c.relname, `",
"+",
"// ::varchar AS ref_table_name",
"`d.attname, `",
"+",
"// ::varchar AS ref_column_name",
"`0, `",
"+",
"// ::integer AS key_id",
"`0, `",
"+",
"// ::integer AS seq_no",
"`'', `",
"+",
"// ::varchar AS on_update",
"`'', `",
"+",
"// ::varchar AS on_delete",
"`'' `",
"+",
"// ::varchar AS match",
"`FROM pg_constraint r `",
"+",
"`JOIN ONLY pg_class a ON a.oid = r.conrelid `",
"+",
"`JOIN ONLY pg_attribute b ON b.attisdropped = false AND b.attnum = ANY(r.conkey) AND b.attrelid = r.conrelid `",
"+",
"`JOIN ONLY pg_class i on i.oid = r.conindid `",
"+",
"`JOIN ONLY pg_class c on c.oid = r.confrelid `",
"+",
"`JOIN ONLY pg_attribute d ON d.attisdropped = false AND d.attnum = ANY(r.confkey) AND d.attrelid = r.confrelid `",
"+",
"`JOIN ONLY pg_namespace n ON n.oid = r.connamespace `",
"+",
"`WHERE r.contype = 'f' AND n.nspname = $1 AND a.relname = $2 `",
"+",
"`ORDER BY r.conname, b.attname`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"schema",
",",
"table",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"schema",
",",
"table",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"ForeignKey",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"fk",
":=",
"ForeignKey",
"{",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"fk",
".",
"ForeignKeyName",
",",
"&",
"fk",
".",
"ColumnName",
",",
"&",
"fk",
".",
"RefIndexName",
",",
"&",
"fk",
".",
"RefTableName",
",",
"&",
"fk",
".",
"RefColumnName",
",",
"&",
"fk",
".",
"KeyID",
",",
"&",
"fk",
".",
"SeqNo",
",",
"&",
"fk",
".",
"OnUpdate",
",",
"&",
"fk",
".",
"OnDelete",
",",
"&",
"fk",
".",
"Match",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"fk",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// PgTableForeignKeys runs a custom query, returning results as ForeignKey.
|
[
"PgTableForeignKeys",
"runs",
"a",
"custom",
"query",
"returning",
"results",
"as",
"ForeignKey",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/foreignkey.xo.go#L21-L69
|
22,836
|
xo/xo
|
models/foreignkey.xo.go
|
MsTableForeignKeys
|
func MsTableForeignKeys(db XODB, schema string, table string) ([]*ForeignKey, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`f.name AS foreign_key_name, ` +
`c.name AS column_name, ` +
`o.name AS ref_table_name, ` +
`x.name AS ref_column_name ` +
`FROM sysobjects f ` +
`INNER JOIN sysobjects t ON f.parent_obj = t.id ` +
`INNER JOIN sysreferences r ON f.id = r.constid ` +
`INNER JOIN sysobjects o ON r.rkeyid = o.id ` +
`INNER JOIN syscolumns c ON r.rkeyid = c.id AND r.rkey1 = c.colid ` +
`INNER JOIN syscolumns x ON r.fkeyid = x.id AND r.fkey1 = x.colid ` +
`WHERE f.type = 'F' AND t.type = 'U' AND SCHEMA_NAME(t.uid) = $1 AND t.name = $2`
// run query
XOLog(sqlstr, schema, table)
q, err := db.Query(sqlstr, schema, table)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*ForeignKey{}
for q.Next() {
fk := ForeignKey{}
// scan
err = q.Scan(&fk.ForeignKeyName, &fk.ColumnName, &fk.RefTableName, &fk.RefColumnName)
if err != nil {
return nil, err
}
res = append(res, &fk)
}
return res, nil
}
|
go
|
func MsTableForeignKeys(db XODB, schema string, table string) ([]*ForeignKey, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`f.name AS foreign_key_name, ` +
`c.name AS column_name, ` +
`o.name AS ref_table_name, ` +
`x.name AS ref_column_name ` +
`FROM sysobjects f ` +
`INNER JOIN sysobjects t ON f.parent_obj = t.id ` +
`INNER JOIN sysreferences r ON f.id = r.constid ` +
`INNER JOIN sysobjects o ON r.rkeyid = o.id ` +
`INNER JOIN syscolumns c ON r.rkeyid = c.id AND r.rkey1 = c.colid ` +
`INNER JOIN syscolumns x ON r.fkeyid = x.id AND r.fkey1 = x.colid ` +
`WHERE f.type = 'F' AND t.type = 'U' AND SCHEMA_NAME(t.uid) = $1 AND t.name = $2`
// run query
XOLog(sqlstr, schema, table)
q, err := db.Query(sqlstr, schema, table)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*ForeignKey{}
for q.Next() {
fk := ForeignKey{}
// scan
err = q.Scan(&fk.ForeignKeyName, &fk.ColumnName, &fk.RefTableName, &fk.RefColumnName)
if err != nil {
return nil, err
}
res = append(res, &fk)
}
return res, nil
}
|
[
"func",
"MsTableForeignKeys",
"(",
"db",
"XODB",
",",
"schema",
"string",
",",
"table",
"string",
")",
"(",
"[",
"]",
"*",
"ForeignKey",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`f.name AS foreign_key_name, `",
"+",
"`c.name AS column_name, `",
"+",
"`o.name AS ref_table_name, `",
"+",
"`x.name AS ref_column_name `",
"+",
"`FROM sysobjects f `",
"+",
"`INNER JOIN sysobjects t ON f.parent_obj = t.id `",
"+",
"`INNER JOIN sysreferences r ON f.id = r.constid `",
"+",
"`INNER JOIN sysobjects o ON r.rkeyid = o.id `",
"+",
"`INNER JOIN syscolumns c ON r.rkeyid = c.id AND r.rkey1 = c.colid `",
"+",
"`INNER JOIN syscolumns x ON r.fkeyid = x.id AND r.fkey1 = x.colid `",
"+",
"`WHERE f.type = 'F' AND t.type = 'U' AND SCHEMA_NAME(t.uid) = $1 AND t.name = $2`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"schema",
",",
"table",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"schema",
",",
"table",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"ForeignKey",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"fk",
":=",
"ForeignKey",
"{",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"fk",
".",
"ForeignKeyName",
",",
"&",
"fk",
".",
"ColumnName",
",",
"&",
"fk",
".",
"RefTableName",
",",
"&",
"fk",
".",
"RefColumnName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"fk",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// MsTableForeignKeys runs a custom query, returning results as ForeignKey.
|
[
"MsTableForeignKeys",
"runs",
"a",
"custom",
"query",
"returning",
"results",
"as",
"ForeignKey",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/foreignkey.xo.go#L142-L182
|
22,837
|
xo/xo
|
examples/django/sqlite3/authpermission.xo.go
|
Update
|
func (ap *AuthPermission) Update(db XODB) error {
var err error
// if doesn't exist, bail
if !ap._exists {
return errors.New("update failed: does not exist")
}
// if deleted, bail
if ap._deleted {
return errors.New("update failed: marked for deletion")
}
// sql query
const sqlstr = `UPDATE auth_permission SET ` +
`content_type_id = ?, codename = ?, name = ?` +
` WHERE id = ?`
// run query
XOLog(sqlstr, ap.ContentTypeID, ap.Codename, ap.Name, ap.ID)
_, err = db.Exec(sqlstr, ap.ContentTypeID, ap.Codename, ap.Name, ap.ID)
return err
}
|
go
|
func (ap *AuthPermission) Update(db XODB) error {
var err error
// if doesn't exist, bail
if !ap._exists {
return errors.New("update failed: does not exist")
}
// if deleted, bail
if ap._deleted {
return errors.New("update failed: marked for deletion")
}
// sql query
const sqlstr = `UPDATE auth_permission SET ` +
`content_type_id = ?, codename = ?, name = ?` +
` WHERE id = ?`
// run query
XOLog(sqlstr, ap.ContentTypeID, ap.Codename, ap.Name, ap.ID)
_, err = db.Exec(sqlstr, ap.ContentTypeID, ap.Codename, ap.Name, ap.ID)
return err
}
|
[
"func",
"(",
"ap",
"*",
"AuthPermission",
")",
"Update",
"(",
"db",
"XODB",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"// if doesn't exist, bail",
"if",
"!",
"ap",
".",
"_exists",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// if deleted, bail",
"if",
"ap",
".",
"_deleted",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`UPDATE auth_permission SET `",
"+",
"`content_type_id = ?, codename = ?, name = ?`",
"+",
"` WHERE id = ?`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"ap",
".",
"ContentTypeID",
",",
"ap",
".",
"Codename",
",",
"ap",
".",
"Name",
",",
"ap",
".",
"ID",
")",
"\n",
"_",
",",
"err",
"=",
"db",
".",
"Exec",
"(",
"sqlstr",
",",
"ap",
".",
"ContentTypeID",
",",
"ap",
".",
"Codename",
",",
"ap",
".",
"Name",
",",
"ap",
".",
"ID",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Update updates the AuthPermission in the database.
|
[
"Update",
"updates",
"the",
"AuthPermission",
"in",
"the",
"database",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/sqlite3/authpermission.xo.go#L68-L90
|
22,838
|
xo/xo
|
examples/django/sqlite3/authpermission.xo.go
|
Delete
|
func (ap *AuthPermission) Delete(db XODB) error {
var err error
// if doesn't exist, bail
if !ap._exists {
return nil
}
// if deleted, bail
if ap._deleted {
return nil
}
// sql query
const sqlstr = `DELETE FROM auth_permission WHERE id = ?`
// run query
XOLog(sqlstr, ap.ID)
_, err = db.Exec(sqlstr, ap.ID)
if err != nil {
return err
}
// set deleted
ap._deleted = true
return nil
}
|
go
|
func (ap *AuthPermission) Delete(db XODB) error {
var err error
// if doesn't exist, bail
if !ap._exists {
return nil
}
// if deleted, bail
if ap._deleted {
return nil
}
// sql query
const sqlstr = `DELETE FROM auth_permission WHERE id = ?`
// run query
XOLog(sqlstr, ap.ID)
_, err = db.Exec(sqlstr, ap.ID)
if err != nil {
return err
}
// set deleted
ap._deleted = true
return nil
}
|
[
"func",
"(",
"ap",
"*",
"AuthPermission",
")",
"Delete",
"(",
"db",
"XODB",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"// if doesn't exist, bail",
"if",
"!",
"ap",
".",
"_exists",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// if deleted, bail",
"if",
"ap",
".",
"_deleted",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`DELETE FROM auth_permission WHERE id = ?`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"ap",
".",
"ID",
")",
"\n",
"_",
",",
"err",
"=",
"db",
".",
"Exec",
"(",
"sqlstr",
",",
"ap",
".",
"ID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// set deleted",
"ap",
".",
"_deleted",
"=",
"true",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Delete deletes the AuthPermission from the database.
|
[
"Delete",
"deletes",
"the",
"AuthPermission",
"from",
"the",
"database",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/sqlite3/authpermission.xo.go#L102-L129
|
22,839
|
xo/xo
|
examples/django/mysql/authgrouppermission.xo.go
|
Save
|
func (agp *AuthGroupPermission) Save(db XODB) error {
if agp.Exists() {
return agp.Update(db)
}
return agp.Insert(db)
}
|
go
|
func (agp *AuthGroupPermission) Save(db XODB) error {
if agp.Exists() {
return agp.Update(db)
}
return agp.Insert(db)
}
|
[
"func",
"(",
"agp",
"*",
"AuthGroupPermission",
")",
"Save",
"(",
"db",
"XODB",
")",
"error",
"{",
"if",
"agp",
".",
"Exists",
"(",
")",
"{",
"return",
"agp",
".",
"Update",
"(",
"db",
")",
"\n",
"}",
"\n\n",
"return",
"agp",
".",
"Insert",
"(",
"db",
")",
"\n",
"}"
] |
// Save saves the AuthGroupPermission to the database.
|
[
"Save",
"saves",
"the",
"AuthGroupPermission",
"to",
"the",
"database",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/mysql/authgrouppermission.xo.go#L92-L98
|
22,840
|
xo/xo
|
examples/django/mysql/authgrouppermission.xo.go
|
AuthGroupPermissionsByPermissionID
|
func AuthGroupPermissionsByPermissionID(db XODB, permissionID int) ([]*AuthGroupPermission, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, group_id, permission_id ` +
`FROM django.auth_group_permissions ` +
`WHERE permission_id = ?`
// run query
XOLog(sqlstr, permissionID)
q, err := db.Query(sqlstr, permissionID)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*AuthGroupPermission{}
for q.Next() {
agp := AuthGroupPermission{
_exists: true,
}
// scan
err = q.Scan(&agp.ID, &agp.GroupID, &agp.PermissionID)
if err != nil {
return nil, err
}
res = append(res, &agp)
}
return res, nil
}
|
go
|
func AuthGroupPermissionsByPermissionID(db XODB, permissionID int) ([]*AuthGroupPermission, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, group_id, permission_id ` +
`FROM django.auth_group_permissions ` +
`WHERE permission_id = ?`
// run query
XOLog(sqlstr, permissionID)
q, err := db.Query(sqlstr, permissionID)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*AuthGroupPermission{}
for q.Next() {
agp := AuthGroupPermission{
_exists: true,
}
// scan
err = q.Scan(&agp.ID, &agp.GroupID, &agp.PermissionID)
if err != nil {
return nil, err
}
res = append(res, &agp)
}
return res, nil
}
|
[
"func",
"AuthGroupPermissionsByPermissionID",
"(",
"db",
"XODB",
",",
"permissionID",
"int",
")",
"(",
"[",
"]",
"*",
"AuthGroupPermission",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`id, group_id, permission_id `",
"+",
"`FROM django.auth_group_permissions `",
"+",
"`WHERE permission_id = ?`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"permissionID",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"permissionID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"AuthGroupPermission",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"agp",
":=",
"AuthGroupPermission",
"{",
"_exists",
":",
"true",
",",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"agp",
".",
"ID",
",",
"&",
"agp",
".",
"GroupID",
",",
"&",
"agp",
".",
"PermissionID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"agp",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// AuthGroupPermissionsByPermissionID retrieves a row from 'django.auth_group_permissions' as a AuthGroupPermission.
//
// Generated from index 'auth_group_permissi_permission_id_84c5c92e_fk_auth_permission_id'.
|
[
"AuthGroupPermissionsByPermissionID",
"retrieves",
"a",
"row",
"from",
"django",
".",
"auth_group_permissions",
"as",
"a",
"AuthGroupPermission",
".",
"Generated",
"from",
"index",
"auth_group_permissi_permission_id_84c5c92e_fk_auth_permission_id",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/mysql/authgrouppermission.xo.go#L147-L181
|
22,841
|
xo/xo
|
main.go
|
processArgs
|
func processArgs(args *internal.ArgType) error {
var err error
// get working directory
cwd, err := os.Getwd()
if err != nil {
return err
}
// determine out path
if args.Out == "" {
args.Path = cwd
} else {
// determine what to do with Out
fi, err := os.Stat(args.Out)
if err == nil && fi.IsDir() {
// out is directory
args.Path = args.Out
} else if err == nil && !fi.IsDir() {
// file exists (will truncate later)
args.Path = path.Dir(args.Out)
args.Filename = path.Base(args.Out)
// error if not split was set, but destination is not a directory
if !args.SingleFile {
return errors.New("output path is not directory")
}
} else if _, ok := err.(*os.PathError); ok {
// path error (ie, file doesn't exist yet)
args.Path = path.Dir(args.Out)
args.Filename = path.Base(args.Out)
// error if split was set, but dest doesn't exist
if !args.SingleFile {
return errors.New("output path must be a directory and already exist when not writing to a single file")
}
} else {
return err
}
}
// check user template path
if args.TemplatePath != "" {
fi, err := os.Stat(args.TemplatePath)
if err == nil && !fi.IsDir() {
return errors.New("template path is not directory")
} else if err != nil {
return errors.New("template path must exist")
}
}
// fix path
if args.Path == "." {
args.Path = cwd
}
// determine package name
if args.Package == "" {
args.Package = path.Base(args.Path)
}
// determine filename if not previously set
if args.Filename == "" {
args.Filename = args.Package + args.Suffix
}
// if query mode toggled, but no query, read Stdin.
if args.QueryMode && args.Query == "" {
buf, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
args.Query = string(buf)
}
// query mode parsing
if args.Query != "" {
args.QueryMode = true
}
// check that query type was specified
if args.QueryMode && args.QueryType == "" {
return errors.New("query type must be supplied for query parsing mode")
}
// query trim
if args.QueryMode && args.QueryTrim {
args.Query = strings.TrimSpace(args.Query)
}
// escape all
if args.EscapeAll {
args.EscapeSchemaName = true
args.EscapeTableNames = true
args.EscapeColumnNames = true
}
// if verbose
if args.Verbose {
models.XOLog = func(s string, p ...interface{}) {
fmt.Printf("SQL:\n%s\nPARAMS:\n%v\n\n", s, p)
}
}
return nil
}
|
go
|
func processArgs(args *internal.ArgType) error {
var err error
// get working directory
cwd, err := os.Getwd()
if err != nil {
return err
}
// determine out path
if args.Out == "" {
args.Path = cwd
} else {
// determine what to do with Out
fi, err := os.Stat(args.Out)
if err == nil && fi.IsDir() {
// out is directory
args.Path = args.Out
} else if err == nil && !fi.IsDir() {
// file exists (will truncate later)
args.Path = path.Dir(args.Out)
args.Filename = path.Base(args.Out)
// error if not split was set, but destination is not a directory
if !args.SingleFile {
return errors.New("output path is not directory")
}
} else if _, ok := err.(*os.PathError); ok {
// path error (ie, file doesn't exist yet)
args.Path = path.Dir(args.Out)
args.Filename = path.Base(args.Out)
// error if split was set, but dest doesn't exist
if !args.SingleFile {
return errors.New("output path must be a directory and already exist when not writing to a single file")
}
} else {
return err
}
}
// check user template path
if args.TemplatePath != "" {
fi, err := os.Stat(args.TemplatePath)
if err == nil && !fi.IsDir() {
return errors.New("template path is not directory")
} else if err != nil {
return errors.New("template path must exist")
}
}
// fix path
if args.Path == "." {
args.Path = cwd
}
// determine package name
if args.Package == "" {
args.Package = path.Base(args.Path)
}
// determine filename if not previously set
if args.Filename == "" {
args.Filename = args.Package + args.Suffix
}
// if query mode toggled, but no query, read Stdin.
if args.QueryMode && args.Query == "" {
buf, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
args.Query = string(buf)
}
// query mode parsing
if args.Query != "" {
args.QueryMode = true
}
// check that query type was specified
if args.QueryMode && args.QueryType == "" {
return errors.New("query type must be supplied for query parsing mode")
}
// query trim
if args.QueryMode && args.QueryTrim {
args.Query = strings.TrimSpace(args.Query)
}
// escape all
if args.EscapeAll {
args.EscapeSchemaName = true
args.EscapeTableNames = true
args.EscapeColumnNames = true
}
// if verbose
if args.Verbose {
models.XOLog = func(s string, p ...interface{}) {
fmt.Printf("SQL:\n%s\nPARAMS:\n%v\n\n", s, p)
}
}
return nil
}
|
[
"func",
"processArgs",
"(",
"args",
"*",
"internal",
".",
"ArgType",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"// get working directory",
"cwd",
",",
"err",
":=",
"os",
".",
"Getwd",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// determine out path",
"if",
"args",
".",
"Out",
"==",
"\"",
"\"",
"{",
"args",
".",
"Path",
"=",
"cwd",
"\n",
"}",
"else",
"{",
"// determine what to do with Out",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"args",
".",
"Out",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"fi",
".",
"IsDir",
"(",
")",
"{",
"// out is directory",
"args",
".",
"Path",
"=",
"args",
".",
"Out",
"\n",
"}",
"else",
"if",
"err",
"==",
"nil",
"&&",
"!",
"fi",
".",
"IsDir",
"(",
")",
"{",
"// file exists (will truncate later)",
"args",
".",
"Path",
"=",
"path",
".",
"Dir",
"(",
"args",
".",
"Out",
")",
"\n",
"args",
".",
"Filename",
"=",
"path",
".",
"Base",
"(",
"args",
".",
"Out",
")",
"\n\n",
"// error if not split was set, but destination is not a directory",
"if",
"!",
"args",
".",
"SingleFile",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"os",
".",
"PathError",
")",
";",
"ok",
"{",
"// path error (ie, file doesn't exist yet)",
"args",
".",
"Path",
"=",
"path",
".",
"Dir",
"(",
"args",
".",
"Out",
")",
"\n",
"args",
".",
"Filename",
"=",
"path",
".",
"Base",
"(",
"args",
".",
"Out",
")",
"\n\n",
"// error if split was set, but dest doesn't exist",
"if",
"!",
"args",
".",
"SingleFile",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// check user template path",
"if",
"args",
".",
"TemplatePath",
"!=",
"\"",
"\"",
"{",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"args",
".",
"TemplatePath",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"!",
"fi",
".",
"IsDir",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// fix path",
"if",
"args",
".",
"Path",
"==",
"\"",
"\"",
"{",
"args",
".",
"Path",
"=",
"cwd",
"\n",
"}",
"\n\n",
"// determine package name",
"if",
"args",
".",
"Package",
"==",
"\"",
"\"",
"{",
"args",
".",
"Package",
"=",
"path",
".",
"Base",
"(",
"args",
".",
"Path",
")",
"\n",
"}",
"\n\n",
"// determine filename if not previously set",
"if",
"args",
".",
"Filename",
"==",
"\"",
"\"",
"{",
"args",
".",
"Filename",
"=",
"args",
".",
"Package",
"+",
"args",
".",
"Suffix",
"\n",
"}",
"\n\n",
"// if query mode toggled, but no query, read Stdin.",
"if",
"args",
".",
"QueryMode",
"&&",
"args",
".",
"Query",
"==",
"\"",
"\"",
"{",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"os",
".",
"Stdin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"args",
".",
"Query",
"=",
"string",
"(",
"buf",
")",
"\n",
"}",
"\n\n",
"// query mode parsing",
"if",
"args",
".",
"Query",
"!=",
"\"",
"\"",
"{",
"args",
".",
"QueryMode",
"=",
"true",
"\n",
"}",
"\n\n",
"// check that query type was specified",
"if",
"args",
".",
"QueryMode",
"&&",
"args",
".",
"QueryType",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// query trim",
"if",
"args",
".",
"QueryMode",
"&&",
"args",
".",
"QueryTrim",
"{",
"args",
".",
"Query",
"=",
"strings",
".",
"TrimSpace",
"(",
"args",
".",
"Query",
")",
"\n",
"}",
"\n\n",
"// escape all",
"if",
"args",
".",
"EscapeAll",
"{",
"args",
".",
"EscapeSchemaName",
"=",
"true",
"\n",
"args",
".",
"EscapeTableNames",
"=",
"true",
"\n",
"args",
".",
"EscapeColumnNames",
"=",
"true",
"\n",
"}",
"\n\n",
"// if verbose",
"if",
"args",
".",
"Verbose",
"{",
"models",
".",
"XOLog",
"=",
"func",
"(",
"s",
"string",
",",
"p",
"...",
"interface",
"{",
"}",
")",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\\n",
"\\n",
"\\n",
"\"",
",",
"s",
",",
"p",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// processArgs processs cli args.
|
[
"processArgs",
"processs",
"cli",
"args",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/main.go#L100-L205
|
22,842
|
xo/xo
|
main.go
|
openDB
|
func openDB(args *internal.ArgType) error {
var err error
// parse dsn
u, err := dburl.Parse(args.DSN)
if err != nil {
return err
}
// save driver type
args.LoaderType = u.Driver
// grab loader
var ok bool
args.Loader, ok = internal.SchemaLoaders[u.Driver]
if !ok {
return errors.New("unsupported database type")
}
// open database connection
args.DB, err = sql.Open(u.Driver, u.DSN)
if err != nil {
return err
}
return nil
}
|
go
|
func openDB(args *internal.ArgType) error {
var err error
// parse dsn
u, err := dburl.Parse(args.DSN)
if err != nil {
return err
}
// save driver type
args.LoaderType = u.Driver
// grab loader
var ok bool
args.Loader, ok = internal.SchemaLoaders[u.Driver]
if !ok {
return errors.New("unsupported database type")
}
// open database connection
args.DB, err = sql.Open(u.Driver, u.DSN)
if err != nil {
return err
}
return nil
}
|
[
"func",
"openDB",
"(",
"args",
"*",
"internal",
".",
"ArgType",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"// parse dsn",
"u",
",",
"err",
":=",
"dburl",
".",
"Parse",
"(",
"args",
".",
"DSN",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// save driver type",
"args",
".",
"LoaderType",
"=",
"u",
".",
"Driver",
"\n\n",
"// grab loader",
"var",
"ok",
"bool",
"\n",
"args",
".",
"Loader",
",",
"ok",
"=",
"internal",
".",
"SchemaLoaders",
"[",
"u",
".",
"Driver",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// open database connection",
"args",
".",
"DB",
",",
"err",
"=",
"sql",
".",
"Open",
"(",
"u",
".",
"Driver",
",",
"u",
".",
"DSN",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// openDB attempts to open a database connection.
|
[
"openDB",
"attempts",
"to",
"open",
"a",
"database",
"connection",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/main.go#L208-L234
|
22,843
|
xo/xo
|
main.go
|
getFile
|
func getFile(args *internal.ArgType, t *internal.TBuf) (*os.File, error) {
var f *os.File
var err error
// determine filename
var filename = strings.ToLower(t.Name) + args.Suffix
if args.SingleFile {
filename = args.Filename
}
filename = path.Join(args.Path, filename)
// lookup file
f, ok := files[filename]
if ok {
return f, nil
}
// default open mode
mode := os.O_RDWR | os.O_CREATE | os.O_TRUNC
// stat file to determine if file already exists
fi, err := os.Stat(filename)
if err == nil && fi.IsDir() {
return nil, errors.New("filename cannot be directory")
} else if _, ok = err.(*os.PathError); !ok && args.Append && t.TemplateType != internal.XOTemplate {
// file exists so append if append is set and not XO type
mode = os.O_APPEND | os.O_WRONLY
}
// skip
if t.TemplateType == internal.XOTemplate && fi != nil {
return nil, nil
}
// open file
f, err = os.OpenFile(filename, mode, 0666)
if err != nil {
return nil, err
}
// file didn't originally exist, so add package header
if fi == nil || !args.Append {
// add build tags
if args.Tags != "" {
f.WriteString(`// +build ` + args.Tags + "\n\n")
}
// execute
err = args.TemplateSet().Execute(f, "xo_package.go.tpl", args)
if err != nil {
return nil, err
}
}
// store file
files[filename] = f
return f, nil
}
|
go
|
func getFile(args *internal.ArgType, t *internal.TBuf) (*os.File, error) {
var f *os.File
var err error
// determine filename
var filename = strings.ToLower(t.Name) + args.Suffix
if args.SingleFile {
filename = args.Filename
}
filename = path.Join(args.Path, filename)
// lookup file
f, ok := files[filename]
if ok {
return f, nil
}
// default open mode
mode := os.O_RDWR | os.O_CREATE | os.O_TRUNC
// stat file to determine if file already exists
fi, err := os.Stat(filename)
if err == nil && fi.IsDir() {
return nil, errors.New("filename cannot be directory")
} else if _, ok = err.(*os.PathError); !ok && args.Append && t.TemplateType != internal.XOTemplate {
// file exists so append if append is set and not XO type
mode = os.O_APPEND | os.O_WRONLY
}
// skip
if t.TemplateType == internal.XOTemplate && fi != nil {
return nil, nil
}
// open file
f, err = os.OpenFile(filename, mode, 0666)
if err != nil {
return nil, err
}
// file didn't originally exist, so add package header
if fi == nil || !args.Append {
// add build tags
if args.Tags != "" {
f.WriteString(`// +build ` + args.Tags + "\n\n")
}
// execute
err = args.TemplateSet().Execute(f, "xo_package.go.tpl", args)
if err != nil {
return nil, err
}
}
// store file
files[filename] = f
return f, nil
}
|
[
"func",
"getFile",
"(",
"args",
"*",
"internal",
".",
"ArgType",
",",
"t",
"*",
"internal",
".",
"TBuf",
")",
"(",
"*",
"os",
".",
"File",
",",
"error",
")",
"{",
"var",
"f",
"*",
"os",
".",
"File",
"\n",
"var",
"err",
"error",
"\n\n",
"// determine filename",
"var",
"filename",
"=",
"strings",
".",
"ToLower",
"(",
"t",
".",
"Name",
")",
"+",
"args",
".",
"Suffix",
"\n",
"if",
"args",
".",
"SingleFile",
"{",
"filename",
"=",
"args",
".",
"Filename",
"\n",
"}",
"\n",
"filename",
"=",
"path",
".",
"Join",
"(",
"args",
".",
"Path",
",",
"filename",
")",
"\n\n",
"// lookup file",
"f",
",",
"ok",
":=",
"files",
"[",
"filename",
"]",
"\n",
"if",
"ok",
"{",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n\n",
"// default open mode",
"mode",
":=",
"os",
".",
"O_RDWR",
"|",
"os",
".",
"O_CREATE",
"|",
"os",
".",
"O_TRUNC",
"\n\n",
"// stat file to determine if file already exists",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"filename",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"fi",
".",
"IsDir",
"(",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"_",
",",
"ok",
"=",
"err",
".",
"(",
"*",
"os",
".",
"PathError",
")",
";",
"!",
"ok",
"&&",
"args",
".",
"Append",
"&&",
"t",
".",
"TemplateType",
"!=",
"internal",
".",
"XOTemplate",
"{",
"// file exists so append if append is set and not XO type",
"mode",
"=",
"os",
".",
"O_APPEND",
"|",
"os",
".",
"O_WRONLY",
"\n",
"}",
"\n\n",
"// skip",
"if",
"t",
".",
"TemplateType",
"==",
"internal",
".",
"XOTemplate",
"&&",
"fi",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"// open file",
"f",
",",
"err",
"=",
"os",
".",
"OpenFile",
"(",
"filename",
",",
"mode",
",",
"0666",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// file didn't originally exist, so add package header",
"if",
"fi",
"==",
"nil",
"||",
"!",
"args",
".",
"Append",
"{",
"// add build tags",
"if",
"args",
".",
"Tags",
"!=",
"\"",
"\"",
"{",
"f",
".",
"WriteString",
"(",
"`// +build `",
"+",
"args",
".",
"Tags",
"+",
"\"",
"\\n",
"\\n",
"\"",
")",
"\n",
"}",
"\n\n",
"// execute",
"err",
"=",
"args",
".",
"TemplateSet",
"(",
")",
".",
"Execute",
"(",
"f",
",",
"\"",
"\"",
",",
"args",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// store file",
"files",
"[",
"filename",
"]",
"=",
"f",
"\n\n",
"return",
"f",
",",
"nil",
"\n",
"}"
] |
// getFile builds the filepath from the TBuf information, and retrieves the
// file from files. If the built filename is not already defined, then it calls
// the os.OpenFile with the correct parameters depending on the state of args.
|
[
"getFile",
"builds",
"the",
"filepath",
"from",
"the",
"TBuf",
"information",
"and",
"retrieves",
"the",
"file",
"from",
"files",
".",
"If",
"the",
"built",
"filename",
"is",
"not",
"already",
"defined",
"then",
"it",
"calls",
"the",
"os",
".",
"OpenFile",
"with",
"the",
"correct",
"parameters",
"depending",
"on",
"the",
"state",
"of",
"args",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/main.go#L242-L300
|
22,844
|
xo/xo
|
main.go
|
writeTypes
|
func writeTypes(args *internal.ArgType) error {
var err error
out := internal.TBufSlice(args.Generated)
// sort segments
sort.Sort(out)
// loop, writing in order
for _, t := range out {
var f *os.File
// skip when in append and type is XO
if args.Append && t.TemplateType == internal.XOTemplate {
continue
}
// check if generated template is only whitespace/empty
bufStr := strings.TrimSpace(t.Buf.String())
if len(bufStr) == 0 {
continue
}
// get file and filename
f, err = getFile(args, &t)
if err != nil {
return err
}
// should only be nil when type == xo
if f == nil {
continue
}
// write segment
if !args.Append || (t.TemplateType != internal.TypeTemplate && t.TemplateType != internal.QueryTypeTemplate) {
_, err = t.Buf.WriteTo(f)
if err != nil {
return err
}
}
}
// build goimports parameters, closing files
params := []string{"-w"}
for k, f := range files {
params = append(params, k)
// close
err = f.Close()
if err != nil {
return err
}
}
// process written files with goimports
output, err := exec.Command("goimports", params...).CombinedOutput()
if err != nil {
return errors.New(string(output))
}
return nil
}
|
go
|
func writeTypes(args *internal.ArgType) error {
var err error
out := internal.TBufSlice(args.Generated)
// sort segments
sort.Sort(out)
// loop, writing in order
for _, t := range out {
var f *os.File
// skip when in append and type is XO
if args.Append && t.TemplateType == internal.XOTemplate {
continue
}
// check if generated template is only whitespace/empty
bufStr := strings.TrimSpace(t.Buf.String())
if len(bufStr) == 0 {
continue
}
// get file and filename
f, err = getFile(args, &t)
if err != nil {
return err
}
// should only be nil when type == xo
if f == nil {
continue
}
// write segment
if !args.Append || (t.TemplateType != internal.TypeTemplate && t.TemplateType != internal.QueryTypeTemplate) {
_, err = t.Buf.WriteTo(f)
if err != nil {
return err
}
}
}
// build goimports parameters, closing files
params := []string{"-w"}
for k, f := range files {
params = append(params, k)
// close
err = f.Close()
if err != nil {
return err
}
}
// process written files with goimports
output, err := exec.Command("goimports", params...).CombinedOutput()
if err != nil {
return errors.New(string(output))
}
return nil
}
|
[
"func",
"writeTypes",
"(",
"args",
"*",
"internal",
".",
"ArgType",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"out",
":=",
"internal",
".",
"TBufSlice",
"(",
"args",
".",
"Generated",
")",
"\n\n",
"// sort segments",
"sort",
".",
"Sort",
"(",
"out",
")",
"\n\n",
"// loop, writing in order",
"for",
"_",
",",
"t",
":=",
"range",
"out",
"{",
"var",
"f",
"*",
"os",
".",
"File",
"\n\n",
"// skip when in append and type is XO",
"if",
"args",
".",
"Append",
"&&",
"t",
".",
"TemplateType",
"==",
"internal",
".",
"XOTemplate",
"{",
"continue",
"\n",
"}",
"\n\n",
"// check if generated template is only whitespace/empty",
"bufStr",
":=",
"strings",
".",
"TrimSpace",
"(",
"t",
".",
"Buf",
".",
"String",
"(",
")",
")",
"\n",
"if",
"len",
"(",
"bufStr",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n\n",
"// get file and filename",
"f",
",",
"err",
"=",
"getFile",
"(",
"args",
",",
"&",
"t",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// should only be nil when type == xo",
"if",
"f",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n\n",
"// write segment",
"if",
"!",
"args",
".",
"Append",
"||",
"(",
"t",
".",
"TemplateType",
"!=",
"internal",
".",
"TypeTemplate",
"&&",
"t",
".",
"TemplateType",
"!=",
"internal",
".",
"QueryTypeTemplate",
")",
"{",
"_",
",",
"err",
"=",
"t",
".",
"Buf",
".",
"WriteTo",
"(",
"f",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// build goimports parameters, closing files",
"params",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"\n",
"for",
"k",
",",
"f",
":=",
"range",
"files",
"{",
"params",
"=",
"append",
"(",
"params",
",",
"k",
")",
"\n\n",
"// close",
"err",
"=",
"f",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// process written files with goimports",
"output",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"params",
"...",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"string",
"(",
"output",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// writeTypes writes the generated definitions.
|
[
"writeTypes",
"writes",
"the",
"generated",
"definitions",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/main.go#L303-L365
|
22,845
|
xo/xo
|
models/myautoincrement.xo.go
|
MyAutoIncrements
|
func MyAutoIncrements(db XODB, schema string) ([]*MyAutoIncrement, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`table_name ` +
`FROM information_schema.tables ` +
`WHERE auto_increment IS NOT null AND table_schema = ?`
// run query
XOLog(sqlstr, schema)
q, err := db.Query(sqlstr, schema)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*MyAutoIncrement{}
for q.Next() {
mai := MyAutoIncrement{}
// scan
err = q.Scan(&mai.TableName)
if err != nil {
return nil, err
}
res = append(res, &mai)
}
return res, nil
}
|
go
|
func MyAutoIncrements(db XODB, schema string) ([]*MyAutoIncrement, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`table_name ` +
`FROM information_schema.tables ` +
`WHERE auto_increment IS NOT null AND table_schema = ?`
// run query
XOLog(sqlstr, schema)
q, err := db.Query(sqlstr, schema)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*MyAutoIncrement{}
for q.Next() {
mai := MyAutoIncrement{}
// scan
err = q.Scan(&mai.TableName)
if err != nil {
return nil, err
}
res = append(res, &mai)
}
return res, nil
}
|
[
"func",
"MyAutoIncrements",
"(",
"db",
"XODB",
",",
"schema",
"string",
")",
"(",
"[",
"]",
"*",
"MyAutoIncrement",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`table_name `",
"+",
"`FROM information_schema.tables `",
"+",
"`WHERE auto_increment IS NOT null AND table_schema = ?`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"schema",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"schema",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"MyAutoIncrement",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"mai",
":=",
"MyAutoIncrement",
"{",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"mai",
".",
"TableName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"mai",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// MyAutoIncrements runs a custom query, returning results as MyAutoIncrement.
|
[
"MyAutoIncrements",
"runs",
"a",
"custom",
"query",
"returning",
"results",
"as",
"MyAutoIncrement",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/myautoincrement.xo.go#L12-L44
|
22,846
|
xo/xo
|
models/sqautoincrement.xo.go
|
SqAutoIncrements
|
func SqAutoIncrements(db XODB) ([]*SqAutoIncrement, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`name as table_name, sql ` +
`FROM sqlite_master ` +
`WHERE type='table' ` +
`ORDER BY name`
// run query
XOLog(sqlstr)
q, err := db.Query(sqlstr)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*SqAutoIncrement{}
for q.Next() {
sai := SqAutoIncrement{}
// scan
err = q.Scan(&sai.TableName, &sai.SQL)
if err != nil {
return nil, err
}
res = append(res, &sai)
}
return res, nil
}
|
go
|
func SqAutoIncrements(db XODB) ([]*SqAutoIncrement, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`name as table_name, sql ` +
`FROM sqlite_master ` +
`WHERE type='table' ` +
`ORDER BY name`
// run query
XOLog(sqlstr)
q, err := db.Query(sqlstr)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*SqAutoIncrement{}
for q.Next() {
sai := SqAutoIncrement{}
// scan
err = q.Scan(&sai.TableName, &sai.SQL)
if err != nil {
return nil, err
}
res = append(res, &sai)
}
return res, nil
}
|
[
"func",
"SqAutoIncrements",
"(",
"db",
"XODB",
")",
"(",
"[",
"]",
"*",
"SqAutoIncrement",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`name as table_name, sql `",
"+",
"`FROM sqlite_master `",
"+",
"`WHERE type='table' `",
"+",
"`ORDER BY name`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"SqAutoIncrement",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"sai",
":=",
"SqAutoIncrement",
"{",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"sai",
".",
"TableName",
",",
"&",
"sai",
".",
"SQL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"sai",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// SqAutoIncrements runs a custom query, returning results as SqAutoIncrement.
|
[
"SqAutoIncrements",
"runs",
"a",
"custom",
"query",
"returning",
"results",
"as",
"SqAutoIncrement",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/sqautoincrement.xo.go#L13-L46
|
22,847
|
xo/xo
|
internal/util.go
|
fmtIndexName
|
func fmtIndexName(ixName string, tableName string) string {
// chop off _ix, _idx, _index, _pkey, or _key
m := IndexChopSuffixRE.FindStringIndex(ixName)
if m != nil {
ixName = ixName[:m[0]]
}
// check tableName
if ixName == tableName {
return ""
}
// chop off tablename_
if strings.HasPrefix(ixName, tableName+"_") {
ixName = ixName[len(tableName)+1:]
}
// camel case name
return snaker.SnakeToCamelIdentifier(ixName)
}
|
go
|
func fmtIndexName(ixName string, tableName string) string {
// chop off _ix, _idx, _index, _pkey, or _key
m := IndexChopSuffixRE.FindStringIndex(ixName)
if m != nil {
ixName = ixName[:m[0]]
}
// check tableName
if ixName == tableName {
return ""
}
// chop off tablename_
if strings.HasPrefix(ixName, tableName+"_") {
ixName = ixName[len(tableName)+1:]
}
// camel case name
return snaker.SnakeToCamelIdentifier(ixName)
}
|
[
"func",
"fmtIndexName",
"(",
"ixName",
"string",
",",
"tableName",
"string",
")",
"string",
"{",
"// chop off _ix, _idx, _index, _pkey, or _key",
"m",
":=",
"IndexChopSuffixRE",
".",
"FindStringIndex",
"(",
"ixName",
")",
"\n",
"if",
"m",
"!=",
"nil",
"{",
"ixName",
"=",
"ixName",
"[",
":",
"m",
"[",
"0",
"]",
"]",
"\n",
"}",
"\n\n",
"// check tableName",
"if",
"ixName",
"==",
"tableName",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// chop off tablename_",
"if",
"strings",
".",
"HasPrefix",
"(",
"ixName",
",",
"tableName",
"+",
"\"",
"\"",
")",
"{",
"ixName",
"=",
"ixName",
"[",
"len",
"(",
"tableName",
")",
"+",
"1",
":",
"]",
"\n",
"}",
"\n\n",
"// camel case name",
"return",
"snaker",
".",
"SnakeToCamelIdentifier",
"(",
"ixName",
")",
"\n",
"}"
] |
// fmtIndexName formats the index name.
|
[
"fmtIndexName",
"formats",
"the",
"index",
"name",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/util.go#L137-L156
|
22,848
|
xo/xo
|
internal/util.go
|
BuildIndexFuncName
|
func (a *ArgType) BuildIndexFuncName(ixTpl *Index) {
// build func name
funcName := ixTpl.Type.Name
if !ixTpl.Index.IsUnique {
funcName = inflector.Pluralize(ixTpl.Type.Name)
}
funcName = funcName + "By"
// add param names
paramNames := []string{}
ixName := fmtIndexName(ixTpl.Index.IndexName, ixTpl.Type.Table.TableName)
if a.UseIndexNames && ixName != "" {
paramNames = append(paramNames, ixName)
} else {
for _, f := range ixTpl.Fields {
paramNames = append(paramNames, f.Name)
}
}
// store resulting name back
ixTpl.FuncName = funcName + strings.Join(paramNames, "")
}
|
go
|
func (a *ArgType) BuildIndexFuncName(ixTpl *Index) {
// build func name
funcName := ixTpl.Type.Name
if !ixTpl.Index.IsUnique {
funcName = inflector.Pluralize(ixTpl.Type.Name)
}
funcName = funcName + "By"
// add param names
paramNames := []string{}
ixName := fmtIndexName(ixTpl.Index.IndexName, ixTpl.Type.Table.TableName)
if a.UseIndexNames && ixName != "" {
paramNames = append(paramNames, ixName)
} else {
for _, f := range ixTpl.Fields {
paramNames = append(paramNames, f.Name)
}
}
// store resulting name back
ixTpl.FuncName = funcName + strings.Join(paramNames, "")
}
|
[
"func",
"(",
"a",
"*",
"ArgType",
")",
"BuildIndexFuncName",
"(",
"ixTpl",
"*",
"Index",
")",
"{",
"// build func name",
"funcName",
":=",
"ixTpl",
".",
"Type",
".",
"Name",
"\n",
"if",
"!",
"ixTpl",
".",
"Index",
".",
"IsUnique",
"{",
"funcName",
"=",
"inflector",
".",
"Pluralize",
"(",
"ixTpl",
".",
"Type",
".",
"Name",
")",
"\n",
"}",
"\n",
"funcName",
"=",
"funcName",
"+",
"\"",
"\"",
"\n\n",
"// add param names",
"paramNames",
":=",
"[",
"]",
"string",
"{",
"}",
"\n\n",
"ixName",
":=",
"fmtIndexName",
"(",
"ixTpl",
".",
"Index",
".",
"IndexName",
",",
"ixTpl",
".",
"Type",
".",
"Table",
".",
"TableName",
")",
"\n",
"if",
"a",
".",
"UseIndexNames",
"&&",
"ixName",
"!=",
"\"",
"\"",
"{",
"paramNames",
"=",
"append",
"(",
"paramNames",
",",
"ixName",
")",
"\n",
"}",
"else",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"ixTpl",
".",
"Fields",
"{",
"paramNames",
"=",
"append",
"(",
"paramNames",
",",
"f",
".",
"Name",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// store resulting name back",
"ixTpl",
".",
"FuncName",
"=",
"funcName",
"+",
"strings",
".",
"Join",
"(",
"paramNames",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// BuildIndexFuncName builds the index func name for an index and its supplied
// fields.
|
[
"BuildIndexFuncName",
"builds",
"the",
"index",
"func",
"name",
"for",
"an",
"index",
"and",
"its",
"supplied",
"fields",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/util.go#L160-L182
|
22,849
|
xo/xo
|
internal/util.go
|
reverseIndexRune
|
func reverseIndexRune(s string, r rune) int {
if s == "" {
return -1
}
rs := []rune(s)
for i := len(rs) - 1; i >= 0; i-- {
if rs[i] == r {
return i
}
}
return -1
}
|
go
|
func reverseIndexRune(s string, r rune) int {
if s == "" {
return -1
}
rs := []rune(s)
for i := len(rs) - 1; i >= 0; i-- {
if rs[i] == r {
return i
}
}
return -1
}
|
[
"func",
"reverseIndexRune",
"(",
"s",
"string",
",",
"r",
"rune",
")",
"int",
"{",
"if",
"s",
"==",
"\"",
"\"",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n\n",
"rs",
":=",
"[",
"]",
"rune",
"(",
"s",
")",
"\n",
"for",
"i",
":=",
"len",
"(",
"rs",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"if",
"rs",
"[",
"i",
"]",
"==",
"r",
"{",
"return",
"i",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"-",
"1",
"\n",
"}"
] |
// reverseIndexRune finds the last rune r in s, returning -1 if not present.
|
[
"reverseIndexRune",
"finds",
"the",
"last",
"rune",
"r",
"in",
"s",
"returning",
"-",
"1",
"if",
"not",
"present",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/util.go#L198-L211
|
22,850
|
xo/xo
|
internal/util.go
|
SingularizeIdentifier
|
func SingularizeIdentifier(s string) string {
if i := reverseIndexRune(s, '_'); i != -1 {
s = s[:i] + "_" + inflector.Singularize(s[i+1:])
} else {
s = inflector.Singularize(s)
}
return snaker.SnakeToCamelIdentifier(s)
}
|
go
|
func SingularizeIdentifier(s string) string {
if i := reverseIndexRune(s, '_'); i != -1 {
s = s[:i] + "_" + inflector.Singularize(s[i+1:])
} else {
s = inflector.Singularize(s)
}
return snaker.SnakeToCamelIdentifier(s)
}
|
[
"func",
"SingularizeIdentifier",
"(",
"s",
"string",
")",
"string",
"{",
"if",
"i",
":=",
"reverseIndexRune",
"(",
"s",
",",
"'_'",
")",
";",
"i",
"!=",
"-",
"1",
"{",
"s",
"=",
"s",
"[",
":",
"i",
"]",
"+",
"\"",
"\"",
"+",
"inflector",
".",
"Singularize",
"(",
"s",
"[",
"i",
"+",
"1",
":",
"]",
")",
"\n",
"}",
"else",
"{",
"s",
"=",
"inflector",
".",
"Singularize",
"(",
"s",
")",
"\n",
"}",
"\n\n",
"return",
"snaker",
".",
"SnakeToCamelIdentifier",
"(",
"s",
")",
"\n",
"}"
] |
// SinguralizeIdentifier will singularize a identifier, returning it in
// CamelCase.
|
[
"SinguralizeIdentifier",
"will",
"singularize",
"a",
"identifier",
"returning",
"it",
"in",
"CamelCase",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/util.go#L215-L223
|
22,851
|
xo/xo
|
loaders/sqlite.go
|
SqParseType
|
func SqParseType(args *internal.ArgType, dt string, nullable bool) (int, string, string) {
precision := 0
nilVal := "nil"
unsigned := false
dt = strings.ToLower(dt)
// extract precision
dt, precision, _ = args.ParsePrecision(dt)
if uRE.MatchString(dt) {
unsigned = true
uRE.ReplaceAllString(dt, "")
}
var typ string
switch dt {
case "bool", "boolean":
nilVal = "false"
typ = "bool"
if nullable {
nilVal = "sql.NullBool{}"
typ = "sql.NullBool"
}
case "int", "integer", "tinyint", "smallint", "mediumint", "bigint":
nilVal = "0"
typ = args.Int32Type
if nullable {
nilVal = "sql.NullInt64{}"
typ = "sql.NullInt64"
}
case "numeric", "real", "double", "float", "decimal":
nilVal = "0.0"
typ = "float64"
if nullable {
nilVal = "sql.NullFloat64{}"
typ = "sql.NullFloat64"
}
case "blob":
typ = "[]byte"
case "timestamp", "datetime", "date", "timestamp with time zone", "time with time zone", "time without time zone", "timestamp without time zone":
nilVal = "xoutil.SqTime{}"
typ = "xoutil.SqTime"
default:
// case "varchar", "character", "varying character", "nchar", "native character", "nvarchar", "text", "clob", "datetime", "date", "time":
nilVal = `""`
typ = "string"
if nullable {
nilVal = "sql.NullString{}"
typ = "sql.NullString"
}
}
// if unsigned ...
if internal.IntRE.MatchString(typ) && unsigned {
typ = "u" + typ
}
return precision, nilVal, typ
}
|
go
|
func SqParseType(args *internal.ArgType, dt string, nullable bool) (int, string, string) {
precision := 0
nilVal := "nil"
unsigned := false
dt = strings.ToLower(dt)
// extract precision
dt, precision, _ = args.ParsePrecision(dt)
if uRE.MatchString(dt) {
unsigned = true
uRE.ReplaceAllString(dt, "")
}
var typ string
switch dt {
case "bool", "boolean":
nilVal = "false"
typ = "bool"
if nullable {
nilVal = "sql.NullBool{}"
typ = "sql.NullBool"
}
case "int", "integer", "tinyint", "smallint", "mediumint", "bigint":
nilVal = "0"
typ = args.Int32Type
if nullable {
nilVal = "sql.NullInt64{}"
typ = "sql.NullInt64"
}
case "numeric", "real", "double", "float", "decimal":
nilVal = "0.0"
typ = "float64"
if nullable {
nilVal = "sql.NullFloat64{}"
typ = "sql.NullFloat64"
}
case "blob":
typ = "[]byte"
case "timestamp", "datetime", "date", "timestamp with time zone", "time with time zone", "time without time zone", "timestamp without time zone":
nilVal = "xoutil.SqTime{}"
typ = "xoutil.SqTime"
default:
// case "varchar", "character", "varying character", "nchar", "native character", "nvarchar", "text", "clob", "datetime", "date", "time":
nilVal = `""`
typ = "string"
if nullable {
nilVal = "sql.NullString{}"
typ = "sql.NullString"
}
}
// if unsigned ...
if internal.IntRE.MatchString(typ) && unsigned {
typ = "u" + typ
}
return precision, nilVal, typ
}
|
[
"func",
"SqParseType",
"(",
"args",
"*",
"internal",
".",
"ArgType",
",",
"dt",
"string",
",",
"nullable",
"bool",
")",
"(",
"int",
",",
"string",
",",
"string",
")",
"{",
"precision",
":=",
"0",
"\n",
"nilVal",
":=",
"\"",
"\"",
"\n",
"unsigned",
":=",
"false",
"\n\n",
"dt",
"=",
"strings",
".",
"ToLower",
"(",
"dt",
")",
"\n\n",
"// extract precision",
"dt",
",",
"precision",
",",
"_",
"=",
"args",
".",
"ParsePrecision",
"(",
"dt",
")",
"\n\n",
"if",
"uRE",
".",
"MatchString",
"(",
"dt",
")",
"{",
"unsigned",
"=",
"true",
"\n",
"uRE",
".",
"ReplaceAllString",
"(",
"dt",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"typ",
"string",
"\n",
"switch",
"dt",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"if",
"nullable",
"{",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"args",
".",
"Int32Type",
"\n",
"if",
"nullable",
"{",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"if",
"nullable",
"{",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"case",
"\"",
"\"",
":",
"typ",
"=",
"\"",
"\"",
"\n\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n\n",
"default",
":",
"// case \"varchar\", \"character\", \"varying character\", \"nchar\", \"native character\", \"nvarchar\", \"text\", \"clob\", \"datetime\", \"date\", \"time\":",
"nilVal",
"=",
"`\"\"`",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"if",
"nullable",
"{",
"nilVal",
"=",
"\"",
"\"",
"\n",
"typ",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n\n",
"// if unsigned ...",
"if",
"internal",
".",
"IntRE",
".",
"MatchString",
"(",
"typ",
")",
"&&",
"unsigned",
"{",
"typ",
"=",
"\"",
"\"",
"+",
"typ",
"\n",
"}",
"\n\n",
"return",
"precision",
",",
"nilVal",
",",
"typ",
"\n",
"}"
] |
// SqParseType parse a sqlite type into a Go type based on the column
// definition.
|
[
"SqParseType",
"parse",
"a",
"sqlite",
"type",
"into",
"a",
"Go",
"type",
"based",
"on",
"the",
"column",
"definition",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/sqlite.go#L52-L116
|
22,852
|
xo/xo
|
loaders/sqlite.go
|
SqTables
|
func SqTables(db models.XODB, schema string, relkind string) ([]*models.Table, error) {
var err error
// get the tables
rows, err := models.SqTables(db, relkind)
if err != nil {
return nil, err
}
// get the SQL for the Autoincrement detection
autoIncrements, err := models.SqAutoIncrements(db)
if err != nil {
// Set it to an empty set on error.
autoIncrements = []*models.SqAutoIncrement{}
}
// Add information about manual FK.
var tables []*models.Table
for _, row := range rows {
manualPk := true
// Look for a match in the table name where it contains the autoincrement
// keyword for the given table in the SQL.
for _, autoInc := range autoIncrements {
lSQL := strings.ToLower(autoInc.SQL)
if autoInc.TableName == row.TableName && strings.Contains(lSQL, "autoincrement") {
manualPk = false
} else {
cols, err := SqTableColumns(db, schema, row.TableName)
if err != nil {
return nil, err
}
for _, col := range cols {
if col.IsPrimaryKey == true {
dt := strings.ToUpper(col.DataType)
if dt == "INTEGER" {
manualPk = false
}
break
}
}
}
}
tables = append(tables, &models.Table{
TableName: row.TableName,
Type: row.Type,
ManualPk: manualPk,
})
}
return tables, nil
}
|
go
|
func SqTables(db models.XODB, schema string, relkind string) ([]*models.Table, error) {
var err error
// get the tables
rows, err := models.SqTables(db, relkind)
if err != nil {
return nil, err
}
// get the SQL for the Autoincrement detection
autoIncrements, err := models.SqAutoIncrements(db)
if err != nil {
// Set it to an empty set on error.
autoIncrements = []*models.SqAutoIncrement{}
}
// Add information about manual FK.
var tables []*models.Table
for _, row := range rows {
manualPk := true
// Look for a match in the table name where it contains the autoincrement
// keyword for the given table in the SQL.
for _, autoInc := range autoIncrements {
lSQL := strings.ToLower(autoInc.SQL)
if autoInc.TableName == row.TableName && strings.Contains(lSQL, "autoincrement") {
manualPk = false
} else {
cols, err := SqTableColumns(db, schema, row.TableName)
if err != nil {
return nil, err
}
for _, col := range cols {
if col.IsPrimaryKey == true {
dt := strings.ToUpper(col.DataType)
if dt == "INTEGER" {
manualPk = false
}
break
}
}
}
}
tables = append(tables, &models.Table{
TableName: row.TableName,
Type: row.Type,
ManualPk: manualPk,
})
}
return tables, nil
}
|
[
"func",
"SqTables",
"(",
"db",
"models",
".",
"XODB",
",",
"schema",
"string",
",",
"relkind",
"string",
")",
"(",
"[",
"]",
"*",
"models",
".",
"Table",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// get the tables",
"rows",
",",
"err",
":=",
"models",
".",
"SqTables",
"(",
"db",
",",
"relkind",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// get the SQL for the Autoincrement detection",
"autoIncrements",
",",
"err",
":=",
"models",
".",
"SqAutoIncrements",
"(",
"db",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Set it to an empty set on error.",
"autoIncrements",
"=",
"[",
"]",
"*",
"models",
".",
"SqAutoIncrement",
"{",
"}",
"\n",
"}",
"\n\n",
"// Add information about manual FK.",
"var",
"tables",
"[",
"]",
"*",
"models",
".",
"Table",
"\n",
"for",
"_",
",",
"row",
":=",
"range",
"rows",
"{",
"manualPk",
":=",
"true",
"\n",
"// Look for a match in the table name where it contains the autoincrement",
"// keyword for the given table in the SQL.",
"for",
"_",
",",
"autoInc",
":=",
"range",
"autoIncrements",
"{",
"lSQL",
":=",
"strings",
".",
"ToLower",
"(",
"autoInc",
".",
"SQL",
")",
"\n",
"if",
"autoInc",
".",
"TableName",
"==",
"row",
".",
"TableName",
"&&",
"strings",
".",
"Contains",
"(",
"lSQL",
",",
"\"",
"\"",
")",
"{",
"manualPk",
"=",
"false",
"\n",
"}",
"else",
"{",
"cols",
",",
"err",
":=",
"SqTableColumns",
"(",
"db",
",",
"schema",
",",
"row",
".",
"TableName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"col",
":=",
"range",
"cols",
"{",
"if",
"col",
".",
"IsPrimaryKey",
"==",
"true",
"{",
"dt",
":=",
"strings",
".",
"ToUpper",
"(",
"col",
".",
"DataType",
")",
"\n",
"if",
"dt",
"==",
"\"",
"\"",
"{",
"manualPk",
"=",
"false",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"tables",
"=",
"append",
"(",
"tables",
",",
"&",
"models",
".",
"Table",
"{",
"TableName",
":",
"row",
".",
"TableName",
",",
"Type",
":",
"row",
".",
"Type",
",",
"ManualPk",
":",
"manualPk",
",",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"tables",
",",
"nil",
"\n",
"}"
] |
// SqTables returns the sqlite tables with the manual PK information added.
// ManualPk is true when the table's primary key is not autoincrement.
|
[
"SqTables",
"returns",
"the",
"sqlite",
"tables",
"with",
"the",
"manual",
"PK",
"information",
"added",
".",
"ManualPk",
"is",
"true",
"when",
"the",
"table",
"s",
"primary",
"key",
"is",
"not",
"autoincrement",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/sqlite.go#L120-L170
|
22,853
|
xo/xo
|
loaders/sqlite.go
|
SqTableColumns
|
func SqTableColumns(db models.XODB, schema string, table string) ([]*models.Column, error) {
var err error
// grab
rows, err := models.SqTableColumns(db, table)
if err != nil {
return nil, err
}
// fix columns
var cols []*models.Column
for _, row := range rows {
cols = append(cols, &models.Column{
FieldOrdinal: row.FieldOrdinal,
ColumnName: row.ColumnName,
DataType: row.DataType,
NotNull: row.NotNull,
DefaultValue: row.DefaultValue,
IsPrimaryKey: row.PkColIndex != 0,
})
}
return cols, nil
}
|
go
|
func SqTableColumns(db models.XODB, schema string, table string) ([]*models.Column, error) {
var err error
// grab
rows, err := models.SqTableColumns(db, table)
if err != nil {
return nil, err
}
// fix columns
var cols []*models.Column
for _, row := range rows {
cols = append(cols, &models.Column{
FieldOrdinal: row.FieldOrdinal,
ColumnName: row.ColumnName,
DataType: row.DataType,
NotNull: row.NotNull,
DefaultValue: row.DefaultValue,
IsPrimaryKey: row.PkColIndex != 0,
})
}
return cols, nil
}
|
[
"func",
"SqTableColumns",
"(",
"db",
"models",
".",
"XODB",
",",
"schema",
"string",
",",
"table",
"string",
")",
"(",
"[",
"]",
"*",
"models",
".",
"Column",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// grab",
"rows",
",",
"err",
":=",
"models",
".",
"SqTableColumns",
"(",
"db",
",",
"table",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// fix columns",
"var",
"cols",
"[",
"]",
"*",
"models",
".",
"Column",
"\n",
"for",
"_",
",",
"row",
":=",
"range",
"rows",
"{",
"cols",
"=",
"append",
"(",
"cols",
",",
"&",
"models",
".",
"Column",
"{",
"FieldOrdinal",
":",
"row",
".",
"FieldOrdinal",
",",
"ColumnName",
":",
"row",
".",
"ColumnName",
",",
"DataType",
":",
"row",
".",
"DataType",
",",
"NotNull",
":",
"row",
".",
"NotNull",
",",
"DefaultValue",
":",
"row",
".",
"DefaultValue",
",",
"IsPrimaryKey",
":",
"row",
".",
"PkColIndex",
"!=",
"0",
",",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"cols",
",",
"nil",
"\n",
"}"
] |
// SqTableColumns returns the sqlite table column info.
|
[
"SqTableColumns",
"returns",
"the",
"sqlite",
"table",
"column",
"info",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/sqlite.go#L173-L196
|
22,854
|
xo/xo
|
loaders/sqlite.go
|
SqQueryColumns
|
func SqQueryColumns(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
}
// load column information
return SqTableColumns(args.DB, "", xoid)
}
|
go
|
func SqQueryColumns(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
}
// load column information
return SqTableColumns(args.DB, "", xoid)
}
|
[
"func",
"SqQueryColumns",
"(",
"args",
"*",
"internal",
".",
"ArgType",
",",
"inspect",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"*",
"models",
".",
"Column",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// create temporary view xoid",
"xoid",
":=",
"\"",
"\"",
"+",
"internal",
".",
"GenRandomID",
"(",
")",
"\n",
"viewq",
":=",
"`CREATE TEMPORARY VIEW `",
"+",
"xoid",
"+",
"` AS `",
"+",
"strings",
".",
"Join",
"(",
"inspect",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"models",
".",
"XOLog",
"(",
"viewq",
")",
"\n",
"_",
",",
"err",
"=",
"args",
".",
"DB",
".",
"Exec",
"(",
"viewq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// load column information",
"return",
"SqTableColumns",
"(",
"args",
".",
"DB",
",",
"\"",
"\"",
",",
"xoid",
")",
"\n",
"}"
] |
// SqQueryColumns parses a sqlite query and generates a type for it.
|
[
"SqQueryColumns",
"parses",
"a",
"sqlite",
"query",
"and",
"generates",
"a",
"type",
"for",
"it",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/sqlite.go#L199-L213
|
22,855
|
xo/xo
|
examples/django/postgres/authgrouppermission.xo.go
|
AuthGroupPermissionByID
|
func AuthGroupPermissionByID(db XODB, id int) (*AuthGroupPermission, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, group_id, permission_id ` +
`FROM public.auth_group_permissions ` +
`WHERE id = $1`
// run query
XOLog(sqlstr, id)
agp := AuthGroupPermission{
_exists: true,
}
err = db.QueryRow(sqlstr, id).Scan(&agp.ID, &agp.GroupID, &agp.PermissionID)
if err != nil {
return nil, err
}
return &agp, nil
}
|
go
|
func AuthGroupPermissionByID(db XODB, id int) (*AuthGroupPermission, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, group_id, permission_id ` +
`FROM public.auth_group_permissions ` +
`WHERE id = $1`
// run query
XOLog(sqlstr, id)
agp := AuthGroupPermission{
_exists: true,
}
err = db.QueryRow(sqlstr, id).Scan(&agp.ID, &agp.GroupID, &agp.PermissionID)
if err != nil {
return nil, err
}
return &agp, nil
}
|
[
"func",
"AuthGroupPermissionByID",
"(",
"db",
"XODB",
",",
"id",
"int",
")",
"(",
"*",
"AuthGroupPermission",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`id, group_id, permission_id `",
"+",
"`FROM public.auth_group_permissions `",
"+",
"`WHERE id = $1`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"id",
")",
"\n",
"agp",
":=",
"AuthGroupPermission",
"{",
"_exists",
":",
"true",
",",
"}",
"\n\n",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"sqlstr",
",",
"id",
")",
".",
"Scan",
"(",
"&",
"agp",
".",
"ID",
",",
"&",
"agp",
".",
"GroupID",
",",
"&",
"agp",
".",
"PermissionID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"agp",
",",
"nil",
"\n",
"}"
] |
// AuthGroupPermissionByID retrieves a row from 'public.auth_group_permissions' as a AuthGroupPermission.
//
// Generated from index 'auth_group_permissions_pkey'.
|
[
"AuthGroupPermissionByID",
"retrieves",
"a",
"row",
"from",
"public",
".",
"auth_group_permissions",
"as",
"a",
"AuthGroupPermission",
".",
"Generated",
"from",
"index",
"auth_group_permissions_pkey",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authgrouppermission.xo.go#L281-L302
|
22,856
|
xo/xo
|
examples/django/postgres/djangosession.xo.go
|
Update
|
func (ds *DjangoSession) Update(db XODB) error {
var err error
// if doesn't exist, bail
if !ds._exists {
return errors.New("update failed: does not exist")
}
// if deleted, bail
if ds._deleted {
return errors.New("update failed: marked for deletion")
}
// sql query
const sqlstr = `UPDATE public.django_session SET (` +
`session_data, expire_date` +
`) = ( ` +
`$1, $2` +
`) WHERE session_key = $3`
// run query
XOLog(sqlstr, ds.SessionData, ds.ExpireDate, ds.SessionKey)
_, err = db.Exec(sqlstr, ds.SessionData, ds.ExpireDate, ds.SessionKey)
return err
}
|
go
|
func (ds *DjangoSession) Update(db XODB) error {
var err error
// if doesn't exist, bail
if !ds._exists {
return errors.New("update failed: does not exist")
}
// if deleted, bail
if ds._deleted {
return errors.New("update failed: marked for deletion")
}
// sql query
const sqlstr = `UPDATE public.django_session SET (` +
`session_data, expire_date` +
`) = ( ` +
`$1, $2` +
`) WHERE session_key = $3`
// run query
XOLog(sqlstr, ds.SessionData, ds.ExpireDate, ds.SessionKey)
_, err = db.Exec(sqlstr, ds.SessionData, ds.ExpireDate, ds.SessionKey)
return err
}
|
[
"func",
"(",
"ds",
"*",
"DjangoSession",
")",
"Update",
"(",
"db",
"XODB",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"// if doesn't exist, bail",
"if",
"!",
"ds",
".",
"_exists",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// if deleted, bail",
"if",
"ds",
".",
"_deleted",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`UPDATE public.django_session SET (`",
"+",
"`session_data, expire_date`",
"+",
"`) = ( `",
"+",
"`$1, $2`",
"+",
"`) WHERE session_key = $3`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"ds",
".",
"SessionData",
",",
"ds",
".",
"ExpireDate",
",",
"ds",
".",
"SessionKey",
")",
"\n",
"_",
",",
"err",
"=",
"db",
".",
"Exec",
"(",
"sqlstr",
",",
"ds",
".",
"SessionData",
",",
"ds",
".",
"ExpireDate",
",",
"ds",
".",
"SessionKey",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Update updates the DjangoSession in the database.
|
[
"Update",
"updates",
"the",
"DjangoSession",
"in",
"the",
"database",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/djangosession.xo.go#L61-L85
|
22,857
|
xo/xo
|
examples/django/postgres/djangosession.xo.go
|
DjangoSessionsBySessionKey
|
func DjangoSessionsBySessionKey(db XODB, sessionKey string) ([]*DjangoSession, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`session_key, session_data, expire_date ` +
`FROM public.django_session ` +
`WHERE session_key = $1`
// run query
XOLog(sqlstr, sessionKey)
q, err := db.Query(sqlstr, sessionKey)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*DjangoSession{}
for q.Next() {
ds := DjangoSession{
_exists: true,
}
// scan
err = q.Scan(&ds.SessionKey, &ds.SessionData, &ds.ExpireDate)
if err != nil {
return nil, err
}
res = append(res, &ds)
}
return res, nil
}
|
go
|
func DjangoSessionsBySessionKey(db XODB, sessionKey string) ([]*DjangoSession, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`session_key, session_data, expire_date ` +
`FROM public.django_session ` +
`WHERE session_key = $1`
// run query
XOLog(sqlstr, sessionKey)
q, err := db.Query(sqlstr, sessionKey)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*DjangoSession{}
for q.Next() {
ds := DjangoSession{
_exists: true,
}
// scan
err = q.Scan(&ds.SessionKey, &ds.SessionData, &ds.ExpireDate)
if err != nil {
return nil, err
}
res = append(res, &ds)
}
return res, nil
}
|
[
"func",
"DjangoSessionsBySessionKey",
"(",
"db",
"XODB",
",",
"sessionKey",
"string",
")",
"(",
"[",
"]",
"*",
"DjangoSession",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`session_key, session_data, expire_date `",
"+",
"`FROM public.django_session `",
"+",
"`WHERE session_key = $1`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"sessionKey",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"sessionKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"DjangoSession",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"ds",
":=",
"DjangoSession",
"{",
"_exists",
":",
"true",
",",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"ds",
".",
"SessionKey",
",",
"&",
"ds",
".",
"SessionData",
",",
"&",
"ds",
".",
"ExpireDate",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"ds",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// DjangoSessionsBySessionKey retrieves a row from 'public.django_session' as a DjangoSession.
//
// Generated from index 'django_session_session_key_c0390e0f_like'.
|
[
"DjangoSessionsBySessionKey",
"retrieves",
"a",
"row",
"from",
"public",
".",
"django_session",
"as",
"a",
"DjangoSession",
".",
"Generated",
"from",
"index",
"django_session_session_key_c0390e0f_like",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/djangosession.xo.go#L229-L263
|
22,858
|
xo/xo
|
internal/templates.go
|
TemplateLoader
|
func (a *ArgType) TemplateLoader(name string) ([]byte, error) {
// no template path specified
if a.TemplatePath == "" {
return templates.Asset(name)
}
return ioutil.ReadFile(path.Join(a.TemplatePath, name))
}
|
go
|
func (a *ArgType) TemplateLoader(name string) ([]byte, error) {
// no template path specified
if a.TemplatePath == "" {
return templates.Asset(name)
}
return ioutil.ReadFile(path.Join(a.TemplatePath, name))
}
|
[
"func",
"(",
"a",
"*",
"ArgType",
")",
"TemplateLoader",
"(",
"name",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// no template path specified",
"if",
"a",
".",
"TemplatePath",
"==",
"\"",
"\"",
"{",
"return",
"templates",
".",
"Asset",
"(",
"name",
")",
"\n",
"}",
"\n\n",
"return",
"ioutil",
".",
"ReadFile",
"(",
"path",
".",
"Join",
"(",
"a",
".",
"TemplatePath",
",",
"name",
")",
")",
"\n",
"}"
] |
// TemplateLoader loads templates from the specified name.
|
[
"TemplateLoader",
"loads",
"templates",
"from",
"the",
"specified",
"name",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/templates.go#L15-L22
|
22,859
|
xo/xo
|
internal/templates.go
|
TemplateSet
|
func (a *ArgType) TemplateSet() *TemplateSet {
if a.templateSet == nil {
a.templateSet = &TemplateSet{
funcs: a.NewTemplateFuncs(),
l: a.TemplateLoader,
tpls: map[string]*template.Template{},
}
}
return a.templateSet
}
|
go
|
func (a *ArgType) TemplateSet() *TemplateSet {
if a.templateSet == nil {
a.templateSet = &TemplateSet{
funcs: a.NewTemplateFuncs(),
l: a.TemplateLoader,
tpls: map[string]*template.Template{},
}
}
return a.templateSet
}
|
[
"func",
"(",
"a",
"*",
"ArgType",
")",
"TemplateSet",
"(",
")",
"*",
"TemplateSet",
"{",
"if",
"a",
".",
"templateSet",
"==",
"nil",
"{",
"a",
".",
"templateSet",
"=",
"&",
"TemplateSet",
"{",
"funcs",
":",
"a",
".",
"NewTemplateFuncs",
"(",
")",
",",
"l",
":",
"a",
".",
"TemplateLoader",
",",
"tpls",
":",
"map",
"[",
"string",
"]",
"*",
"template",
".",
"Template",
"{",
"}",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"a",
".",
"templateSet",
"\n",
"}"
] |
// TemplateSet retrieves the created template set.
|
[
"TemplateSet",
"retrieves",
"the",
"created",
"template",
"set",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/templates.go#L25-L35
|
22,860
|
xo/xo
|
internal/templates.go
|
ExecuteTemplate
|
func (a *ArgType) ExecuteTemplate(tt TemplateType, name string, sub string, obj interface{}) error {
var err error
// setup generated
if a.Generated == nil {
a.Generated = []TBuf{}
}
// create store
v := TBuf{
TemplateType: tt,
Name: name,
Subname: sub,
Buf: new(bytes.Buffer),
}
// build template name
loaderType := ""
if tt != XOTemplate {
if a.LoaderType == "oci8" || a.LoaderType == "ora" {
// force oracle for oci8 since the oracle driver doesn't recognize
// 'oracle' as valid protocol
loaderType = "oracle."
} else {
loaderType = a.LoaderType + "."
}
}
templateName := fmt.Sprintf("%s%s.go.tpl", loaderType, tt)
// execute template
err = a.TemplateSet().Execute(v.Buf, templateName, obj)
if err != nil {
return err
}
a.Generated = append(a.Generated, v)
return nil
}
|
go
|
func (a *ArgType) ExecuteTemplate(tt TemplateType, name string, sub string, obj interface{}) error {
var err error
// setup generated
if a.Generated == nil {
a.Generated = []TBuf{}
}
// create store
v := TBuf{
TemplateType: tt,
Name: name,
Subname: sub,
Buf: new(bytes.Buffer),
}
// build template name
loaderType := ""
if tt != XOTemplate {
if a.LoaderType == "oci8" || a.LoaderType == "ora" {
// force oracle for oci8 since the oracle driver doesn't recognize
// 'oracle' as valid protocol
loaderType = "oracle."
} else {
loaderType = a.LoaderType + "."
}
}
templateName := fmt.Sprintf("%s%s.go.tpl", loaderType, tt)
// execute template
err = a.TemplateSet().Execute(v.Buf, templateName, obj)
if err != nil {
return err
}
a.Generated = append(a.Generated, v)
return nil
}
|
[
"func",
"(",
"a",
"*",
"ArgType",
")",
"ExecuteTemplate",
"(",
"tt",
"TemplateType",
",",
"name",
"string",
",",
"sub",
"string",
",",
"obj",
"interface",
"{",
"}",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"// setup generated",
"if",
"a",
".",
"Generated",
"==",
"nil",
"{",
"a",
".",
"Generated",
"=",
"[",
"]",
"TBuf",
"{",
"}",
"\n",
"}",
"\n\n",
"// create store",
"v",
":=",
"TBuf",
"{",
"TemplateType",
":",
"tt",
",",
"Name",
":",
"name",
",",
"Subname",
":",
"sub",
",",
"Buf",
":",
"new",
"(",
"bytes",
".",
"Buffer",
")",
",",
"}",
"\n\n",
"// build template name",
"loaderType",
":=",
"\"",
"\"",
"\n",
"if",
"tt",
"!=",
"XOTemplate",
"{",
"if",
"a",
".",
"LoaderType",
"==",
"\"",
"\"",
"||",
"a",
".",
"LoaderType",
"==",
"\"",
"\"",
"{",
"// force oracle for oci8 since the oracle driver doesn't recognize",
"// 'oracle' as valid protocol",
"loaderType",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"loaderType",
"=",
"a",
".",
"LoaderType",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n",
"templateName",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"loaderType",
",",
"tt",
")",
"\n\n",
"// execute template",
"err",
"=",
"a",
".",
"TemplateSet",
"(",
")",
".",
"Execute",
"(",
"v",
".",
"Buf",
",",
"templateName",
",",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"a",
".",
"Generated",
"=",
"append",
"(",
"a",
".",
"Generated",
",",
"v",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// ExecuteTemplate loads and parses the supplied template with name and
// executes it with obj as the context.
|
[
"ExecuteTemplate",
"loads",
"and",
"parses",
"the",
"supplied",
"template",
"with",
"name",
"and",
"executes",
"it",
"with",
"obj",
"as",
"the",
"context",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/templates.go#L39-L76
|
22,861
|
xo/xo
|
internal/templates.go
|
Execute
|
func (ts *TemplateSet) Execute(w io.Writer, name string, obj interface{}) error {
tpl, ok := ts.tpls[name]
if !ok {
// attempt to load and parse the template
buf, err := ts.l(name)
if err != nil {
return err
}
// parse template
tpl, err = template.New(name).Funcs(ts.funcs).Parse(string(buf))
if err != nil {
return err
}
}
return tpl.Execute(w, obj)
}
|
go
|
func (ts *TemplateSet) Execute(w io.Writer, name string, obj interface{}) error {
tpl, ok := ts.tpls[name]
if !ok {
// attempt to load and parse the template
buf, err := ts.l(name)
if err != nil {
return err
}
// parse template
tpl, err = template.New(name).Funcs(ts.funcs).Parse(string(buf))
if err != nil {
return err
}
}
return tpl.Execute(w, obj)
}
|
[
"func",
"(",
"ts",
"*",
"TemplateSet",
")",
"Execute",
"(",
"w",
"io",
".",
"Writer",
",",
"name",
"string",
",",
"obj",
"interface",
"{",
"}",
")",
"error",
"{",
"tpl",
",",
"ok",
":=",
"ts",
".",
"tpls",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"// attempt to load and parse the template",
"buf",
",",
"err",
":=",
"ts",
".",
"l",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// parse template",
"tpl",
",",
"err",
"=",
"template",
".",
"New",
"(",
"name",
")",
".",
"Funcs",
"(",
"ts",
".",
"funcs",
")",
".",
"Parse",
"(",
"string",
"(",
"buf",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"tpl",
".",
"Execute",
"(",
"w",
",",
"obj",
")",
"\n",
"}"
] |
// Execute executes a specified template in the template set using the supplied
// obj as its parameters and writing the output to w.
|
[
"Execute",
"executes",
"a",
"specified",
"template",
"in",
"the",
"template",
"set",
"using",
"the",
"supplied",
"obj",
"as",
"its",
"parameters",
"and",
"writing",
"the",
"output",
"to",
"w",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/templates.go#L87-L104
|
22,862
|
xo/xo
|
examples/django/sqlite3/authusergroup.xo.go
|
Save
|
func (aug *AuthUserGroup) Save(db XODB) error {
if aug.Exists() {
return aug.Update(db)
}
return aug.Insert(db)
}
|
go
|
func (aug *AuthUserGroup) Save(db XODB) error {
if aug.Exists() {
return aug.Update(db)
}
return aug.Insert(db)
}
|
[
"func",
"(",
"aug",
"*",
"AuthUserGroup",
")",
"Save",
"(",
"db",
"XODB",
")",
"error",
"{",
"if",
"aug",
".",
"Exists",
"(",
")",
"{",
"return",
"aug",
".",
"Update",
"(",
"db",
")",
"\n",
"}",
"\n\n",
"return",
"aug",
".",
"Insert",
"(",
"db",
")",
"\n",
"}"
] |
// Save saves the AuthUserGroup to the database.
|
[
"Save",
"saves",
"the",
"AuthUserGroup",
"to",
"the",
"database",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/sqlite3/authusergroup.xo.go#L92-L98
|
22,863
|
xo/xo
|
examples/django/sqlite3/authusergroup.xo.go
|
AuthUserGroupByUserIDGroupID
|
func AuthUserGroupByUserIDGroupID(db XODB, userID int, groupID int) (*AuthUserGroup, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, user_id, group_id ` +
`FROM auth_user_groups ` +
`WHERE user_id = ? AND group_id = ?`
// run query
XOLog(sqlstr, userID, groupID)
aug := AuthUserGroup{
_exists: true,
}
err = db.QueryRow(sqlstr, userID, groupID).Scan(&aug.ID, &aug.UserID, &aug.GroupID)
if err != nil {
return nil, err
}
return &aug, nil
}
|
go
|
func AuthUserGroupByUserIDGroupID(db XODB, userID int, groupID int) (*AuthUserGroup, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`id, user_id, group_id ` +
`FROM auth_user_groups ` +
`WHERE user_id = ? AND group_id = ?`
// run query
XOLog(sqlstr, userID, groupID)
aug := AuthUserGroup{
_exists: true,
}
err = db.QueryRow(sqlstr, userID, groupID).Scan(&aug.ID, &aug.UserID, &aug.GroupID)
if err != nil {
return nil, err
}
return &aug, nil
}
|
[
"func",
"AuthUserGroupByUserIDGroupID",
"(",
"db",
"XODB",
",",
"userID",
"int",
",",
"groupID",
"int",
")",
"(",
"*",
"AuthUserGroup",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`id, user_id, group_id `",
"+",
"`FROM auth_user_groups `",
"+",
"`WHERE user_id = ? AND group_id = ?`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"userID",
",",
"groupID",
")",
"\n",
"aug",
":=",
"AuthUserGroup",
"{",
"_exists",
":",
"true",
",",
"}",
"\n\n",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"sqlstr",
",",
"userID",
",",
"groupID",
")",
".",
"Scan",
"(",
"&",
"aug",
".",
"ID",
",",
"&",
"aug",
".",
"UserID",
",",
"&",
"aug",
".",
"GroupID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"aug",
",",
"nil",
"\n",
"}"
] |
// AuthUserGroupByUserIDGroupID retrieves a row from 'auth_user_groups' as a AuthUserGroup.
//
// Generated from index 'auth_user_groups_user_id_94350c0c_uniq'.
|
[
"AuthUserGroupByUserIDGroupID",
"retrieves",
"a",
"row",
"from",
"auth_user_groups",
"as",
"a",
"AuthUserGroup",
".",
"Generated",
"from",
"index",
"auth_user_groups_user_id_94350c0c_uniq",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/sqlite3/authusergroup.xo.go#L251-L272
|
22,864
|
xo/xo
|
examples/django/sqlite3/authgrouppermission.xo.go
|
Update
|
func (agp *AuthGroupPermission) Update(db XODB) error {
var err error
// if doesn't exist, bail
if !agp._exists {
return errors.New("update failed: does not exist")
}
// if deleted, bail
if agp._deleted {
return errors.New("update failed: marked for deletion")
}
// sql query
const sqlstr = `UPDATE auth_group_permissions SET ` +
`group_id = ?, permission_id = ?` +
` WHERE id = ?`
// run query
XOLog(sqlstr, agp.GroupID, agp.PermissionID, agp.ID)
_, err = db.Exec(sqlstr, agp.GroupID, agp.PermissionID, agp.ID)
return err
}
|
go
|
func (agp *AuthGroupPermission) Update(db XODB) error {
var err error
// if doesn't exist, bail
if !agp._exists {
return errors.New("update failed: does not exist")
}
// if deleted, bail
if agp._deleted {
return errors.New("update failed: marked for deletion")
}
// sql query
const sqlstr = `UPDATE auth_group_permissions SET ` +
`group_id = ?, permission_id = ?` +
` WHERE id = ?`
// run query
XOLog(sqlstr, agp.GroupID, agp.PermissionID, agp.ID)
_, err = db.Exec(sqlstr, agp.GroupID, agp.PermissionID, agp.ID)
return err
}
|
[
"func",
"(",
"agp",
"*",
"AuthGroupPermission",
")",
"Update",
"(",
"db",
"XODB",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"// if doesn't exist, bail",
"if",
"!",
"agp",
".",
"_exists",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// if deleted, bail",
"if",
"agp",
".",
"_deleted",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`UPDATE auth_group_permissions SET `",
"+",
"`group_id = ?, permission_id = ?`",
"+",
"` WHERE id = ?`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"agp",
".",
"GroupID",
",",
"agp",
".",
"PermissionID",
",",
"agp",
".",
"ID",
")",
"\n",
"_",
",",
"err",
"=",
"db",
".",
"Exec",
"(",
"sqlstr",
",",
"agp",
".",
"GroupID",
",",
"agp",
".",
"PermissionID",
",",
"agp",
".",
"ID",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Update updates the AuthGroupPermission in the database.
|
[
"Update",
"updates",
"the",
"AuthGroupPermission",
"in",
"the",
"database",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/sqlite3/authgrouppermission.xo.go#L67-L89
|
22,865
|
xo/xo
|
examples/django/sqlite3/authgrouppermission.xo.go
|
Delete
|
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
}
// set deleted
agp._deleted = true
return nil
}
|
go
|
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
}
// set deleted
agp._deleted = true
return nil
}
|
[
"func",
"(",
"agp",
"*",
"AuthGroupPermission",
")",
"Delete",
"(",
"db",
"XODB",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"// if doesn't exist, bail",
"if",
"!",
"agp",
".",
"_exists",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// if deleted, bail",
"if",
"agp",
".",
"_deleted",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`DELETE FROM auth_group_permissions WHERE id = ?`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"agp",
".",
"ID",
")",
"\n",
"_",
",",
"err",
"=",
"db",
".",
"Exec",
"(",
"sqlstr",
",",
"agp",
".",
"ID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// set deleted",
"agp",
".",
"_deleted",
"=",
"true",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Delete deletes the AuthGroupPermission from the database.
|
[
"Delete",
"deletes",
"the",
"AuthGroupPermission",
"from",
"the",
"database",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/sqlite3/authgrouppermission.xo.go#L101-L128
|
22,866
|
xo/xo
|
examples/django/postgres/authuser.xo.go
|
AuthUsersByUsername
|
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 != nil {
return nil, err
}
defer q.Close()
// load results
res := []*AuthUser{}
for q.Next() {
au := AuthUser{
_exists: true,
}
// scan
err = q.Scan(&au.ID, &au.Password, &au.LastLogin, &au.IsSuperuser, &au.Username, &au.FirstName, &au.LastName, &au.Email, &au.IsStaff, &au.IsActive, &au.DateJoined)
if err != nil {
return nil, err
}
res = append(res, &au)
}
return res, nil
}
|
go
|
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 != nil {
return nil, err
}
defer q.Close()
// load results
res := []*AuthUser{}
for q.Next() {
au := AuthUser{
_exists: true,
}
// scan
err = q.Scan(&au.ID, &au.Password, &au.LastLogin, &au.IsSuperuser, &au.Username, &au.FirstName, &au.LastName, &au.Email, &au.IsStaff, &au.IsActive, &au.DateJoined)
if err != nil {
return nil, err
}
res = append(res, &au)
}
return res, nil
}
|
[
"func",
"AuthUsersByUsername",
"(",
"db",
"XODB",
",",
"username",
"string",
")",
"(",
"[",
"]",
"*",
"AuthUser",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// 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`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"username",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"username",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"AuthUser",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"au",
":=",
"AuthUser",
"{",
"_exists",
":",
"true",
",",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"au",
".",
"ID",
",",
"&",
"au",
".",
"Password",
",",
"&",
"au",
".",
"LastLogin",
",",
"&",
"au",
".",
"IsSuperuser",
",",
"&",
"au",
".",
"Username",
",",
"&",
"au",
".",
"FirstName",
",",
"&",
"au",
".",
"LastName",
",",
"&",
"au",
".",
"Email",
",",
"&",
"au",
".",
"IsStaff",
",",
"&",
"au",
".",
"IsActive",
",",
"&",
"au",
".",
"DateJoined",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"au",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// AuthUsersByUsername retrieves a row from 'public.auth_user' as a AuthUser.
//
// Generated from index 'auth_user_username_6821ab7c_like'.
|
[
"AuthUsersByUsername",
"retrieves",
"a",
"row",
"from",
"public",
".",
"auth_user",
"as",
"a",
"AuthUser",
".",
"Generated",
"from",
"index",
"auth_user_username_6821ab7c_like",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authuser.xo.go#L200-L234
|
22,867
|
xo/xo
|
internal/loader.go
|
NthParam
|
func (tl TypeLoader) NthParam(i int) string {
if tl.ParamN != nil {
return tl.ParamN(i)
}
return fmt.Sprintf("$%d", i+1)
}
|
go
|
func (tl TypeLoader) NthParam(i int) string {
if tl.ParamN != nil {
return tl.ParamN(i)
}
return fmt.Sprintf("$%d", i+1)
}
|
[
"func",
"(",
"tl",
"TypeLoader",
")",
"NthParam",
"(",
"i",
"int",
")",
"string",
"{",
"if",
"tl",
".",
"ParamN",
"!=",
"nil",
"{",
"return",
"tl",
".",
"ParamN",
"(",
"i",
")",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
"+",
"1",
")",
"\n",
"}"
] |
// NthParam satisifies Loader's NthParam.
|
[
"NthParam",
"satisifies",
"Loader",
"s",
"NthParam",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L67-L73
|
22,868
|
xo/xo
|
internal/loader.go
|
Escape
|
func (tl TypeLoader) Escape(typ EscType, s string) string {
if e, ok := tl.Esc[typ]; ok && e != nil {
return e(s)
}
return `"` + s + `"`
}
|
go
|
func (tl TypeLoader) Escape(typ EscType, s string) string {
if e, ok := tl.Esc[typ]; ok && e != nil {
return e(s)
}
return `"` + s + `"`
}
|
[
"func",
"(",
"tl",
"TypeLoader",
")",
"Escape",
"(",
"typ",
"EscType",
",",
"s",
"string",
")",
"string",
"{",
"if",
"e",
",",
"ok",
":=",
"tl",
".",
"Esc",
"[",
"typ",
"]",
";",
"ok",
"&&",
"e",
"!=",
"nil",
"{",
"return",
"e",
"(",
"s",
")",
"\n",
"}",
"\n\n",
"return",
"`\"`",
"+",
"s",
"+",
"`\"`",
"\n",
"}"
] |
// Escape escapes the provided identifier based on the EscType.
|
[
"Escape",
"escapes",
"the",
"provided",
"identifier",
"based",
"on",
"the",
"EscType",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L85-L91
|
22,869
|
xo/xo
|
internal/loader.go
|
Relkind
|
func (tl TypeLoader) Relkind(rt RelType) string {
if tl.ProcessRelkind != nil {
return tl.ProcessRelkind(rt)
}
return rt.String()
}
|
go
|
func (tl TypeLoader) Relkind(rt RelType) string {
if tl.ProcessRelkind != nil {
return tl.ProcessRelkind(rt)
}
return rt.String()
}
|
[
"func",
"(",
"tl",
"TypeLoader",
")",
"Relkind",
"(",
"rt",
"RelType",
")",
"string",
"{",
"if",
"tl",
".",
"ProcessRelkind",
"!=",
"nil",
"{",
"return",
"tl",
".",
"ProcessRelkind",
"(",
"rt",
")",
"\n",
"}",
"\n\n",
"return",
"rt",
".",
"String",
"(",
")",
"\n",
"}"
] |
// Relkind satisfies Loader's Relkind.
|
[
"Relkind",
"satisfies",
"Loader",
"s",
"Relkind",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L94-L100
|
22,870
|
xo/xo
|
internal/loader.go
|
SchemaName
|
func (tl TypeLoader) SchemaName(args *ArgType) (string, error) {
if tl.Schema != nil {
return tl.Schema(args)
}
return "", nil
}
|
go
|
func (tl TypeLoader) SchemaName(args *ArgType) (string, error) {
if tl.Schema != nil {
return tl.Schema(args)
}
return "", nil
}
|
[
"func",
"(",
"tl",
"TypeLoader",
")",
"SchemaName",
"(",
"args",
"*",
"ArgType",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"tl",
".",
"Schema",
"!=",
"nil",
"{",
"return",
"tl",
".",
"Schema",
"(",
"args",
")",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}"
] |
// SchemaName returns the active schema name.
|
[
"SchemaName",
"returns",
"the",
"active",
"schema",
"name",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L103-L109
|
22,871
|
xo/xo
|
internal/loader.go
|
LoadSchema
|
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(args, View)
if err != nil {
return err
}
// merge views with the tableMap
for k, v := range viewMap {
tableMap[k] = v
}
// load foreign keys
_, err = tl.LoadForeignKeys(args, tableMap)
if err != nil {
return err
}
// load indexes
_, err = tl.LoadIndexes(args, tableMap)
if err != nil {
return err
}
return nil
}
|
go
|
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(args, View)
if err != nil {
return err
}
// merge views with the tableMap
for k, v := range viewMap {
tableMap[k] = v
}
// load foreign keys
_, err = tl.LoadForeignKeys(args, tableMap)
if err != nil {
return err
}
// load indexes
_, err = tl.LoadIndexes(args, tableMap)
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"tl",
"TypeLoader",
")",
"LoadSchema",
"(",
"args",
"*",
"ArgType",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"// load enums",
"_",
",",
"err",
"=",
"tl",
".",
"LoadEnums",
"(",
"args",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// load procs",
"_",
",",
"err",
"=",
"tl",
".",
"LoadProcs",
"(",
"args",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// load tables",
"tableMap",
",",
"err",
":=",
"tl",
".",
"LoadRelkind",
"(",
"args",
",",
"Table",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// load views",
"viewMap",
",",
"err",
":=",
"tl",
".",
"LoadRelkind",
"(",
"args",
",",
"View",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// merge views with the tableMap",
"for",
"k",
",",
"v",
":=",
"range",
"viewMap",
"{",
"tableMap",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"// load foreign keys",
"_",
",",
"err",
"=",
"tl",
".",
"LoadForeignKeys",
"(",
"args",
",",
"tableMap",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// load indexes",
"_",
",",
"err",
"=",
"tl",
".",
"LoadIndexes",
"(",
"args",
",",
"tableMap",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// LoadSchema loads schema definitions.
|
[
"LoadSchema",
"loads",
"schema",
"definitions",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L247-L292
|
22,872
|
xo/xo
|
internal/loader.go
|
LoadEnums
|
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: SingularizeIdentifier(e.EnumName),
Schema: args.Schema,
Values: []*EnumValue{},
Enum: e,
ReverseConstNames: args.UseReversedEnumConstNames,
}
err = tl.LoadEnumValues(args, enumTpl)
if err != nil {
return nil, err
}
enumMap[enumTpl.Name] = enumTpl
args.KnownTypeMap[enumTpl.Name] = true
}
// generate enum templates
for _, e := range enumMap {
err = args.ExecuteTemplate(EnumTemplate, e.Name, "", e)
if err != nil {
return nil, err
}
}
return enumMap, nil
}
|
go
|
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: SingularizeIdentifier(e.EnumName),
Schema: args.Schema,
Values: []*EnumValue{},
Enum: e,
ReverseConstNames: args.UseReversedEnumConstNames,
}
err = tl.LoadEnumValues(args, enumTpl)
if err != nil {
return nil, err
}
enumMap[enumTpl.Name] = enumTpl
args.KnownTypeMap[enumTpl.Name] = true
}
// generate enum templates
for _, e := range enumMap {
err = args.ExecuteTemplate(EnumTemplate, e.Name, "", e)
if err != nil {
return nil, err
}
}
return enumMap, nil
}
|
[
"func",
"(",
"tl",
"TypeLoader",
")",
"LoadEnums",
"(",
"args",
"*",
"ArgType",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"Enum",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// not supplied, so bail",
"if",
"tl",
".",
"EnumList",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"// load enums",
"enumList",
",",
"err",
":=",
"tl",
".",
"EnumList",
"(",
"args",
".",
"DB",
",",
"args",
".",
"Schema",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// process enums",
"enumMap",
":=",
"map",
"[",
"string",
"]",
"*",
"Enum",
"{",
"}",
"\n",
"for",
"_",
",",
"e",
":=",
"range",
"enumList",
"{",
"enumTpl",
":=",
"&",
"Enum",
"{",
"Name",
":",
"SingularizeIdentifier",
"(",
"e",
".",
"EnumName",
")",
",",
"Schema",
":",
"args",
".",
"Schema",
",",
"Values",
":",
"[",
"]",
"*",
"EnumValue",
"{",
"}",
",",
"Enum",
":",
"e",
",",
"ReverseConstNames",
":",
"args",
".",
"UseReversedEnumConstNames",
",",
"}",
"\n\n",
"err",
"=",
"tl",
".",
"LoadEnumValues",
"(",
"args",
",",
"enumTpl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"enumMap",
"[",
"enumTpl",
".",
"Name",
"]",
"=",
"enumTpl",
"\n",
"args",
".",
"KnownTypeMap",
"[",
"enumTpl",
".",
"Name",
"]",
"=",
"true",
"\n",
"}",
"\n\n",
"// generate enum templates",
"for",
"_",
",",
"e",
":=",
"range",
"enumMap",
"{",
"err",
"=",
"args",
".",
"ExecuteTemplate",
"(",
"EnumTemplate",
",",
"e",
".",
"Name",
",",
"\"",
"\"",
",",
"e",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"enumMap",
",",
"nil",
"\n",
"}"
] |
// LoadEnums loads schema enums.
|
[
"LoadEnums",
"loads",
"schema",
"enums",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L295-L338
|
22,873
|
xo/xo
|
internal/loader.go
|
LoadEnumValues
|
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 strings.HasSuffix(strings.ToLower(name), strings.ToLower(enumTpl.Name)) {
n := name[:len(name)-len(enumTpl.Name)]
if len(n) > 0 {
name = n
}
}
enumTpl.Values = append(enumTpl.Values, &EnumValue{
Name: name,
Val: ev,
})
}
return nil
}
|
go
|
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 strings.HasSuffix(strings.ToLower(name), strings.ToLower(enumTpl.Name)) {
n := name[:len(name)-len(enumTpl.Name)]
if len(n) > 0 {
name = n
}
}
enumTpl.Values = append(enumTpl.Values, &EnumValue{
Name: name,
Val: ev,
})
}
return nil
}
|
[
"func",
"(",
"tl",
"TypeLoader",
")",
"LoadEnumValues",
"(",
"args",
"*",
"ArgType",
",",
"enumTpl",
"*",
"Enum",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"// load enum values",
"enumValues",
",",
"err",
":=",
"tl",
".",
"EnumValueList",
"(",
"args",
".",
"DB",
",",
"args",
".",
"Schema",
",",
"enumTpl",
".",
"Enum",
".",
"EnumName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// process enum values",
"for",
"_",
",",
"ev",
":=",
"range",
"enumValues",
"{",
"// chop off redundant enum name if applicable",
"name",
":=",
"snaker",
".",
"SnakeToCamelIdentifier",
"(",
"ev",
".",
"EnumValue",
")",
"\n",
"if",
"strings",
".",
"HasSuffix",
"(",
"strings",
".",
"ToLower",
"(",
"name",
")",
",",
"strings",
".",
"ToLower",
"(",
"enumTpl",
".",
"Name",
")",
")",
"{",
"n",
":=",
"name",
"[",
":",
"len",
"(",
"name",
")",
"-",
"len",
"(",
"enumTpl",
".",
"Name",
")",
"]",
"\n",
"if",
"len",
"(",
"n",
")",
">",
"0",
"{",
"name",
"=",
"n",
"\n",
"}",
"\n",
"}",
"\n\n",
"enumTpl",
".",
"Values",
"=",
"append",
"(",
"enumTpl",
".",
"Values",
",",
"&",
"EnumValue",
"{",
"Name",
":",
"name",
",",
"Val",
":",
"ev",
",",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// LoadEnumValues loads schema enum values.
|
[
"LoadEnumValues",
"loads",
"schema",
"enum",
"values",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L341-L368
|
22,874
|
xo/xo
|
internal/loader.go
|
LoadProcs
|
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 more underscores
name := p.ProcName
for strings.HasPrefix(name, "_") {
name = name[1:]
}
// create template
procTpl := &Proc{
Name: snaker.SnakeToCamelIdentifier(name),
Schema: args.Schema,
Params: []*Field{},
Return: &Field{},
Proc: p,
}
// parse return type into template
// TODO: fix this so that nullable types can be returned
_, procTpl.Return.NilType, procTpl.Return.Type = tl.ParseType(args, p.ReturnType, false)
// load proc parameters
err = tl.LoadProcParams(args, procTpl)
if err != nil {
return nil, err
}
procMap[p.ProcName] = procTpl
}
// generate proc templates
for _, p := range procMap {
err = args.ExecuteTemplate(ProcTemplate, "sp_"+p.Name, "", p)
if err != nil {
return nil, err
}
}
return procMap, nil
}
|
go
|
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 more underscores
name := p.ProcName
for strings.HasPrefix(name, "_") {
name = name[1:]
}
// create template
procTpl := &Proc{
Name: snaker.SnakeToCamelIdentifier(name),
Schema: args.Schema,
Params: []*Field{},
Return: &Field{},
Proc: p,
}
// parse return type into template
// TODO: fix this so that nullable types can be returned
_, procTpl.Return.NilType, procTpl.Return.Type = tl.ParseType(args, p.ReturnType, false)
// load proc parameters
err = tl.LoadProcParams(args, procTpl)
if err != nil {
return nil, err
}
procMap[p.ProcName] = procTpl
}
// generate proc templates
for _, p := range procMap {
err = args.ExecuteTemplate(ProcTemplate, "sp_"+p.Name, "", p)
if err != nil {
return nil, err
}
}
return procMap, nil
}
|
[
"func",
"(",
"tl",
"TypeLoader",
")",
"LoadProcs",
"(",
"args",
"*",
"ArgType",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"Proc",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// not supplied, so bail",
"if",
"tl",
".",
"ProcList",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"// load procs",
"procList",
",",
"err",
":=",
"tl",
".",
"ProcList",
"(",
"args",
".",
"DB",
",",
"args",
".",
"Schema",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// process procs",
"procMap",
":=",
"map",
"[",
"string",
"]",
"*",
"Proc",
"{",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"procList",
"{",
"// fix the name if it starts with one or more underscores",
"name",
":=",
"p",
".",
"ProcName",
"\n",
"for",
"strings",
".",
"HasPrefix",
"(",
"name",
",",
"\"",
"\"",
")",
"{",
"name",
"=",
"name",
"[",
"1",
":",
"]",
"\n",
"}",
"\n\n",
"// create template",
"procTpl",
":=",
"&",
"Proc",
"{",
"Name",
":",
"snaker",
".",
"SnakeToCamelIdentifier",
"(",
"name",
")",
",",
"Schema",
":",
"args",
".",
"Schema",
",",
"Params",
":",
"[",
"]",
"*",
"Field",
"{",
"}",
",",
"Return",
":",
"&",
"Field",
"{",
"}",
",",
"Proc",
":",
"p",
",",
"}",
"\n\n",
"// parse return type into template",
"// TODO: fix this so that nullable types can be returned",
"_",
",",
"procTpl",
".",
"Return",
".",
"NilType",
",",
"procTpl",
".",
"Return",
".",
"Type",
"=",
"tl",
".",
"ParseType",
"(",
"args",
",",
"p",
".",
"ReturnType",
",",
"false",
")",
"\n\n",
"// load proc parameters",
"err",
"=",
"tl",
".",
"LoadProcParams",
"(",
"args",
",",
"procTpl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"procMap",
"[",
"p",
".",
"ProcName",
"]",
"=",
"procTpl",
"\n",
"}",
"\n\n",
"// generate proc templates",
"for",
"_",
",",
"p",
":=",
"range",
"procMap",
"{",
"err",
"=",
"args",
".",
"ExecuteTemplate",
"(",
"ProcTemplate",
",",
"\"",
"\"",
"+",
"p",
".",
"Name",
",",
"\"",
"\"",
",",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"procMap",
",",
"nil",
"\n",
"}"
] |
// LoadProcs loads schema stored procedures definitions.
|
[
"LoadProcs",
"loads",
"schema",
"stored",
"procedures",
"definitions",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L371-L425
|
22,875
|
xo/xo
|
internal/loader.go
|
LoadProcParams
|
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", i),
}
// TODO: fix this so that nullable types can be used as parameters
_, _, paramTpl.Type = tl.ParseType(args, strings.TrimSpace(p.ParamType), false)
// add to proc params
if procTpl.ProcParams != "" {
procTpl.ProcParams = procTpl.ProcParams + ", "
}
procTpl.ProcParams = procTpl.ProcParams + p.ParamType
procTpl.Params = append(procTpl.Params, paramTpl)
}
return nil
}
|
go
|
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", i),
}
// TODO: fix this so that nullable types can be used as parameters
_, _, paramTpl.Type = tl.ParseType(args, strings.TrimSpace(p.ParamType), false)
// add to proc params
if procTpl.ProcParams != "" {
procTpl.ProcParams = procTpl.ProcParams + ", "
}
procTpl.ProcParams = procTpl.ProcParams + p.ParamType
procTpl.Params = append(procTpl.Params, paramTpl)
}
return nil
}
|
[
"func",
"(",
"tl",
"TypeLoader",
")",
"LoadProcParams",
"(",
"args",
"*",
"ArgType",
",",
"procTpl",
"*",
"Proc",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"// load proc params",
"paramList",
",",
"err",
":=",
"tl",
".",
"ProcParamList",
"(",
"args",
".",
"DB",
",",
"args",
".",
"Schema",
",",
"procTpl",
".",
"Proc",
".",
"ProcName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// process params",
"for",
"i",
",",
"p",
":=",
"range",
"paramList",
"{",
"// TODO: some databases support named parameters in procs (MySQL)",
"paramTpl",
":=",
"&",
"Field",
"{",
"Name",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
")",
",",
"}",
"\n\n",
"// TODO: fix this so that nullable types can be used as parameters",
"_",
",",
"_",
",",
"paramTpl",
".",
"Type",
"=",
"tl",
".",
"ParseType",
"(",
"args",
",",
"strings",
".",
"TrimSpace",
"(",
"p",
".",
"ParamType",
")",
",",
"false",
")",
"\n\n",
"// add to proc params",
"if",
"procTpl",
".",
"ProcParams",
"!=",
"\"",
"\"",
"{",
"procTpl",
".",
"ProcParams",
"=",
"procTpl",
".",
"ProcParams",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"procTpl",
".",
"ProcParams",
"=",
"procTpl",
".",
"ProcParams",
"+",
"p",
".",
"ParamType",
"\n\n",
"procTpl",
".",
"Params",
"=",
"append",
"(",
"procTpl",
".",
"Params",
",",
"paramTpl",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// LoadProcParams loads schema stored procedure parameters.
|
[
"LoadProcParams",
"loads",
"schema",
"stored",
"procedure",
"parameters",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L428-L457
|
22,876
|
xo/xo
|
internal/loader.go
|
LoadForeignKeys
|
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)
}
// generate templates
for _, fk := range fkMap {
err = args.ExecuteTemplate(ForeignKeyTemplate, fk.Type.Name, fk.ForeignKey.ForeignKeyName, fk)
if err != nil {
return nil, err
}
}
return fkMap, nil
}
|
go
|
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)
}
// generate templates
for _, fk := range fkMap {
err = args.ExecuteTemplate(ForeignKeyTemplate, fk.Type.Name, fk.ForeignKey.ForeignKeyName, fk)
if err != nil {
return nil, err
}
}
return fkMap, nil
}
|
[
"func",
"(",
"tl",
"TypeLoader",
")",
"LoadForeignKeys",
"(",
"args",
"*",
"ArgType",
",",
"tableMap",
"map",
"[",
"string",
"]",
"*",
"Type",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"ForeignKey",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"fkMap",
":=",
"map",
"[",
"string",
"]",
"*",
"ForeignKey",
"{",
"}",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"tableMap",
"{",
"// load keys per table",
"err",
"=",
"tl",
".",
"LoadTableForeignKeys",
"(",
"args",
",",
"tableMap",
",",
"t",
",",
"fkMap",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// determine foreign key names",
"for",
"_",
",",
"fk",
":=",
"range",
"fkMap",
"{",
"fk",
".",
"Name",
"=",
"args",
".",
"ForeignKeyName",
"(",
"fkMap",
",",
"fk",
")",
"\n",
"}",
"\n\n",
"// generate templates",
"for",
"_",
",",
"fk",
":=",
"range",
"fkMap",
"{",
"err",
"=",
"args",
".",
"ExecuteTemplate",
"(",
"ForeignKeyTemplate",
",",
"fk",
".",
"Type",
".",
"Name",
",",
"fk",
".",
"ForeignKey",
".",
"ForeignKeyName",
",",
"fk",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"fkMap",
",",
"nil",
"\n",
"}"
] |
// LoadForeignKeys loads foreign keys.
|
[
"LoadForeignKeys",
"loads",
"foreign",
"keys",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L553-L579
|
22,877
|
xo/xo
|
internal/loader.go
|
LoadTableForeignKeys
|
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 := range typeTpl.Fields {
if f.Col.ColumnName == fk.ColumnName {
col = f
break colLoop
}
}
refTplLoop:
// find ref table
for _, t := range tableMap {
if t.Table.TableName == fk.RefTableName {
refTpl = t
break refTplLoop
}
}
refColLoop:
// find ref column
for _, f := range refTpl.Fields {
if f.Col.ColumnName == fk.RefColumnName {
refCol = f
break refColLoop
}
}
// no ref col, but have ref tpl, so use primary key
if refTpl != nil && refCol == nil {
refCol = refTpl.PrimaryKey
}
// check everything was found
if col == nil || refTpl == nil || refCol == nil {
return errors.New("could not find col, refTpl, or refCol")
}
// foreign key name
if fk.ForeignKeyName == "" {
fk.ForeignKeyName = typeTpl.Table.TableName + "_" + col.Col.ColumnName + "_fkey"
}
// create foreign key template
fkMap[fk.ForeignKeyName] = &ForeignKey{
Schema: args.Schema,
Type: typeTpl,
Field: col,
RefType: refTpl,
RefField: refCol,
ForeignKey: fk,
}
}
return nil
}
|
go
|
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 := range typeTpl.Fields {
if f.Col.ColumnName == fk.ColumnName {
col = f
break colLoop
}
}
refTplLoop:
// find ref table
for _, t := range tableMap {
if t.Table.TableName == fk.RefTableName {
refTpl = t
break refTplLoop
}
}
refColLoop:
// find ref column
for _, f := range refTpl.Fields {
if f.Col.ColumnName == fk.RefColumnName {
refCol = f
break refColLoop
}
}
// no ref col, but have ref tpl, so use primary key
if refTpl != nil && refCol == nil {
refCol = refTpl.PrimaryKey
}
// check everything was found
if col == nil || refTpl == nil || refCol == nil {
return errors.New("could not find col, refTpl, or refCol")
}
// foreign key name
if fk.ForeignKeyName == "" {
fk.ForeignKeyName = typeTpl.Table.TableName + "_" + col.Col.ColumnName + "_fkey"
}
// create foreign key template
fkMap[fk.ForeignKeyName] = &ForeignKey{
Schema: args.Schema,
Type: typeTpl,
Field: col,
RefType: refTpl,
RefField: refCol,
ForeignKey: fk,
}
}
return nil
}
|
[
"func",
"(",
"tl",
"TypeLoader",
")",
"LoadTableForeignKeys",
"(",
"args",
"*",
"ArgType",
",",
"tableMap",
"map",
"[",
"string",
"]",
"*",
"Type",
",",
"typeTpl",
"*",
"Type",
",",
"fkMap",
"map",
"[",
"string",
"]",
"*",
"ForeignKey",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"// load foreign keys",
"foreignKeyList",
",",
"err",
":=",
"tl",
".",
"ForeignKeyList",
"(",
"args",
".",
"DB",
",",
"args",
".",
"Schema",
",",
"typeTpl",
".",
"Table",
".",
"TableName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// loop over foreign keys for table",
"for",
"_",
",",
"fk",
":=",
"range",
"foreignKeyList",
"{",
"var",
"refTpl",
"*",
"Type",
"\n",
"var",
"col",
",",
"refCol",
"*",
"Field",
"\n\n",
"colLoop",
":",
"// find column",
"for",
"_",
",",
"f",
":=",
"range",
"typeTpl",
".",
"Fields",
"{",
"if",
"f",
".",
"Col",
".",
"ColumnName",
"==",
"fk",
".",
"ColumnName",
"{",
"col",
"=",
"f",
"\n",
"break",
"colLoop",
"\n",
"}",
"\n",
"}",
"\n\n",
"refTplLoop",
":",
"// find ref table",
"for",
"_",
",",
"t",
":=",
"range",
"tableMap",
"{",
"if",
"t",
".",
"Table",
".",
"TableName",
"==",
"fk",
".",
"RefTableName",
"{",
"refTpl",
"=",
"t",
"\n",
"break",
"refTplLoop",
"\n",
"}",
"\n",
"}",
"\n\n",
"refColLoop",
":",
"// find ref column",
"for",
"_",
",",
"f",
":=",
"range",
"refTpl",
".",
"Fields",
"{",
"if",
"f",
".",
"Col",
".",
"ColumnName",
"==",
"fk",
".",
"RefColumnName",
"{",
"refCol",
"=",
"f",
"\n",
"break",
"refColLoop",
"\n",
"}",
"\n",
"}",
"\n\n",
"// no ref col, but have ref tpl, so use primary key",
"if",
"refTpl",
"!=",
"nil",
"&&",
"refCol",
"==",
"nil",
"{",
"refCol",
"=",
"refTpl",
".",
"PrimaryKey",
"\n",
"}",
"\n\n",
"// check everything was found",
"if",
"col",
"==",
"nil",
"||",
"refTpl",
"==",
"nil",
"||",
"refCol",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// foreign key name",
"if",
"fk",
".",
"ForeignKeyName",
"==",
"\"",
"\"",
"{",
"fk",
".",
"ForeignKeyName",
"=",
"typeTpl",
".",
"Table",
".",
"TableName",
"+",
"\"",
"\"",
"+",
"col",
".",
"Col",
".",
"ColumnName",
"+",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// create foreign key template",
"fkMap",
"[",
"fk",
".",
"ForeignKeyName",
"]",
"=",
"&",
"ForeignKey",
"{",
"Schema",
":",
"args",
".",
"Schema",
",",
"Type",
":",
"typeTpl",
",",
"Field",
":",
"col",
",",
"RefType",
":",
"refTpl",
",",
"RefField",
":",
"refCol",
",",
"ForeignKey",
":",
"fk",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// LoadTableForeignKeys loads schema foreign key definitions per table.
|
[
"LoadTableForeignKeys",
"loads",
"schema",
"foreign",
"key",
"definitions",
"per",
"table",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L582-L650
|
22,878
|
xo/xo
|
internal/loader.go
|
LoadIndexes
|
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, ix)
if err != nil {
return nil, err
}
}
return ixMap, nil
}
|
go
|
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, ix)
if err != nil {
return nil, err
}
}
return ixMap, nil
}
|
[
"func",
"(",
"tl",
"TypeLoader",
")",
"LoadIndexes",
"(",
"args",
"*",
"ArgType",
",",
"tableMap",
"map",
"[",
"string",
"]",
"*",
"Type",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"Index",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"ixMap",
":=",
"map",
"[",
"string",
"]",
"*",
"Index",
"{",
"}",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"tableMap",
"{",
"// load table indexes",
"err",
"=",
"tl",
".",
"LoadTableIndexes",
"(",
"args",
",",
"t",
",",
"ixMap",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// generate templates",
"for",
"_",
",",
"ix",
":=",
"range",
"ixMap",
"{",
"err",
"=",
"args",
".",
"ExecuteTemplate",
"(",
"IndexTemplate",
",",
"ix",
".",
"Type",
".",
"Name",
",",
"ix",
".",
"Index",
".",
"IndexName",
",",
"ix",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"ixMap",
",",
"nil",
"\n",
"}"
] |
// LoadIndexes loads schema index definitions.
|
[
"LoadIndexes",
"loads",
"schema",
"index",
"definitions",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L653-L674
|
22,879
|
xo/xo
|
internal/loader.go
|
LoadTableIndexes
|
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.IsPrimary || (ix.Origin == "pk")
// create index template
ixTpl := &Index{
Schema: args.Schema,
Type: typeTpl,
Fields: []*Field{},
Index: ix,
}
// load index columns
err = tl.LoadIndexColumns(args, ixTpl)
if err != nil {
return err
}
// build func name
args.BuildIndexFuncName(ixTpl)
ixMap[typeTpl.Table.TableName+"_"+ix.IndexName] = ixTpl
}
// search for primary key if it was skipped being set in the type
pk := typeTpl.PrimaryKey
if pk == nil {
for _, f := range typeTpl.Fields {
if f.Col.IsPrimaryKey {
pk = f
break
}
}
}
// if no primary key index loaded, but a primary key column was defined in
// the type, then create the definition here. this is needed for sqlite, as
// sqlite doesn't define primary keys in its index list
if args.LoaderType != "ora" && !priIxLoaded && pk != nil {
ixName := typeTpl.Table.TableName + "_" + pk.Col.ColumnName + "_pkey"
ixMap[ixName] = &Index{
FuncName: typeTpl.Name + "By" + pk.Name,
Schema: args.Schema,
Type: typeTpl,
Fields: []*Field{pk},
Index: &models.Index{
IndexName: ixName,
IsUnique: true,
IsPrimary: true,
},
}
}
return nil
}
|
go
|
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.IsPrimary || (ix.Origin == "pk")
// create index template
ixTpl := &Index{
Schema: args.Schema,
Type: typeTpl,
Fields: []*Field{},
Index: ix,
}
// load index columns
err = tl.LoadIndexColumns(args, ixTpl)
if err != nil {
return err
}
// build func name
args.BuildIndexFuncName(ixTpl)
ixMap[typeTpl.Table.TableName+"_"+ix.IndexName] = ixTpl
}
// search for primary key if it was skipped being set in the type
pk := typeTpl.PrimaryKey
if pk == nil {
for _, f := range typeTpl.Fields {
if f.Col.IsPrimaryKey {
pk = f
break
}
}
}
// if no primary key index loaded, but a primary key column was defined in
// the type, then create the definition here. this is needed for sqlite, as
// sqlite doesn't define primary keys in its index list
if args.LoaderType != "ora" && !priIxLoaded && pk != nil {
ixName := typeTpl.Table.TableName + "_" + pk.Col.ColumnName + "_pkey"
ixMap[ixName] = &Index{
FuncName: typeTpl.Name + "By" + pk.Name,
Schema: args.Schema,
Type: typeTpl,
Fields: []*Field{pk},
Index: &models.Index{
IndexName: ixName,
IsUnique: true,
IsPrimary: true,
},
}
}
return nil
}
|
[
"func",
"(",
"tl",
"TypeLoader",
")",
"LoadTableIndexes",
"(",
"args",
"*",
"ArgType",
",",
"typeTpl",
"*",
"Type",
",",
"ixMap",
"map",
"[",
"string",
"]",
"*",
"Index",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"var",
"priIxLoaded",
"bool",
"\n\n",
"// load indexes",
"indexList",
",",
"err",
":=",
"tl",
".",
"IndexList",
"(",
"args",
".",
"DB",
",",
"args",
".",
"Schema",
",",
"typeTpl",
".",
"Table",
".",
"TableName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// process indexes",
"for",
"_",
",",
"ix",
":=",
"range",
"indexList",
"{",
"// save whether or not the primary key index was processed",
"priIxLoaded",
"=",
"priIxLoaded",
"||",
"ix",
".",
"IsPrimary",
"||",
"(",
"ix",
".",
"Origin",
"==",
"\"",
"\"",
")",
"\n\n",
"// create index template",
"ixTpl",
":=",
"&",
"Index",
"{",
"Schema",
":",
"args",
".",
"Schema",
",",
"Type",
":",
"typeTpl",
",",
"Fields",
":",
"[",
"]",
"*",
"Field",
"{",
"}",
",",
"Index",
":",
"ix",
",",
"}",
"\n\n",
"// load index columns",
"err",
"=",
"tl",
".",
"LoadIndexColumns",
"(",
"args",
",",
"ixTpl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// build func name",
"args",
".",
"BuildIndexFuncName",
"(",
"ixTpl",
")",
"\n\n",
"ixMap",
"[",
"typeTpl",
".",
"Table",
".",
"TableName",
"+",
"\"",
"\"",
"+",
"ix",
".",
"IndexName",
"]",
"=",
"ixTpl",
"\n",
"}",
"\n\n",
"// search for primary key if it was skipped being set in the type",
"pk",
":=",
"typeTpl",
".",
"PrimaryKey",
"\n",
"if",
"pk",
"==",
"nil",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"typeTpl",
".",
"Fields",
"{",
"if",
"f",
".",
"Col",
".",
"IsPrimaryKey",
"{",
"pk",
"=",
"f",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// if no primary key index loaded, but a primary key column was defined in",
"// the type, then create the definition here. this is needed for sqlite, as",
"// sqlite doesn't define primary keys in its index list",
"if",
"args",
".",
"LoaderType",
"!=",
"\"",
"\"",
"&&",
"!",
"priIxLoaded",
"&&",
"pk",
"!=",
"nil",
"{",
"ixName",
":=",
"typeTpl",
".",
"Table",
".",
"TableName",
"+",
"\"",
"\"",
"+",
"pk",
".",
"Col",
".",
"ColumnName",
"+",
"\"",
"\"",
"\n",
"ixMap",
"[",
"ixName",
"]",
"=",
"&",
"Index",
"{",
"FuncName",
":",
"typeTpl",
".",
"Name",
"+",
"\"",
"\"",
"+",
"pk",
".",
"Name",
",",
"Schema",
":",
"args",
".",
"Schema",
",",
"Type",
":",
"typeTpl",
",",
"Fields",
":",
"[",
"]",
"*",
"Field",
"{",
"pk",
"}",
",",
"Index",
":",
"&",
"models",
".",
"Index",
"{",
"IndexName",
":",
"ixName",
",",
"IsUnique",
":",
"true",
",",
"IsPrimary",
":",
"true",
",",
"}",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// LoadTableIndexes loads schema index definitions per table.
|
[
"LoadTableIndexes",
"loads",
"schema",
"index",
"definitions",
"per",
"table",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L677-L742
|
22,880
|
xo/xo
|
internal/loader.go
|
LoadIndexColumns
|
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.Type.Fields {
if f.Col.ColumnName == ic.ColumnName {
field = f
break fieldLoop
}
}
if field == nil {
continue
}
ixTpl.Fields = append(ixTpl.Fields, field)
}
return nil
}
|
go
|
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.Type.Fields {
if f.Col.ColumnName == ic.ColumnName {
field = f
break fieldLoop
}
}
if field == nil {
continue
}
ixTpl.Fields = append(ixTpl.Fields, field)
}
return nil
}
|
[
"func",
"(",
"tl",
"TypeLoader",
")",
"LoadIndexColumns",
"(",
"args",
"*",
"ArgType",
",",
"ixTpl",
"*",
"Index",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"// load index columns",
"indexCols",
",",
"err",
":=",
"tl",
".",
"IndexColumnList",
"(",
"args",
".",
"DB",
",",
"args",
".",
"Schema",
",",
"ixTpl",
".",
"Type",
".",
"Table",
".",
"TableName",
",",
"ixTpl",
".",
"Index",
".",
"IndexName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// process index columns",
"for",
"_",
",",
"ic",
":=",
"range",
"indexCols",
"{",
"var",
"field",
"*",
"Field",
"\n\n",
"fieldLoop",
":",
"// find field",
"for",
"_",
",",
"f",
":=",
"range",
"ixTpl",
".",
"Type",
".",
"Fields",
"{",
"if",
"f",
".",
"Col",
".",
"ColumnName",
"==",
"ic",
".",
"ColumnName",
"{",
"field",
"=",
"f",
"\n",
"break",
"fieldLoop",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"field",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n\n",
"ixTpl",
".",
"Fields",
"=",
"append",
"(",
"ixTpl",
".",
"Fields",
",",
"field",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// LoadIndexColumns loads the index column information.
|
[
"LoadIndexColumns",
"loads",
"the",
"index",
"column",
"information",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/loader.go#L745-L775
|
22,881
|
xo/xo
|
examples/django/postgres/authpermission.xo.go
|
AuthPermissionByContentTypeIDCodename
|
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, contentTypeID, codename).Scan(&ap.ID, &ap.Name, &ap.ContentTypeID, &ap.Codename)
if err != nil {
return nil, err
}
return &ap, nil
}
|
go
|
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, contentTypeID, codename).Scan(&ap.ID, &ap.Name, &ap.ContentTypeID, &ap.Codename)
if err != nil {
return nil, err
}
return &ap, nil
}
|
[
"func",
"AuthPermissionByContentTypeIDCodename",
"(",
"db",
"XODB",
",",
"contentTypeID",
"int",
",",
"codename",
"string",
")",
"(",
"*",
"AuthPermission",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`id, name, content_type_id, codename `",
"+",
"`FROM public.auth_permission `",
"+",
"`WHERE content_type_id = $1 AND codename = $2`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"contentTypeID",
",",
"codename",
")",
"\n",
"ap",
":=",
"AuthPermission",
"{",
"_exists",
":",
"true",
",",
"}",
"\n\n",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"sqlstr",
",",
"contentTypeID",
",",
"codename",
")",
".",
"Scan",
"(",
"&",
"ap",
".",
"ID",
",",
"&",
"ap",
".",
"Name",
",",
"&",
"ap",
".",
"ContentTypeID",
",",
"&",
"ap",
".",
"Codename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"ap",
",",
"nil",
"\n",
"}"
] |
// AuthPermissionByContentTypeIDCodename retrieves a row from 'public.auth_permission' as a AuthPermission.
//
// Generated from index 'auth_permission_content_type_id_01ab375a_uniq'.
|
[
"AuthPermissionByContentTypeIDCodename",
"retrieves",
"a",
"row",
"from",
"public",
".",
"auth_permission",
"as",
"a",
"AuthPermission",
".",
"Generated",
"from",
"index",
"auth_permission_content_type_id_01ab375a_uniq",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authpermission.xo.go#L210-L231
|
22,882
|
xo/xo
|
examples/django/postgres/authpermission.xo.go
|
AuthPermissionByID
|
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)
if err != nil {
return nil, err
}
return &ap, nil
}
|
go
|
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)
if err != nil {
return nil, err
}
return &ap, nil
}
|
[
"func",
"AuthPermissionByID",
"(",
"db",
"XODB",
",",
"id",
"int",
")",
"(",
"*",
"AuthPermission",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`id, name, content_type_id, codename `",
"+",
"`FROM public.auth_permission `",
"+",
"`WHERE id = $1`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"id",
")",
"\n",
"ap",
":=",
"AuthPermission",
"{",
"_exists",
":",
"true",
",",
"}",
"\n\n",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"sqlstr",
",",
"id",
")",
".",
"Scan",
"(",
"&",
"ap",
".",
"ID",
",",
"&",
"ap",
".",
"Name",
",",
"&",
"ap",
".",
"ContentTypeID",
",",
"&",
"ap",
".",
"Codename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"ap",
",",
"nil",
"\n",
"}"
] |
// AuthPermissionByID retrieves a row from 'public.auth_permission' as a AuthPermission.
//
// Generated from index 'auth_permission_pkey'.
|
[
"AuthPermissionByID",
"retrieves",
"a",
"row",
"from",
"public",
".",
"auth_permission",
"as",
"a",
"AuthPermission",
".",
"Generated",
"from",
"index",
"auth_permission_pkey",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/postgres/authpermission.xo.go#L236-L257
|
22,883
|
xo/xo
|
models/sequence.xo.go
|
PgSequences
|
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.relkind = 'S'`
// run query
XOLog(sqlstr, schema)
q, err := db.Query(sqlstr, schema)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*Sequence{}
for q.Next() {
s := Sequence{}
// scan
err = q.Scan(&s.TableName)
if err != nil {
return nil, err
}
res = append(res, &s)
}
return res, nil
}
|
go
|
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.relkind = 'S'`
// run query
XOLog(sqlstr, schema)
q, err := db.Query(sqlstr, schema)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*Sequence{}
for q.Next() {
s := Sequence{}
// scan
err = q.Scan(&s.TableName)
if err != nil {
return nil, err
}
res = append(res, &s)
}
return res, nil
}
|
[
"func",
"PgSequences",
"(",
"db",
"XODB",
",",
"schema",
"string",
")",
"(",
"[",
"]",
"*",
"Sequence",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// 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.relkind = 'S'`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"schema",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"schema",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"Sequence",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"s",
":=",
"Sequence",
"{",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"s",
".",
"TableName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"s",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// PgSequences runs a custom query, returning results as Sequence.
|
[
"PgSequences",
"runs",
"a",
"custom",
"query",
"returning",
"results",
"as",
"Sequence",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/sequence.xo.go#L12-L47
|
22,884
|
xo/xo
|
models/sqcolumn.xo.go
|
SqTableColumns
|
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, &sc.ColumnName, &sc.DataType, &sc.NotNull, &sc.DefaultValue, &sc.PkColIndex)
if err != nil {
return nil, err
}
res = append(res, &sc)
}
return res, nil
}
|
go
|
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, &sc.ColumnName, &sc.DataType, &sc.NotNull, &sc.DefaultValue, &sc.PkColIndex)
if err != nil {
return nil, err
}
res = append(res, &sc)
}
return res, nil
}
|
[
"func",
"SqTableColumns",
"(",
"db",
"XODB",
",",
"table",
"string",
")",
"(",
"[",
"]",
"*",
"SqColumn",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"var",
"sqlstr",
"=",
"`PRAGMA table_info(`",
"+",
"table",
"+",
"`)`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"table",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"SqColumn",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"sc",
":=",
"SqColumn",
"{",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"sc",
".",
"FieldOrdinal",
",",
"&",
"sc",
".",
"ColumnName",
",",
"&",
"sc",
".",
"DataType",
",",
"&",
"sc",
".",
"NotNull",
",",
"&",
"sc",
".",
"DefaultValue",
",",
"&",
"sc",
".",
"PkColIndex",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"sc",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// SqTableColumns runs a custom query, returning results as SqColumn.
|
[
"SqTableColumns",
"runs",
"a",
"custom",
"query",
"returning",
"results",
"as",
"SqColumn",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/sqcolumn.xo.go#L21-L50
|
22,885
|
xo/xo
|
examples/django/oracle/authuseruserpermission.xo.go
|
Save
|
func (auup *AuthUserUserPermission) Save(db XODB) error {
if auup.Exists() {
return auup.Update(db)
}
return auup.Insert(db)
}
|
go
|
func (auup *AuthUserUserPermission) Save(db XODB) error {
if auup.Exists() {
return auup.Update(db)
}
return auup.Insert(db)
}
|
[
"func",
"(",
"auup",
"*",
"AuthUserUserPermission",
")",
"Save",
"(",
"db",
"XODB",
")",
"error",
"{",
"if",
"auup",
".",
"Exists",
"(",
")",
"{",
"return",
"auup",
".",
"Update",
"(",
"db",
")",
"\n",
"}",
"\n\n",
"return",
"auup",
".",
"Insert",
"(",
"db",
")",
"\n",
"}"
] |
// Save saves the AuthUserUserPermission to the database.
|
[
"Save",
"saves",
"the",
"AuthUserUserPermission",
"to",
"the",
"database",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authuseruserpermission.xo.go#L90-L96
|
22,886
|
xo/xo
|
examples/django/oracle/authuseruserpermission.xo.go
|
AuthUserUserPermissionByUserIDPermissionID
|
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, userID, permissionID).Scan(&auup.ID, &auup.UserID, &auup.PermissionID)
if err != nil {
return nil, err
}
return &auup, nil
}
|
go
|
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, userID, permissionID).Scan(&auup.ID, &auup.UserID, &auup.PermissionID)
if err != nil {
return nil, err
}
return &auup, nil
}
|
[
"func",
"AuthUserUserPermissionByUserIDPermissionID",
"(",
"db",
"XODB",
",",
"userID",
"float64",
",",
"permissionID",
"float64",
")",
"(",
"*",
"AuthUserUserPermission",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`id, user_id, permission_id `",
"+",
"`FROM django.auth_user_user_permissions `",
"+",
"`WHERE user_id = :1 AND permission_id = :2`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"userID",
",",
"permissionID",
")",
"\n",
"auup",
":=",
"AuthUserUserPermission",
"{",
"_exists",
":",
"true",
",",
"}",
"\n\n",
"err",
"=",
"db",
".",
"QueryRow",
"(",
"sqlstr",
",",
"userID",
",",
"permissionID",
")",
".",
"Scan",
"(",
"&",
"auup",
".",
"ID",
",",
"&",
"auup",
".",
"UserID",
",",
"&",
"auup",
".",
"PermissionID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"auup",
",",
"nil",
"\n",
"}"
] |
// AuthUserUserPermissionByUserIDPermissionID retrieves a row from 'django.auth_user_user_permissions' as a AuthUserUserPermission.
//
// Generated from index 'auth_use_user_id_14a6b632_uniq'.
|
[
"AuthUserUserPermissionByUserIDPermissionID",
"retrieves",
"a",
"row",
"from",
"django",
".",
"auth_user_user_permissions",
"as",
"a",
"AuthUserUserPermission",
".",
"Generated",
"from",
"index",
"auth_use_user_id_14a6b632_uniq",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authuseruserpermission.xo.go#L145-L166
|
22,887
|
xo/xo
|
examples/django/oracle/authuseruserpermission.xo.go
|
AuthUserUserPermissionsByUserID
|
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 := []*AuthUserUserPermission{}
for q.Next() {
auup := AuthUserUserPermission{
_exists: true,
}
// scan
err = q.Scan(&auup.ID, &auup.UserID, &auup.PermissionID)
if err != nil {
return nil, err
}
res = append(res, &auup)
}
return res, nil
}
|
go
|
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 := []*AuthUserUserPermission{}
for q.Next() {
auup := AuthUserUserPermission{
_exists: true,
}
// scan
err = q.Scan(&auup.ID, &auup.UserID, &auup.PermissionID)
if err != nil {
return nil, err
}
res = append(res, &auup)
}
return res, nil
}
|
[
"func",
"AuthUserUserPermissionsByUserID",
"(",
"db",
"XODB",
",",
"userID",
"float64",
")",
"(",
"[",
"]",
"*",
"AuthUserUserPermission",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT `",
"+",
"`id, user_id, permission_id `",
"+",
"`FROM django.auth_user_user_permissions `",
"+",
"`WHERE user_id = :1`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"userID",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"userID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"AuthUserUserPermission",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"auup",
":=",
"AuthUserUserPermission",
"{",
"_exists",
":",
"true",
",",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"auup",
".",
"ID",
",",
"&",
"auup",
".",
"UserID",
",",
"&",
"auup",
".",
"PermissionID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"auup",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// AuthUserUserPermissionsByUserID retrieves a row from 'django.auth_user_user_permissions' as a AuthUserUserPermission.
//
// Generated from index 'auth_user_user_permissions1cca'.
|
[
"AuthUserUserPermissionsByUserID",
"retrieves",
"a",
"row",
"from",
"django",
".",
"auth_user_user_permissions",
"as",
"a",
"AuthUserUserPermission",
".",
"Generated",
"from",
"index",
"auth_user_user_permissions1cca",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/oracle/authuseruserpermission.xo.go#L171-L205
|
22,888
|
xo/xo
|
examples/django/sqlite3/djangomigration.xo.go
|
Save
|
func (dm *DjangoMigration) Save(db XODB) error {
if dm.Exists() {
return dm.Update(db)
}
return dm.Insert(db)
}
|
go
|
func (dm *DjangoMigration) Save(db XODB) error {
if dm.Exists() {
return dm.Update(db)
}
return dm.Insert(db)
}
|
[
"func",
"(",
"dm",
"*",
"DjangoMigration",
")",
"Save",
"(",
"db",
"XODB",
")",
"error",
"{",
"if",
"dm",
".",
"Exists",
"(",
")",
"{",
"return",
"dm",
".",
"Update",
"(",
"db",
")",
"\n",
"}",
"\n\n",
"return",
"dm",
".",
"Insert",
"(",
"db",
")",
"\n",
"}"
] |
// Save saves the DjangoMigration to the database.
|
[
"Save",
"saves",
"the",
"DjangoMigration",
"to",
"the",
"database",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/examples/django/sqlite3/djangomigration.xo.go#L94-L100
|
22,889
|
xo/xo
|
loaders/mysql.go
|
MySchema
|
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
}
|
go
|
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
}
|
[
"func",
"MySchema",
"(",
"args",
"*",
"internal",
".",
"ArgType",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// sql query",
"const",
"sqlstr",
"=",
"`SELECT SCHEMA()`",
"\n\n",
"var",
"schema",
"string",
"\n\n",
"// run query",
"models",
".",
"XOLog",
"(",
"sqlstr",
")",
"\n",
"err",
"=",
"args",
".",
"DB",
".",
"QueryRow",
"(",
"sqlstr",
")",
".",
"Scan",
"(",
"&",
"schema",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"schema",
",",
"nil",
"\n",
"}"
] |
// MySchema retrieves the name of the current schema.
|
[
"MySchema",
"retrieves",
"the",
"name",
"of",
"the",
"current",
"schema",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/mysql.go#L35-L51
|
22,890
|
xo/xo
|
loaders/mysql.go
|
MyEnumValues
|
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{
EnumValue: ev,
ConstValue: i + 1,
})
}
return enumVals, nil
}
|
go
|
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{
EnumValue: ev,
ConstValue: i + 1,
})
}
return enumVals, nil
}
|
[
"func",
"MyEnumValues",
"(",
"db",
"models",
".",
"XODB",
",",
"schema",
"string",
",",
"enum",
"string",
")",
"(",
"[",
"]",
"*",
"models",
".",
"EnumValue",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// load enum vals",
"res",
",",
"err",
":=",
"models",
".",
"MyEnumValues",
"(",
"db",
",",
"schema",
",",
"enum",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// process enum vals",
"enumVals",
":=",
"[",
"]",
"*",
"models",
".",
"EnumValue",
"{",
"}",
"\n",
"for",
"i",
",",
"ev",
":=",
"range",
"strings",
".",
"Split",
"(",
"res",
".",
"EnumValues",
"[",
"1",
":",
"len",
"(",
"res",
".",
"EnumValues",
")",
"-",
"1",
"]",
",",
"\"",
"\"",
")",
"{",
"enumVals",
"=",
"append",
"(",
"enumVals",
",",
"&",
"models",
".",
"EnumValue",
"{",
"EnumValue",
":",
"ev",
",",
"ConstValue",
":",
"i",
"+",
"1",
",",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"enumVals",
",",
"nil",
"\n",
"}"
] |
// MyEnumValues loads the enum values.
|
[
"MyEnumValues",
"loads",
"the",
"enum",
"values",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/mysql.go#L221-L240
|
22,891
|
xo/xo
|
loaders/mysql.go
|
MyTables
|
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 = []*models.MyAutoIncrement{}
}
// Add information about manual FK.
var tables []*models.Table
for _, row := range rows {
manualPk := true
// Look for a match in the table name where it contains the autoincrement
for _, autoInc := range autoIncrements {
if autoInc.TableName == row.TableName {
manualPk = false
}
}
tables = append(tables, &models.Table{
TableName: row.TableName,
Type: row.Type,
ManualPk: manualPk,
})
}
return tables, nil
}
|
go
|
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 = []*models.MyAutoIncrement{}
}
// Add information about manual FK.
var tables []*models.Table
for _, row := range rows {
manualPk := true
// Look for a match in the table name where it contains the autoincrement
for _, autoInc := range autoIncrements {
if autoInc.TableName == row.TableName {
manualPk = false
}
}
tables = append(tables, &models.Table{
TableName: row.TableName,
Type: row.Type,
ManualPk: manualPk,
})
}
return tables, nil
}
|
[
"func",
"MyTables",
"(",
"db",
"models",
".",
"XODB",
",",
"schema",
"string",
",",
"relkind",
"string",
")",
"(",
"[",
"]",
"*",
"models",
".",
"Table",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// get the tables",
"rows",
",",
"err",
":=",
"models",
".",
"MyTables",
"(",
"db",
",",
"schema",
",",
"relkind",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// get the tables that have Autoincrementing included",
"autoIncrements",
",",
"err",
":=",
"models",
".",
"MyAutoIncrements",
"(",
"db",
",",
"schema",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Set it to an empty set on error.",
"autoIncrements",
"=",
"[",
"]",
"*",
"models",
".",
"MyAutoIncrement",
"{",
"}",
"\n",
"}",
"\n\n",
"// Add information about manual FK.",
"var",
"tables",
"[",
"]",
"*",
"models",
".",
"Table",
"\n",
"for",
"_",
",",
"row",
":=",
"range",
"rows",
"{",
"manualPk",
":=",
"true",
"\n",
"// Look for a match in the table name where it contains the autoincrement",
"for",
"_",
",",
"autoInc",
":=",
"range",
"autoIncrements",
"{",
"if",
"autoInc",
".",
"TableName",
"==",
"row",
".",
"TableName",
"{",
"manualPk",
"=",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"tables",
"=",
"append",
"(",
"tables",
",",
"&",
"models",
".",
"Table",
"{",
"TableName",
":",
"row",
".",
"TableName",
",",
"Type",
":",
"row",
".",
"Type",
",",
"ManualPk",
":",
"manualPk",
",",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"tables",
",",
"nil",
"\n",
"}"
] |
// MyTables returns the MySql tables with the manual PK information added.
// ManualPk is true when the table's primary key is not autoincrement.
|
[
"MyTables",
"returns",
"the",
"MySql",
"tables",
"with",
"the",
"manual",
"PK",
"information",
"added",
".",
"ManualPk",
"is",
"true",
"when",
"the",
"table",
"s",
"primary",
"key",
"is",
"not",
"autoincrement",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/mysql.go#L244-L278
|
22,892
|
xo/xo
|
loaders/mysql.go
|
MyQueryColumns
|
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, args.Schema, xoid)
// drop inspect view
dropq := `DROP VIEW ` + xoid
models.XOLog(dropq)
_, _ = args.DB.Exec(dropq)
// load column information
return cols, err
}
|
go
|
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, args.Schema, xoid)
// drop inspect view
dropq := `DROP VIEW ` + xoid
models.XOLog(dropq)
_, _ = args.DB.Exec(dropq)
// load column information
return cols, err
}
|
[
"func",
"MyQueryColumns",
"(",
"args",
"*",
"internal",
".",
"ArgType",
",",
"inspect",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"*",
"models",
".",
"Column",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// create temporary view xoid",
"xoid",
":=",
"\"",
"\"",
"+",
"internal",
".",
"GenRandomID",
"(",
")",
"\n",
"viewq",
":=",
"`CREATE VIEW `",
"+",
"xoid",
"+",
"` AS (`",
"+",
"strings",
".",
"Join",
"(",
"inspect",
",",
"\"",
"\\n",
"\"",
")",
"+",
"`)`",
"\n",
"models",
".",
"XOLog",
"(",
"viewq",
")",
"\n",
"_",
",",
"err",
"=",
"args",
".",
"DB",
".",
"Exec",
"(",
"viewq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// load columns",
"cols",
",",
"err",
":=",
"models",
".",
"MyTableColumns",
"(",
"args",
".",
"DB",
",",
"args",
".",
"Schema",
",",
"xoid",
")",
"\n\n",
"// drop inspect view",
"dropq",
":=",
"`DROP VIEW `",
"+",
"xoid",
"\n",
"models",
".",
"XOLog",
"(",
"dropq",
")",
"\n",
"_",
",",
"_",
"=",
"args",
".",
"DB",
".",
"Exec",
"(",
"dropq",
")",
"\n\n",
"// load column information",
"return",
"cols",
",",
"err",
"\n",
"}"
] |
// MyQueryColumns parses the query and generates a type for it.
|
[
"MyQueryColumns",
"parses",
"the",
"query",
"and",
"generates",
"a",
"type",
"for",
"it",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/mysql.go#L281-L303
|
22,893
|
xo/xo
|
internal/argtype.go
|
NewDefaultArgs
|
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{
"bool": true,
"string": true,
"byte": true,
"rune": true,
"int": true,
"int16": true,
"int32": true,
"int64": true,
"uint": true,
"uint8": true,
"uint16": true,
"uint32": true,
"uint64": true,
"float32": true,
"float64": true,
"Slice": true,
"StringSlice": true,
},
// ShortNameTypeMap is the collection of Go style short names for types, mainly
// used for use with declaring a func receiver on a type.
ShortNameTypeMap: map[string]string{
"bool": "b",
"string": "s",
"byte": "b",
"rune": "r",
"int": "i",
"int16": "i",
"int32": "i",
"int64": "i",
"uint": "u",
"uint8": "u",
"uint16": "u",
"uint32": "u",
"uint64": "u",
"float32": "f",
"float64": "f",
"Slice": "s",
"StringSlice": "ss",
},
}
}
|
go
|
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{
"bool": true,
"string": true,
"byte": true,
"rune": true,
"int": true,
"int16": true,
"int32": true,
"int64": true,
"uint": true,
"uint8": true,
"uint16": true,
"uint32": true,
"uint64": true,
"float32": true,
"float64": true,
"Slice": true,
"StringSlice": true,
},
// ShortNameTypeMap is the collection of Go style short names for types, mainly
// used for use with declaring a func receiver on a type.
ShortNameTypeMap: map[string]string{
"bool": "b",
"string": "s",
"byte": "b",
"rune": "r",
"int": "i",
"int16": "i",
"int32": "i",
"int64": "i",
"uint": "u",
"uint8": "u",
"uint16": "u",
"uint32": "u",
"uint64": "u",
"float32": "f",
"float64": "f",
"Slice": "s",
"StringSlice": "ss",
},
}
}
|
[
"func",
"NewDefaultArgs",
"(",
")",
"*",
"ArgType",
"{",
"fkMode",
":=",
"FkModeSmart",
"\n\n",
"return",
"&",
"ArgType",
"{",
"Suffix",
":",
"\"",
"\"",
",",
"Int32Type",
":",
"\"",
"\"",
",",
"Uint32Type",
":",
"\"",
"\"",
",",
"ForeignKeyMode",
":",
"&",
"fkMode",
",",
"QueryParamDelimiter",
":",
"\"",
"\"",
",",
"NameConflictSuffix",
":",
"\"",
"\"",
",",
"// KnownTypeMap is the collection of known Go types.",
"KnownTypeMap",
":",
"map",
"[",
"string",
"]",
"bool",
"{",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"}",
",",
"// ShortNameTypeMap is the collection of Go style short names for types, mainly",
"// used for use with declaring a func receiver on a type.",
"ShortNameTypeMap",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
",",
"}",
"\n",
"}"
] |
// NewDefaultArgs returns the default arguments.
|
[
"NewDefaultArgs",
"returns",
"the",
"default",
"arguments",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/internal/argtype.go#L156-L210
|
22,894
|
xo/xo
|
models/msidentity.xo.go
|
MsIdentities
|
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)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*MsIdentity{}
for q.Next() {
mi := MsIdentity{}
// scan
err = q.Scan(&mi.TableName)
if err != nil {
return nil, err
}
res = append(res, &mi)
}
return res, nil
}
|
go
|
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)
if err != nil {
return nil, err
}
defer q.Close()
// load results
res := []*MsIdentity{}
for q.Next() {
mi := MsIdentity{}
// scan
err = q.Scan(&mi.TableName)
if err != nil {
return nil, err
}
res = append(res, &mi)
}
return res, nil
}
|
[
"func",
"MsIdentities",
"(",
"db",
"XODB",
",",
"schema",
"string",
")",
"(",
"[",
"]",
"*",
"MsIdentity",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// 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'`",
"\n\n",
"// run query",
"XOLog",
"(",
"sqlstr",
",",
"schema",
")",
"\n",
"q",
",",
"err",
":=",
"db",
".",
"Query",
"(",
"sqlstr",
",",
"schema",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"q",
".",
"Close",
"(",
")",
"\n\n",
"// load results",
"res",
":=",
"[",
"]",
"*",
"MsIdentity",
"{",
"}",
"\n",
"for",
"q",
".",
"Next",
"(",
")",
"{",
"mi",
":=",
"MsIdentity",
"{",
"}",
"\n\n",
"// scan",
"err",
"=",
"q",
".",
"Scan",
"(",
"&",
"mi",
".",
"TableName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"&",
"mi",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// MsIdentities runs a custom query, returning results as MsIdentity.
|
[
"MsIdentities",
"runs",
"a",
"custom",
"query",
"returning",
"results",
"as",
"MsIdentity",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/models/msidentity.xo.go#L12-L44
|
22,895
|
xo/xo
|
loaders/postgres.go
|
PgRelkind
|
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
}
|
go
|
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
}
|
[
"func",
"PgRelkind",
"(",
"relType",
"internal",
".",
"RelType",
")",
"string",
"{",
"var",
"s",
"string",
"\n",
"switch",
"relType",
"{",
"case",
"internal",
".",
"Table",
":",
"s",
"=",
"\"",
"\"",
"\n",
"case",
"internal",
".",
"View",
":",
"s",
"=",
"\"",
"\"",
"\n",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] |
// PgRelkind returns the postgres string representation for RelType.
|
[
"PgRelkind",
"returns",
"the",
"postgres",
"string",
"representation",
"for",
"RelType",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/postgres.go#L39-L50
|
22,896
|
xo/xo
|
loaders/postgres.go
|
PgQueryStrip
|
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] = ""
}
}
}
|
go
|
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] = ""
}
}
}
|
[
"func",
"PgQueryStrip",
"(",
"query",
"[",
"]",
"string",
",",
"queryComments",
"[",
"]",
"string",
")",
"{",
"for",
"i",
",",
"l",
":=",
"range",
"query",
"{",
"pos",
":=",
"pgQueryStripRE",
".",
"FindStringIndex",
"(",
"l",
")",
"\n",
"if",
"pos",
"!=",
"nil",
"{",
"query",
"[",
"i",
"]",
"=",
"l",
"[",
":",
"pos",
"[",
"0",
"]",
"]",
"+",
"l",
"[",
"pos",
"[",
"1",
"]",
":",
"]",
"\n",
"queryComments",
"[",
"i",
"+",
"1",
"]",
"=",
"l",
"[",
"pos",
"[",
"0",
"]",
":",
"pos",
"[",
"1",
"]",
"]",
"\n",
"}",
"else",
"{",
"queryComments",
"[",
"i",
"+",
"1",
"]",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// PgQueryStrip strips stuff.
|
[
"PgQueryStrip",
"strips",
"stuff",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/postgres.go#L219-L229
|
22,897
|
xo/xo
|
loaders/postgres.go
|
PgTables
|
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{}
}
// Add information about manual FK.
var tables []*models.Table
for _, row := range rows {
manualPk := true
// Look for a match in the table name where it contains the sequence
for _, sequence := range sequences {
if sequence.TableName == row.TableName {
manualPk = false
}
}
tables = append(tables, &models.Table{
TableName: row.TableName,
Type: row.Type,
ManualPk: manualPk,
})
}
return tables, nil
}
|
go
|
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{}
}
// Add information about manual FK.
var tables []*models.Table
for _, row := range rows {
manualPk := true
// Look for a match in the table name where it contains the sequence
for _, sequence := range sequences {
if sequence.TableName == row.TableName {
manualPk = false
}
}
tables = append(tables, &models.Table{
TableName: row.TableName,
Type: row.Type,
ManualPk: manualPk,
})
}
return tables, nil
}
|
[
"func",
"PgTables",
"(",
"db",
"models",
".",
"XODB",
",",
"schema",
"string",
",",
"relkind",
"string",
")",
"(",
"[",
"]",
"*",
"models",
".",
"Table",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// get the tables",
"rows",
",",
"err",
":=",
"models",
".",
"PgTables",
"(",
"db",
",",
"schema",
",",
"relkind",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Get the tables that have a sequence defined.",
"sequences",
",",
"err",
":=",
"models",
".",
"PgSequences",
"(",
"db",
",",
"schema",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Set it to an empty set on error.",
"sequences",
"=",
"[",
"]",
"*",
"models",
".",
"Sequence",
"{",
"}",
"\n",
"}",
"\n\n",
"// Add information about manual FK.",
"var",
"tables",
"[",
"]",
"*",
"models",
".",
"Table",
"\n",
"for",
"_",
",",
"row",
":=",
"range",
"rows",
"{",
"manualPk",
":=",
"true",
"\n",
"// Look for a match in the table name where it contains the sequence",
"for",
"_",
",",
"sequence",
":=",
"range",
"sequences",
"{",
"if",
"sequence",
".",
"TableName",
"==",
"row",
".",
"TableName",
"{",
"manualPk",
"=",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"tables",
"=",
"append",
"(",
"tables",
",",
"&",
"models",
".",
"Table",
"{",
"TableName",
":",
"row",
".",
"TableName",
",",
"Type",
":",
"row",
".",
"Type",
",",
"ManualPk",
":",
"manualPk",
",",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"tables",
",",
"nil",
"\n",
"}"
] |
// PgTables returns the Postgres tables with the manual PK information added.
// ManualPk is true when the table does not have a sequence defined.
|
[
"PgTables",
"returns",
"the",
"Postgres",
"tables",
"with",
"the",
"manual",
"PK",
"information",
"added",
".",
"ManualPk",
"is",
"true",
"when",
"the",
"table",
"does",
"not",
"have",
"a",
"sequence",
"defined",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/postgres.go#L233-L267
|
22,898
|
xo/xo
|
loaders/postgres.go
|
PgQueryColumns
|
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 view was created
var nspq = `SELECT n.nspname ` +
`FROM pg_class c ` +
`JOIN pg_namespace n ON n.oid = c.relnamespace ` +
`WHERE n.nspname LIKE 'pg_temp%' AND c.relname = $1`
// run query
var schema string
models.XOLog(nspq, xoid)
err = args.DB.QueryRow(nspq, xoid).Scan(&schema)
if err != nil {
return nil, err
}
// load column information
return models.PgTableColumns(args.DB, schema, xoid, false)
}
|
go
|
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 view was created
var nspq = `SELECT n.nspname ` +
`FROM pg_class c ` +
`JOIN pg_namespace n ON n.oid = c.relnamespace ` +
`WHERE n.nspname LIKE 'pg_temp%' AND c.relname = $1`
// run query
var schema string
models.XOLog(nspq, xoid)
err = args.DB.QueryRow(nspq, xoid).Scan(&schema)
if err != nil {
return nil, err
}
// load column information
return models.PgTableColumns(args.DB, schema, xoid, false)
}
|
[
"func",
"PgQueryColumns",
"(",
"args",
"*",
"internal",
".",
"ArgType",
",",
"inspect",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"*",
"models",
".",
"Column",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// create temporary view xoid",
"xoid",
":=",
"\"",
"\"",
"+",
"internal",
".",
"GenRandomID",
"(",
")",
"\n",
"viewq",
":=",
"`CREATE TEMPORARY VIEW `",
"+",
"xoid",
"+",
"` AS (`",
"+",
"strings",
".",
"Join",
"(",
"inspect",
",",
"\"",
"\\n",
"\"",
")",
"+",
"`)`",
"\n",
"models",
".",
"XOLog",
"(",
"viewq",
")",
"\n",
"_",
",",
"err",
"=",
"args",
".",
"DB",
".",
"Exec",
"(",
"viewq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// query to determine schema name where temporary view was created",
"var",
"nspq",
"=",
"`SELECT n.nspname `",
"+",
"`FROM pg_class c `",
"+",
"`JOIN pg_namespace n ON n.oid = c.relnamespace `",
"+",
"`WHERE n.nspname LIKE 'pg_temp%' AND c.relname = $1`",
"\n\n",
"// run query",
"var",
"schema",
"string",
"\n",
"models",
".",
"XOLog",
"(",
"nspq",
",",
"xoid",
")",
"\n",
"err",
"=",
"args",
".",
"DB",
".",
"QueryRow",
"(",
"nspq",
",",
"xoid",
")",
".",
"Scan",
"(",
"&",
"schema",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// load column information",
"return",
"models",
".",
"PgTableColumns",
"(",
"args",
".",
"DB",
",",
"schema",
",",
"xoid",
",",
"false",
")",
"\n",
"}"
] |
// PgQueryColumns parses the query and generates a type for it.
|
[
"PgQueryColumns",
"parses",
"the",
"query",
"and",
"generates",
"a",
"type",
"for",
"it",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/postgres.go#L270-L298
|
22,899
|
xo/xo
|
loaders/postgres.go
|
PgIndexColumns
|
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 + "."
}
// put cols in order using colOrder
ret := []*models.IndexColumn{}
for _, v := range strings.Split(colOrd.Ord, " ") {
cid, err := strconv.Atoi(v)
if err != nil {
return nil, fmt.Errorf("could not convert %s%s index %s column %s to int", s, table, index, v)
}
// find column
found := false
var c *models.IndexColumn
for _, ic := range cols {
if cid == ic.Cid {
found = true
c = ic
break
}
}
// sanity check
if !found {
return nil, fmt.Errorf("could not find %s%s index %s column id %d", s, table, index, cid)
}
ret = append(ret, c)
}
return ret, nil
}
|
go
|
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 + "."
}
// put cols in order using colOrder
ret := []*models.IndexColumn{}
for _, v := range strings.Split(colOrd.Ord, " ") {
cid, err := strconv.Atoi(v)
if err != nil {
return nil, fmt.Errorf("could not convert %s%s index %s column %s to int", s, table, index, v)
}
// find column
found := false
var c *models.IndexColumn
for _, ic := range cols {
if cid == ic.Cid {
found = true
c = ic
break
}
}
// sanity check
if !found {
return nil, fmt.Errorf("could not find %s%s index %s column id %d", s, table, index, cid)
}
ret = append(ret, c)
}
return ret, nil
}
|
[
"func",
"PgIndexColumns",
"(",
"db",
"models",
".",
"XODB",
",",
"schema",
"string",
",",
"table",
"string",
",",
"index",
"string",
")",
"(",
"[",
"]",
"*",
"models",
".",
"IndexColumn",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"// load columns",
"cols",
",",
"err",
":=",
"models",
".",
"PgIndexColumns",
"(",
"db",
",",
"schema",
",",
"index",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// load col order",
"colOrd",
",",
"err",
":=",
"models",
".",
"PgGetColOrder",
"(",
"db",
",",
"schema",
",",
"index",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// build schema name used in errors",
"s",
":=",
"schema",
"\n",
"if",
"s",
"!=",
"\"",
"\"",
"{",
"s",
"=",
"s",
"+",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// put cols in order using colOrder",
"ret",
":=",
"[",
"]",
"*",
"models",
".",
"IndexColumn",
"{",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"strings",
".",
"Split",
"(",
"colOrd",
".",
"Ord",
",",
"\"",
"\"",
")",
"{",
"cid",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
",",
"table",
",",
"index",
",",
"v",
")",
"\n",
"}",
"\n\n",
"// find column",
"found",
":=",
"false",
"\n",
"var",
"c",
"*",
"models",
".",
"IndexColumn",
"\n",
"for",
"_",
",",
"ic",
":=",
"range",
"cols",
"{",
"if",
"cid",
"==",
"ic",
".",
"Cid",
"{",
"found",
"=",
"true",
"\n",
"c",
"=",
"ic",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"// sanity check",
"if",
"!",
"found",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
",",
"table",
",",
"index",
",",
"cid",
")",
"\n",
"}",
"\n\n",
"ret",
"=",
"append",
"(",
"ret",
",",
"c",
")",
"\n",
"}",
"\n\n",
"return",
"ret",
",",
"nil",
"\n",
"}"
] |
// PgIndexColumns returns the column list for an index.
|
[
"PgIndexColumns",
"returns",
"the",
"column",
"list",
"for",
"an",
"index",
"."
] |
1a94fa516029cb306cce6d379d086e4d5b5bb232
|
https://github.com/xo/xo/blob/1a94fa516029cb306cce6d379d086e4d5b5bb232/loaders/postgres.go#L301-L350
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.