Skip to content

Commit

Permalink
initial update
Browse files Browse the repository at this point in the history
  • Loading branch information
drkameleon committed Oct 30, 2020
1 parent b30b9bb commit b74b123
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
6 changes: 3 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MIT License

Copyright (c) 2020 Arturo Programming Language

Copyright (c) 2019-2020 Yanis Zafirópulos (aka Dr.Kameleon)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
10 changes: 10 additions & 0 deletions example.art
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|"]
]
]
4 changes: 4 additions & 0 deletions info.art
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"
45 changes: 45 additions & 0 deletions main.art
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
]

0 comments on commit b74b123

Please sign in to comment.