-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.art
47 lines (36 loc) · 952 Bytes
/
main.art
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
;==========================================
; DB :module
; for Arturo
;
; @file: db/main.art
; @author: drkameleon
;==========================================
;-------------------------------
; Main methods
;-------------------------------
db: function [name,block][
dbobj: open name
create: function [table,contents][
fields: []
loop #contents [k,v][
if is? :string v ->
'fields ++ ~"|k| |v|"
]
fields: join.with:", " fields
q: ~"DROP TABLE IF EXISTS |table|"
query dbobj q
q: ~"CREATE TABLE |table| (|fields|)"
query dbobj q
]
insert: function [table,contents][
details: #contents
tableKeys: join.with:", " select keys details 'x -> is? :string details \ x
tableValues: join.with:", " map (select values details 'x -> is? :string x) 'x -> ~"\"|x|\""
q: ~"INSERT INTO |table| (|tableKeys|) VALUES (|tableValues|)"
query dbobj "BEGIN"
query dbobj q
query dbobj "COMMIT"
]
do block
close dbobj
]