-
Notifications
You must be signed in to change notification settings - Fork 24
/
sqlite3.go
52 lines (44 loc) · 1.06 KB
/
sqlite3.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
// Package sqlite3 implements a Go interface to the SQLite database.
package sqlite3
// #cgo LDFLAGS: -lsqlite3
// #include <sqlite3.h>
import "C"
// Initialize starts the SQLite3 engine.
func Initialize() {
C.sqlite3_initialize()
}
// Shutdown stops the SQLite3 engine.
func Shutdown() {
C.sqlite3_shutdown()
}
// Session initializes a database and calls `f` to access it.
func Session(filename string, f func(db *Database)) {
Initialize()
defer Shutdown()
if db, e := Open(filename); e == nil {
defer db.Close()
f(db)
}
}
// TransientDatabase initializes a in-memory database and calls `f` to
// access it.
func TransientSession(f func(db *Database)) {
Initialize()
defer Shutdown()
if db := TransientDatabase(); db.Open() == nil {
defer db.Close()
f(db)
}
}
// LibVersion returns the version of the SQLite3 engine.
func LibVersion() string {
return C.GoString(C.sqlite3_libversion())
}
// Value represents any SQLite3 value.
type Value struct {
cptr *C.sqlite3_value
}
// Blob represents the SQLite3 blob type.
type Blob struct {
cptr *C.sqlite3_blob
}