-
-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathdatabase_d_sqlite.v
More file actions
49 lines (41 loc) · 981 Bytes
/
database_d_sqlite.v
File metadata and controls
49 lines (41 loc) · 981 Bytes
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
module main
import config
import db.sqlite
import os
type GitlyDb = sqlite.DB
fn connect_db(conf config.Config) !GitlyDb {
path := first_env(['GITLY_SQLITE_PATH', 'GITLY_DB_PATH'], conf.sqlite.path)
return GitlyDb(sqlite.connect(path)!)
}
fn db_backend_name() string {
return 'sqlite'
}
fn db_exec_values(db &GitlyDb, query string) ![][]string {
rows := db.exec(query)!
mut values := [][]string{cap: rows.len}
for row in rows {
values << row.vals.clone()
}
return values
}
fn db_column_exists(db &GitlyDb, table_name string, column_name string) !bool {
rows := db_exec_values(db, 'pragma table_info(${sql_table(table_name)})')!
for row in rows {
if row.len > 1 && row[1] == column_name {
return true
}
}
return false
}
fn db_bool_column_type() string {
return 'INTEGER NOT NULL DEFAULT 0'
}
fn first_env(keys []string, fallback string) string {
for key in keys {
value := os.getenv(key)
if value != '' {
return value
}
}
return fallback
}