This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
pg_type.go
199 lines (180 loc) · 4.55 KB
/
pg_type.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package postlite
import (
"fmt"
"github.com/mattn/go-sqlite3"
)
type pgTypeModule struct{}
func (m *pgTypeModule) Create(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
err := c.DeclareVTab(fmt.Sprintf(`
CREATE TABLE %s (
oid INTEGER,
typname TEXT,
typnamespace INTEGER,
typowner INTEGER,
typlen INTEGER,
typbyval INTEGER,
typtype TEXT,
typcategory TEXT,
typispreferred INTEGER,
typisdefined INTEGER,
typdelim TEXT,
typrelid INTEGER,
typelem INTEGER,
typarray INTEGER,
typinput TEXT,
typoutput TEXT,
typreceive TEXT,
typsend TEXT,
typmodin TEXT,
typmodout TEXT,
typanalyze TEXT,
typalign TEXT,
typstorage TEXT,
typnotnull INTEGER,
typbasetype INTEGER,
typtypmod INTEGER,
typndims INTEGER,
typcollation INTEGER,
typdefaultbin TEXT,
typdefault TEXT,
typacl TEXT
)`, args[0]))
if err != nil {
return nil, err
}
return &pgTypeTable{}, nil
}
func (m *pgTypeModule) Connect(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
return m.Create(c, args)
}
func (m *pgTypeModule) DestroyModule() {}
type pgTypeTable struct{}
func (t *pgTypeTable) Open() (sqlite3.VTabCursor, error) {
return &pgTypeCursor{}, nil
}
func (t *pgTypeTable) BestIndex(cst []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy) (*sqlite3.IndexResult, error) {
return &sqlite3.IndexResult{Used: make([]bool, len(cst))}, nil
}
func (t *pgTypeTable) Disconnect() error { return nil }
func (t *pgTypeTable) Destroy() error { return nil }
type pgTypeCursor struct {
index int
}
func (c *pgTypeCursor) Column(sctx *sqlite3.SQLiteContext, col int) error {
switch col {
case 0:
sctx.ResultInt(pgTypes[c.index].oid)
case 1:
sctx.ResultText(pgTypes[c.index].typname)
case 2:
sctx.ResultInt(pgTypes[c.index].typnamespace)
case 3:
sctx.ResultInt(pgTypes[c.index].typowner)
case 4:
sctx.ResultInt(pgTypes[c.index].typlen)
case 5:
sctx.ResultInt(pgTypes[c.index].typbyval)
case 6:
sctx.ResultText(pgTypes[c.index].typtype)
case 7:
sctx.ResultText(pgTypes[c.index].typcategory)
case 8:
sctx.ResultInt(pgTypes[c.index].typispreferred)
case 9:
sctx.ResultInt(pgTypes[c.index].typisdefined)
case 10:
sctx.ResultText(pgTypes[c.index].typdelim)
case 11:
sctx.ResultInt(pgTypes[c.index].typrelid)
case 12:
sctx.ResultInt(pgTypes[c.index].typelem)
case 13:
sctx.ResultInt(pgTypes[c.index].typarray)
case 14:
sctx.ResultText(pgTypes[c.index].typinput)
case 15:
sctx.ResultText(pgTypes[c.index].typoutput)
case 16:
sctx.ResultText(pgTypes[c.index].typreceive)
case 17:
sctx.ResultText(pgTypes[c.index].typsend)
case 18:
sctx.ResultText(pgTypes[c.index].typmodin)
case 19:
sctx.ResultText(pgTypes[c.index].typmodout)
case 20:
sctx.ResultText(pgTypes[c.index].typanalyze)
case 21:
sctx.ResultText(pgTypes[c.index].typalign)
case 22:
sctx.ResultText(pgTypes[c.index].typstorage)
case 23:
sctx.ResultInt(pgTypes[c.index].typnotnull)
case 24:
sctx.ResultInt(pgTypes[c.index].typbasetype)
case 25:
sctx.ResultInt(pgTypes[c.index].typtypmod)
case 26:
sctx.ResultInt(pgTypes[c.index].typndims)
case 27:
sctx.ResultInt(pgTypes[c.index].typcollation)
case 28:
sctx.ResultText(pgTypes[c.index].typdefaultbin)
case 29:
sctx.ResultText(pgTypes[c.index].typdefault)
case 30:
sctx.ResultText(pgTypes[c.index].typacl)
}
return nil
}
func (c *pgTypeCursor) Filter(idxNum int, idxStr string, vals []interface{}) error {
c.index = 0
return nil
}
func (c *pgTypeCursor) Next() error {
c.index++
return nil
}
func (c *pgTypeCursor) EOF() bool {
return c.index >= len(pgTypes)
}
func (c *pgTypeCursor) Rowid() (int64, error) {
return int64(c.index), nil
}
func (c *pgTypeCursor) Close() error {
return nil
}
type pgType struct {
oid int
typname string
typnamespace int
typowner int
typlen int
typbyval int
typtype string
typcategory string
typispreferred int
typisdefined int
typdelim string
typrelid int
typelem int
typarray int
typinput string
typoutput string
typreceive string
typsend string
typmodin string
typmodout string
typanalyze string
typalign string
typstorage string
typnotnull int
typbasetype int
typtypmod int
typndims int
typcollation int
typdefaultbin string
typdefault string
typacl string
}
var pgTypes = []pgType{}