From b74b12377e55b833daeb7fb17ced4645d8e0e528 Mon Sep 17 00:00:00 2001 From: drkameleon Date: Fri, 30 Oct 2020 18:34:27 +0100 Subject: [PATCH] initial update --- LICENSE | 6 +++--- example.art | 10 ++++++++++ info.art | 4 ++++ main.art | 45 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 example.art create mode 100644 info.art create mode 100644 main.art diff --git a/LICENSE b/LICENSE index 540fa24..178f06a 100644 --- a/LICENSE +++ b/LICENSE @@ -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 @@ -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. \ No newline at end of file diff --git a/example.art b/example.art new file mode 100644 index 0000000..45c70f5 --- /dev/null +++ b/example.art @@ -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|"] + ] +] \ No newline at end of file diff --git a/info.art b/info.art new file mode 100644 index 0000000..960c5a4 --- /dev/null +++ b/info.art @@ -0,0 +1,4 @@ +description: "Db management module for Arturo" +version: "0.1" +dependencies: [] +author: "Yanis Zafirópulos" \ No newline at end of file diff --git a/main.art b/main.art new file mode 100644 index 0000000..63f822f --- /dev/null +++ b/main.art @@ -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 +] \ No newline at end of file