-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwith_cgo.go
More file actions
49 lines (40 loc) · 1.07 KB
/
with_cgo.go
File metadata and controls
49 lines (40 loc) · 1.07 KB
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
//go:build cgo
package sqlite
import (
"database/sql"
"net/url"
"strconv"
_ "github.com/mattn/go-sqlite3"
)
type sqlError struct {
Code int
ExtendedCode int
SystemErrno int
Err string
}
func (e sqlError) Error() string {
return e.Err
}
var errCantOpen = sqlError{
Code: 14,
ExtendedCode: 14,
SystemErrno: 0x0d,
Err: "unable to open database file: permission denied",
}
var errNoSuchTable = &sqlError{
Code: 1,
ExtendedCode: 1,
Err: "no such table: activities",
}
var defaultQueryParam = url.Values{
"_txlock": []string{"immediate"},
"_journal": []string{"WAL"},
"_busy_timeout": []string{strconv.Itoa(int(2 * defaultTimeout.Milliseconds()))},
"_synchronous": []string{"NORMAL"},
"cache_size": []string{"-64000"},
}
// sqlOpen will use the github.com/mattn/go-sqlite3 package when compiled with CGO
// this driver is more performant but, as said, it requires CGO
var sqlOpen = func(dataSourceName string) (*sql.DB, error) {
return sql.Open("sqlite3", dataSourceName+"?"+defaultQueryParam.Encode())
}