MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / usqlRegister

Function usqlRegister

cmd/cql/internal/console.go:154–243  ·  view source on GitHub ↗

UsqlRegister init xo/usql driver

()

Source from the content-addressed store, hash-verified

152
153// UsqlRegister init xo/usql driver
154func usqlRegister() {
155 // set command name of usql
156 text.CommandName = "covenantsql"
157
158 // register SQLite3 database
159 drivers.Register("sqlite3", drivers.Driver{
160 AllowMultilineComments: true,
161 ForceParams: drivers.ForceQueryParameters([]string{
162 "loc", "auto",
163 }),
164 Version: func(db drivers.DB) (string, error) {
165 var ver string
166 err := db.QueryRow(`SELECT sqlite_version()`).Scan(&ver)
167 if err != nil {
168 return "", err
169 }
170 return "SQLite3 " + ver, nil
171 },
172 Err: func(err error) (string, string) {
173 if e, ok := err.(sqlite3.Error); ok {
174 return strconv.Itoa(int(e.Code)), e.Error()
175 }
176
177 code, msg := "", err.Error()
178 if e, ok := err.(sqlite3.ErrNo); ok {
179 code = strconv.Itoa(int(e))
180 }
181
182 return code, msg
183 },
184 ConvertBytes: func(buf []byte, tfmt string) (string, error) {
185 // attempt to convert buf if it matches a time format, and if it
186 // does, then return a formatted time string.
187 s := string(buf)
188 if s != "" && strings.TrimSpace(s) != "" {
189 t := new(SqTime)
190 if err := t.Scan(buf); err == nil {
191 return t.Format(tfmt), nil
192 }
193 }
194 return s, nil
195 },
196 })
197
198 // register CovenantSQL database
199 drivers.Register("covenantsql", drivers.Driver{
200 AllowMultilineComments: true,
201 Version: func(db drivers.DB) (string, error) {
202 return Version, nil
203 },
204 Err: func(err error) (string, string) {
205 return "", err.Error()
206 },
207 ConvertBytes: func(buf []byte, tfmt string) (string, error) {
208 // attempt to convert buf if it matches a time format, and if it
209 // does, then return a formatted time string.
210 s := string(buf)
211 if s != "" && strings.TrimSpace(s) != "" {

Callers 1

runConsoleFunction · 0.85

Calls 8

WaitDBCreationFunction · 0.92
RegisterMethod · 0.80
QueryRowMethod · 0.80
ErrorMethod · 0.80
InfofMethod · 0.80
ScanMethod · 0.45
FormatMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected