-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_db.nim
39 lines (26 loc) · 965 Bytes
/
create_db.nim
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
# Copyright Thomas T. Jarløv (TTJ) - ttj@ttj.dk
when NimMajor >= 2:
import
db_connector/db_sqlite
else:
import
std/db_sqlite
const dbName = "tests/db_general.db"
proc openDB*(): DbConn =
return open(dbName, "", "", "")
proc createDB*() =
let db = openDB()
db.exec(sql"DROP TABLE IF EXISTS my_table")
db.exec(sql"""CREATE TABLE my_table (
id INTEGER PRIMARY KEY,
name VARCHAR(50) NOT NULL,
age INTEGER,
ident TEXT,
is_nimmer BOOLEAN
)""")
db.exec(sql"INSERT INTO my_table (id, name) VALUES (0, ?)", "Jack")
for i in 1..5:
db.exec(sql("INSERT INTO my_table (id, name, age, ident, is_nimmer) VALUES (?, ?, ?, ?, ?)"), $i, "Joe-" & $i, $i, "Nim", (if i <= 2: "true" else: "false"))
for i in 6..10:
db.exec(sql("INSERT INTO my_table (id, name, age, ident) VALUES (?, ?, ?, ?)"), $i, "Cathrine-" & $i, $i, "Lag")
db.close()