forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.go
59 lines (50 loc) · 1.04 KB
/
info.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
49
50
51
52
53
54
55
56
57
58
59
package info
import (
"github.com/sqlc-dev/sqlc/internal/sql/catalog"
)
// Provide a read-only view into the catalog
func Newo(c *catalog.Catalog) InformationSchema {
return InformationSchema{c: c}
}
type InformationSchema struct {
c *catalog.Catalog
}
type Table struct {
Catalog string
Schema string
Name string
}
// SELECT * FROM information_schema.tables;
func (i *InformationSchema) Tables() []Table {
var tables []Table
for _, s := range i.c.Schemas {
for _, t := range s.Tables {
tables = append(tables, Table{
Catalog: i.c.Name,
Schema: s.Name,
Name: t.Rel.Name,
})
}
}
return tables
}
type Column struct {
Catalog string
Schema string
Table string
Name string
DataType string
IsNullable bool
}
// SELECT * FROM information_schema.columns;
func (i *InformationSchema) Columns() []Column {
return []Column{}
}
type Schema struct {
Catalog string
Name string
}
// SELECT * FROM information_schema.schemata;
func (i *InformationSchema) Schemata() []Schema {
return []Schema{}
}