-
Notifications
You must be signed in to change notification settings - Fork 316
/
sequence.xo.go
47 lines (38 loc) · 1020 Bytes
/
sequence.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
// Package models contains the types for schema 'public'.
package models
// Code generated by xo. DO NOT EDIT.
// Sequence represents a row from '[custom sequence]'.
type Sequence struct {
TableName string // table_name
}
// PgSequences runs a custom query, returning results as Sequence.
func PgSequences(db XODB, schema string) ([]*Sequence, error) {
var err error
// sql query
const sqlstr = `SELECT ` +
`t.relname ` + // ::varchar AS table_name
`FROM pg_class s ` +
`JOIN pg_depend d ON d.objid = s.oid ` +
`JOIN pg_class t ON d.objid = s.oid AND d.refobjid = t.oid ` +
`JOIN pg_namespace n ON n.oid = s.relnamespace ` +
`WHERE n.nspname = $1 AND s.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
}