Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathdatabase_d_sqlite.v
More file actions
Latest commit
62 lines (53 loc) · 1.36 KB
/
Copy pathdatabase_d_sqlite.v
File metadata and controls
62 lines (53 loc) · 1.36 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
50
51
52
53
54
55
56
57
58
59
60
61
62
modulemain
importconfig
importdb.sqlite
importos
typeGitlyDb= sqlite.DB
fnconnect_db(conf config.Config) !GitlyDb {
path:=first_env(['GITLY_SQLITE_PATH', 'GITLY_DB_PATH'], conf.sqlite.path)
mutdb:= sqlite.connect(path)!
if db.busy_timeout(10000) !=0 {
returnerror('failed to configure sqlite busy timeout')
}
db.exec('pragma journal_mode = WAL;') or { eprintln('cannot enable sqlite WAL mode: ${err}') }
returnGitlyDb(db)
}
fndb_backend_name() string {
return'sqlite'
}
fndb_exec_values(mut db GitlyDb, query string) ![][]string {
rows:= db.exec(query)!
mutvalues:= [][]string{cap: rows.len}
for row in rows {
values << row.vals.clone()
}
return values
}
fndb_last_insert_id(mut db GitlyDb) int {
rows:= db.exec('select last_insert_rowid()') or { return0 }
if rows.len >0&& rows[0].vals.len >0 {
return rows[0].vals[0].int()
}
return0
}
fndb_column_exists(mut db GitlyDb, table_name string, column_name string) !bool {
rows:=db_exec_values(mut db, 'pragma table_info(${sql_table(table_name)})')!
for row in rows {
if row.len >1&& row[1] == column_name {
returntrue
}
}
returnfalse
}
fndb_bool_column_type() string {
return'INTEGER NOT NULL DEFAULT 0'
}
fnfirst_env(keys []string, fallback string) string {
for key in keys {
value:= os.getenv(key)
if value !='' {
return value
}
}
return fallback
}