-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenumvalue.xo.go
48 lines (39 loc) · 1.06 KB
/
enumvalue.xo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Package models contains the types for schema 'public'.
package models
// Code generated by xo. DO NOT EDIT.
// EnumValue represents a enum value.
type EnumValue struct {
EnumValue string // enum_value
ConstValue int // const_value
}
// PgEnumValues runs a custom query, returning results as EnumValue.
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
}