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_settings.go
143 lines (124 loc) · 3.3 KB
/
pg_settings.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
package postlite
import (
"fmt"
"github.com/mattn/go-sqlite3"
)
type pgSettingsModule struct{}
func (m *pgSettingsModule) Create(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
err := c.DeclareVTab(fmt.Sprintf(`
CREATE TABLE %s (
name TEXT,
setting TEXT,
unit TEXT,
category TEXT,
short_desc TEXT,
extra_desc TEXT,
context TEXT,
vartype TEXT,
source TEXT,
min_val TEXT,
max_val TEXT,
enumvals TEXT,
boot_val TEXT,
reset_val TEXT,
sourcefile TEXT,
sourceline INTEGER,
pending_restart INTEGER
)`, args[0]))
if err != nil {
return nil, err
}
return &pgSettingsTable{}, nil
}
func (m *pgSettingsModule) Connect(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
return m.Create(c, args)
}
func (m *pgSettingsModule) DestroyModule() {}
type pgSettingsTable struct{}
func (t *pgSettingsTable) Open() (sqlite3.VTabCursor, error) {
return &pgSettingsCursor{}, nil
}
func (t *pgSettingsTable) BestIndex(cst []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy) (*sqlite3.IndexResult, error) {
return &sqlite3.IndexResult{Used: make([]bool, len(cst))}, nil
}
func (t *pgSettingsTable) Disconnect() error { return nil }
func (t *pgSettingsTable) Destroy() error { return nil }
type pgSettingsCursor struct {
index int
}
func (c *pgSettingsCursor) Column(sctx *sqlite3.SQLiteContext, col int) error {
switch col {
case 0:
sctx.ResultText(pgSettings[c.index].name)
case 1:
sctx.ResultText(pgSettings[c.index].setting)
case 2:
sctx.ResultText(pgSettings[c.index].unit)
case 3:
sctx.ResultText(pgSettings[c.index].category)
case 4:
sctx.ResultText(pgSettings[c.index].short_desc)
case 5:
sctx.ResultText(pgSettings[c.index].extra_desc)
case 6:
sctx.ResultText(pgSettings[c.index].context)
case 7:
sctx.ResultText(pgSettings[c.index].vartype)
case 8:
sctx.ResultText(pgSettings[c.index].source)
case 9:
sctx.ResultText(pgSettings[c.index].min_val)
case 10:
sctx.ResultText(pgSettings[c.index].max_val)
case 11:
sctx.ResultText(pgSettings[c.index].enumvals)
case 12:
sctx.ResultText(pgSettings[c.index].boot_val)
case 13:
sctx.ResultText(pgSettings[c.index].reset_val)
case 14:
sctx.ResultText(pgSettings[c.index].sourcefile)
case 15:
sctx.ResultInt(pgSettings[c.index].sourceline)
case 16:
sctx.ResultInt(pgSettings[c.index].pending_restart)
}
return nil
}
func (c *pgSettingsCursor) Filter(idxNum int, idxStr string, vals []interface{}) error {
c.index = 0
return nil
}
func (c *pgSettingsCursor) Next() error {
c.index++
return nil
}
func (c *pgSettingsCursor) EOF() bool {
return c.index >= len(pgSettings)
}
func (c *pgSettingsCursor) Rowid() (int64, error) {
return int64(c.index), nil
}
func (c *pgSettingsCursor) Close() error {
return nil
}
type pgSetting struct {
name string
setting string
unit string
category string
short_desc string
extra_desc string
context string
vartype string
source string
min_val string
max_val string
enumvals string
boot_val string
reset_val string
sourcefile string
sourceline int
pending_restart int
}
var pgSettings = []pgSetting{}