Skip to content

Commit

Permalink
rc 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
gramian committed Mar 12, 2024
1 parent 4358c92 commit 9a482cf
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 51 deletions.
36 changes: 22 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ as well as providing a JSON / REST-like / HTTP API.
The native query language of **ArcadeDB** is a dialect of SQL, closely related to
_OrientDB_'s OSQL, which supports the [SQL command categories](https://www.geeksforgeeks.org/sql-ddl-dql-dml-dcl-tcl-commands/):

* **DDL** - Data Definition Language, via `CREATE`, `DROP`, `ALTER`, `TRUNCATE` of `TYPE`s
* **DDL** - Data Definition Language, via `CREATE`, `DROP`, `ALTER`, `TRUNCATE` of `TYPE`s and `PROPERTY`s
* **DQL** - Data Query Language, via `SELECT`, `TRAVERSE`, `MATCH`
* **DML** - Data Manipulation Language, via `INSERT`, `UPDATE`, `DROP`, `EXPLAIN`, `PROFILE`
* **DML** - Data Manipulation Language, via `INSERT`, `UPDATE`, `DROP`, `CREATE VERTEX`, `CREATE EDGE`, `MOVE VERTEX`
* **TCL** - Transaction Control Language, via `BEGIN`, `COMMIT`, `ROLLBACK`

for the remaining categories holds:
for the remaining category holds:

* **DCL** - Data Control Language, does not apply due to only [server level users](https://docs.arcadedb.com/#Security)
* **TCL** - Transaction Control Language, via [HTTP REST endpoints](https://docs.arcadedb.com/#HTTP-API)


## About `arcadedb`

Expand All @@ -63,10 +64,8 @@ Furthermore, the `arcadedb` module requires `wget` for the HTTP requests:

* [wget](https://www.gnu.org/software/wget/)

during runtime, and imports the `uri-common` egg to url-encode strings,
as well as the `medea` egg to decode JSON:
during runtime, and imports the `medea` egg to decode JSON:

* [uri-common](https://wiki.call-cc.org/eggref/5/uri-common)
* [medea](https://wiki.call-cc.org/eggref/5/medea)

## Local Server Setup
Expand Down Expand Up @@ -107,6 +106,13 @@ Returns **alist** with single entry if connection to server using **string**s
`user`, `pass`, `host`, and optionally **number** `port`, succeded;
returns `#f` if a server error occurs or no response is received.

#### a-clear
```
(a-clear)
```

Returns `true` after clearing internal parameters `server` and `secret`.

### Server Information

#### a-ready?
Expand Down Expand Up @@ -279,19 +285,20 @@ Returns **boolean** that is true if automatic repair succeeded.

#### a-metadata
```
(a-metadata id key value)
(a-metadata id key . value)
```
Returns **boolean** that is true if adding custom attribute
with **symbol** `key` and **string** `value` to type or property **symbol** `id` succeeded.
Returns the value of the custom attribute with **symbol** `key` of type or property **symbol** `id`,
if `value` is not passed.
Returns **boolean** that is true if setting custom attribute **symbol** `key`
with **string** or **number** `value` succeded.

#### a-comment
```
(a-comment)
(a-comment msg)
(a-comment . msg)
```
Returns **string** current database comment of current database, if `msg` is not passed;
returns `#t` if setting **string** `msg` as comment for current database succeded;
returns `#f` if no comment is set, a server error occurs or no response is received.
Returns **string** being database comment of current database, if **string** `msg` is not passed.
Returns **boolean** that is true if setting database comment **string** `msg` succeded.

This function emulates the SQL `COMMENT ON DATABASE` statement,
by creating a type `sys` and upserting or reading the first `comment` property.
Expand All @@ -305,6 +312,7 @@ by creating a type `sys` and upserting or reading the first `comment` property.
* `0.5` [Major Update](https://github.com/gramian/chicken-arcadedb) (2023-03-01)
* `0.6` [Major Update](https://github.com/gramian/chicken-arcadedb) (2023-05-05)
* `0.7` [Minor Update](https://github.com/gramian/chicken-arcadedb) (2023-09-29)
* `0.8` [Major Update](https://github.com/gramian/chicken-arcadedb) (2024-03-12)

## License

Expand Down
6 changes: 3 additions & 3 deletions arcadedb.egg
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
;;;; arcadedb.egg

((version "0.7")
((version "0.8")
(synopsis "An ArcadeDB database driver for CHICKEN Scheme.")
(author "Christian Himpe")
(category db)
(license "ZLIB-Acknowledgement")
(dependencies uri-common medea)
(foreign-dependencies curl)
(dependencies medea)
(foreign-dependencies wget)
(platform (not windows))
(components (extension arcadedb (csc-options "-O3" "-d0" "-C" "-O2")))
)
3 changes: 2 additions & 1 deletion arcadedb.release-info
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
(release "0.4")
(release "0.5")
(release "0.6")
(release "0.7")
(release "0.7")
(release "0.8")
45 changes: 26 additions & 19 deletions arcadedb.scm
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
;;;; ArcadeDB CHICKEN Scheme Module

;;@project: chicken-arcadedb
;;@version: 0.7 (2023-09-29)
;;@version: 0.8 (2024-03-12)
;;@authors: Christian Himpe (0000-0003-2194-6754)
;;@license: zlib-acknowledgement (spdx.org/licenses/zlib-acknowledgement.html)
;;@summary: An ArcadeDB database driver for CHICKEN Scheme

(module arcadedb

(a-help
a-server
a-server a-clear
a-ready? a-version
a-list a-exist?
a-new a-delete
Expand All @@ -22,10 +22,9 @@
a-backup
a-stats a-health
a-repair
a-metadata
a-comment)
a-metadata a-comment)

(import scheme (chicken base) (chicken io) (chicken string) (chicken process) (chicken pathname) uri-common medea)
(import scheme (chicken base) (chicken io) (chicken string) (chicken process) (chicken pathname) medea)

(print "\n; arcadedb: call `(a-help)` for a procedure overview.\n")

Expand Down Expand Up @@ -73,6 +72,7 @@
" (a-help) - Display this message\n"
"\n"
" (a-server user pass host . port) - Set remote server\n"
" (a-clear) - Unset server\n"
"\n"
" (a-ready?) - Is server ready?\n"
" (a-version) - Server version\n"
Expand All @@ -84,7 +84,7 @@
" (a-delete db) - Drop database\n"
"\n"
" (a-use db) - Connect database\n"
" (a-using) - Connected database\n"
" (a-using) - Get connected database\n"
"\n"
" (a-query lang query) - Database query\n"
" (a-command lang cmd) - Database command\n"
Expand All @@ -99,8 +99,8 @@
" (a-stats) - Database statistics\n"
" (a-health) - Database health\n"
" (a-repair) - Repair database\n"
" (a-metadata id key value) - Add metadata\n"
" (a-comment [msg]) - Database comment\n"
" (a-metadata id key . value) - Get or set custom metadata\n"
" (a-comment . msg) - Get or set database comment\n"
"\n"
" For more info see: https://wiki.call-cc.org/eggref/5/arcadedb\n"))

Expand All @@ -113,6 +113,12 @@
(secret (cons user pass))
'((arcadedb . "Hello")))

;;@returns: `true`, after clearing internal parameters `server` and `secret`.
(define (a-clear)
(server #f)
(secret #f)
#t)

;;; Server Information #########################################################

;;@returns: **boolean** answering if server is ready.
Expand Down Expand Up @@ -209,8 +215,8 @@
;;@returns **flonum** being the Jaccard similarity index, given a **symbol** `type` and two **symbol** arguments `x` and `y`.
(define (a-jaccard type x y)
(assert (and (symbol? type) (symbol? x) (symbol? y)))
(cdaar (a-command 'sqlscript (string-append "SELECT intersect($t[0].x,$t[0].y).size().asFloat() / unionall($t[0].x,$t[0].y).size().asFloat()"
"LET $t = (SELECT unionall(" (symbol->string x) ") AS x, unionall(" (symbol->string y) ") AS y FROM " (symbol->string type)");"))))
(cdaar (a-command 'sql (string-append "SELECT intersect($t[0].x,$t[0].y).size().asFloat() / unionall($t[0].x,$t[0].y).size().asFloat()"
"LET $t = (SELECT unionall(" (symbol->string x) ") AS x, unionall(" (symbol->string y) ") AS y FROM " (symbol->string type)");"))))

;;@returns: **boolean** that is true if backing-up current database succeeded.
(define (a-backup)
Expand All @@ -232,17 +238,18 @@
(not (not (a-command 'sql "CHECK DATABASE FIX;"))))

;;@returns: **boolean** that is true if adding custom attribute with **symbol** `key` and **string** `value` to type or property **symbol** `id` succeeded.
(define (a-metadata id key value)
(assert (and (symbol? id) (symbol? key) (or (string? value) (number? value))))
(and (a-command 'sql (string-append "ALTER " (if (substring-index "." (symbol->string id)) "PROPERTY" "TYPE") " " (symbol->string id)
" CUSTOM " (symbol->string key) " = " (if (string? value) (string-append "\"" value "\"") (number->string value)) ";")) #t))
(define (a-metadata id key . value)
(assert (and (symbol? id) (symbol? key)))
(if (null? value)
(let [(res (a-query 'sql (string-append "SELECT custom." (symbol->string key) " FROM schema:types WHERE name = \"" (symbol->string id) "\";")))]
(and (not (null? res)) (not (eqv? (cdaar res) 'null)) (cdaar res)))
(and (a-command 'sql (string-append "ALTER " (if (substring-index "." (symbol->string id)) "PROPERTY" "TYPE") " " (symbol->string id)
" CUSTOM " (symbol->string key) " = " (if (string? (car value)) (string-append "\"" (car value) "\"") (number->string (car value))) ";")) #t)))

;;@returns: **string** comment, or `#t` if **string** `msg` is passed.
(define (a-comment . msg)
(and (a-command 'sql (string-append "CREATE DOCUMENT TYPE sys IF NOT EXISTS;"))
(if (null? msg) (let [(res (a-query 'sql (string-append "SELECT comment FROM sys WHERE on = \"database\" LIMIT 1;")))]
(and res (not (null? res)) (not (null? (car res))) (alist-ref 'comment (car res))))
(let [(str (car msg))]
(and (string? str) (a-command 'sql (string-append "UPDATE sys SET comment = \"" str "\" UPSERT WHERE on = \"database\";")) #t)))))
(and (a-command 'sql (string-append "CREATE VERTEX TYPE " (symbol->string (active)) " IF NOT EXISTS;"))
(if (null? msg) (a-metadata (active) 'comment)
(a-metadata (active) 'comment (car msg)))))

) ; end module
33 changes: 19 additions & 14 deletions arcadedb.wiki
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ as well as providing a JSON / REST-like / HTTP API.
The native query language of '''ArcadeDB''' is a dialect of SQL, closely related to
''OrientDB'''s OSQL, which supports the [[https://www.geeksforgeeks.org/sql-ddl-dql-dml-dcl-tcl-commands/|SQL command categories]]:
* '''DDL''' - Data Definition Language, via {{CREATE}}, {{DROP}}, {{ALTER}}, {{TRUNCATE}} of {{TYPE}}s
* '''DDL''' - Data Definition Language, via {{CREATE}}, {{DROP}}, {{ALTER}}, {{TRUNCATE}} of {{TYPE}}s and {{PROPERTY}}s
* '''DQL''' - Data Query Language, via {{SELECT}}, {{TRAVERSE}}, {{MATCH}}
* '''DML''' - Data Manipulation Language, via {{INSERT}}, {{UPDATE}}, {{DROP}}, {{EXPLAIN}}, {{PROFILE}}
* '''DML''' - Data Manipulation Language, via {{INSERT}}, {{UPDATE}}, {{DROP}}, {{CREATE VERTEX}}, {{CREATE EDGE}}, {{MOVE VERTEX}}
* '''TCL''' - Transaction Control Language, via {{BEGIN}}, {{COMMIT}}, {{ROLLBACK}}
for the remaining categories holds:
for the remaining category holds:
* '''DCL''' - Data Control Language, does not apply due to only [[https://docs.arcadedb.com/#Security|server level users]]
* '''TCL''' - Transaction Control Language, via [[https://docs.arcadedb.com/#HTTP-API|HTTP REST endpoints]]
== About {{arcadedb}}
Expand All @@ -64,10 +64,8 @@ Furthermore, the {{arcadedb}} module requires {{wget}} for the HTTP requests:
* [[https://www.gnu.org/software/wget/|wget]]
during runtime, and imports the {{uri-common}} egg to url-encode strings,
as well as the {{medea}} egg to decode JSON:
during runtime, and imports the {{medea}} egg to decode JSON:
* [[https://wiki.call-cc.org/eggref/5/uri-common|uri-common]]
* [[https://wiki.call-cc.org/eggref/5/medea|medea]]
== Local Server Setup
Expand Down Expand Up @@ -106,6 +104,11 @@ Returns '''alist''' with single entry if connection to server using '''string'''
{{user}}, {{pass}}, {{host}}, and optionally '''number''' {{port}}, succeded;
returns {{#f}} if a server error occurs or no response is received.
==== a-clear
<procedure>(a-clear)</procedure>
Returns {{true}} after clearing internal parameters {{server}} and {{secret}}.
=== Server Information
==== a-ready?
Expand Down Expand Up @@ -257,18 +260,19 @@ returns {{#f}} if a server error occurs or no response is received.
Returns '''boolean''' that is true if automatic repair succeeded.
==== a-metadata
<procedure>(a-metadata id key value)</procedure>
<procedure>(a-metadata id key . value)</procedure>
Returns '''boolean''' that is true if adding custom attribute
with '''symbol''' {{key}} and '''string''' {{value}} to type or property '''symbol''' {{id}} succeeded.
Returns the value of the custom attribute with '''symbol''' {{key}} of type or property '''symbol''' {{key}},
if {{value}} is not passed.
Returns '''boolean''' that is true if setting custom attribute '''symbol''' {{key}}
with '''string''' or '''number''' {{value}} succeded.
==== a-comment
<procedure>(a-comment)</procedure>
<procedure>(a-comment msg)</procedure>
<procedure>(a-comment . msg)</procedure>
Returns '''string''' current database comment of current database, if {{msg}} is not passed;
returns {{#t}} if '''string''' {{msg}} was set as comment for current database succeded;
returns {{#f}} if no comment is set, a server error occurs or no response is received.
Returns '''string''' being database comment of current database, if '''string''' {{msg}} is not passed.
Returns '''boolean''' that is true if setting database comment '''string''' {{msg}} succeded.
This function emulates the SQL {{COMMENT ON DATABASE}} statement,
by creating a type {{sys}} and upserting or reading the first {{comment}} property.
Expand All @@ -282,6 +286,7 @@ by creating a type {{sys}} and upserting or reading the first {{comment}} proper
* {{0.5}} [[https://github.com/gramian/chicken-arcadedb|Major Update]] (2023-03-01)
* {{0.6}} [[https://github.com/gramian/chicken-arcadedb|Major Update]] (2023-05-05)
* {{0.7}} [[https://github.com/gramian/chicken-arcadedb|Minor Update]] (2023-09-29)
* {{0.8}} [[https://github.com/gramian/chicken-arcadedb|Major Update]] (2024-03-12)
== License
Expand Down

0 comments on commit 9a482cf

Please sign in to comment.