-
Notifications
You must be signed in to change notification settings - Fork 1
/
blem_persistence.go
54 lines (44 loc) · 926 Bytes
/
blem_persistence.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
package main
import (
"database/sql"
_ "github.com/mattn/go-sqlite3"
// https://astaxie.gitbooks.io/build-web-application-with-golang/content/en/05.3.html
// https://siongui.github.io/2016/01/09/go-sqlite-example-basic-usage/
)
func InitDB(filepath string) *sql.DB {
db, err := sql.Open("sqlite3", filepath)
if err != nil {
panic(err)
}
if db == nil {
panic("db nil")
}
return db
}
func InitTables(db *sql.DB) {
sql_table := `
CREATE TABLE IF NOT EXISTS TableMap(
TableID BIGINT PRIMARY KEY,
Schema TEXT,
Table TEXT
);
CREATE TABLE IF NOT EXISTS (
);
`
_, err := db.Exec(sql_table)
if err != nil {
panic(err)
}
}
func insertTableMap(t TypeTableName, DB *sql.DB) {
insert_TableMap := `
INSERT OR REPLACE INTO TableMap (
TableID, Schema, Table
) VALUES (?,?,?)
`
stmt, err := DB.Prepare(insert_TableMap)
if err != nil {
panic(err)
}
defer stmt.Close()
}