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
/
Copy pathpg_description.go
95 lines (76 loc) · 2.14 KB
/
pg_description.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
package postlite
import (
"fmt"
"github.com/mattn/go-sqlite3"
)
type pgDescriptionModule struct{}
func (m *pgDescriptionModule) Create(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
err := c.DeclareVTab(fmt.Sprintf(`
CREATE TABLE %s (
objoid INTEGER,
classoid INTEGER,
objsubid INTEGER,
description TEXT
)`, args[0]))
if err != nil {
return nil, err
}
return &pgDescriptionTable{}, nil
}
func (m *pgDescriptionModule) Connect(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
return m.Create(c, args)
}
func (m *pgDescriptionModule) DestroyModule() {}
type pgDescriptionTable struct{}
func (t *pgDescriptionTable) Open() (sqlite3.VTabCursor, error) {
return &pgDescriptionCursor{}, nil
}
func (t *pgDescriptionTable) BestIndex(cst []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy) (*sqlite3.IndexResult, error) {
return &sqlite3.IndexResult{Used: make([]bool, len(cst))}, nil
}
func (t *pgDescriptionTable) Disconnect() error { return nil }
func (t *pgDescriptionTable) Destroy() error { return nil }
type pgDescriptionCursor struct {
index int
}
func (c *pgDescriptionCursor) Column(sctx *sqlite3.SQLiteContext, col int) error {
switch col {
case 0:
sctx.ResultInt(pgDescriptions[c.index].objoid)
case 1:
sctx.ResultInt(pgDescriptions[c.index].classoid)
case 2:
sctx.ResultInt(pgDescriptions[c.index].objsubid)
case 3:
sctx.ResultText(pgDescriptions[c.index].description)
}
return nil
}
func (c *pgDescriptionCursor) Filter(idxNum int, idxStr string, vals []interface{}) error {
c.index = 0
return nil
}
func (c *pgDescriptionCursor) Next() error {
c.index++
return nil
}
func (c *pgDescriptionCursor) EOF() bool {
return c.index >= len(pgDescriptions)
}
func (c *pgDescriptionCursor) Rowid() (int64, error) {
return int64(c.index), nil
}
func (c *pgDescriptionCursor) Close() error {
return nil
}
type pgDescription struct {
objoid int
classoid int
objsubid int
description string
}
var pgDescriptions = []pgDescription{
{11, 2615, 0, "system catalog schema"},
{99, 2615, 0, "reserved schema for TOAST tables"},
{2200, 2615, 0, "standard public schema"},
}