-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b30b9bb
commit b74b123
Showing
4 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
db "something.db" [ | ||
create 'users [ | ||
id: "INTEGER PRIMARY KEY" | ||
name: "VARCHAR(50)" | ||
] | ||
|
||
loop 1..10 'i [ | ||
insert 'users [name: ~"drkameleon: |i|"] | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
description: "Db management module for Arturo" | ||
version: "0.1" | ||
dependencies: [] | ||
author: "Yanis Zafirópulos" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
;========================================== | ||
; DB :module | ||
; for Arturo | ||
; | ||
; @file: db/main.art | ||
; @author: drkameleon | ||
;========================================== | ||
|
||
;------------------------------- | ||
; Main methods | ||
;------------------------------- | ||
|
||
db: function [name,block][ | ||
dbobj: dbOpen name | ||
|
||
create: function [table,contents][ | ||
fields: [] | ||
|
||
loop #contents [k,v][ | ||
if is? :string v -> | ||
'fields ++ ~"|k| |v|" | ||
] | ||
fields: join.with:", " fields | ||
|
||
query: ~"DROP TABLE IF EXISTS |table|" | ||
dbExec dbobj query | ||
|
||
query: ~"CREATE TABLE |table| (|fields|)" | ||
dbExec dbobj query | ||
] | ||
|
||
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|\"" | ||
|
||
query: ~"INSERT INTO |table| (|tableKeys|) VALUES (|tableValues|)" | ||
|
||
dbExec dbobj "BEGIN" | ||
dbExec dbobj query | ||
dbExec dbobj "COMMIT" | ||
] | ||
|
||
do block | ||
] |