OrientDB API Demo 1

"By Athanassios I. Hatzis, PhD"<>" - (C) "<> DateString[]

Basic Test of API Commands

Create TOC

ClearAll["Global`*"]

<<AuthorTools`

nbkObj=SelectedNotebook[];
Paginate[nbkObj]
contObj=MakeContents[nbkObj,"Book"];

NotebookWrite[nbkObj,NotebookImport[contObj]]

Contents

Load Packages

<<"DBAPI`OrientDB`"

Get Server

serverDS=ODBapi[com-> "getServer", usr->"root",pwd-> "123"]//ODBgetDataset

serverDS["globalProperties"]

serverDS["properties"]

serverDS["connections"]

Database Operations

Create Database

ODBapi[
com->"addDatabase",
db->"demo",
dbtype->"plocal/document",
usr->"root",
pwd->"123"]//ODBgetDataset

Get Databases

ODBapi[com->"getDatabases"]//ODBgetDataset

Get Single Database

ODBapi[com->"getDatabases",db-> "demo"]//ODBgetDataset

Classes Operations

SetOptions[ODBapi,db->"demo"];

Add/Delete/Add/Get Class

ODBapi[com->"addClass", class-> "Person"]

ODBapi[com->"delClass",  class-> "Person"]

ODBapi[com->"addClass", class-> "Person"]

ODBapi[com->"getClass",class-> "Person"]//ODBgetDataset

OrientDB OSQL Operations

OrientDB - POST OSQL Command

Make a list of OrientDB SQL Commands (OSQL)

osqlCommmands={
"TRUNCATE CLASS Person",
"INSERT INTO Person (perName,perSurname) VALUES ('Jay','Miner')",
"INSERT INTO Person content {perName:'Luca',perAge:34}",
"UPDATE Person SET perCity='Rome' where perName='Luca'",
"UPDATE Person PUT perPhones = 'office', '+3906222222' WHERE perName = 'Luca'",
"UPDATE Person PUT perPhones = 'mobile', '+393333888' WHERE perName = 'Luca'","CREATE PROPERTY Person.favColours EMBEDDEDLIST STRING",
"UPDATE Person SET favColours=['blue','green'] where perName='Luca'"
};

Execute OSQL commands one by one

res=(ODBapi[com->"addOSQL",sql->#]&/@osqlCommmands)//TableForm

Set permanently the database and command parameters

SetOptions[ODBapi,db->"demo",com-> "addOSQL"];

Get Person records

ODBapi[sql->"select from Person"]//ODBgetDataset

OrientDB - POST OSQL Script

Delete Database

ODBapi[com->"delDatabase",db->"MemberArticleDB",usr->"root",pwd->"123"]

Create Database

ODBapi[com->"addDatabase",db->"MemberArticleDB",dbtype->"plocal/graph",usr->"root",pwd->"123"]//ODBgetDataset

Create Classes and Properties with an OrientDB SQL script

Make an OSQL Batch Script to Create the Graph Database

osqlScriptCreateDB="
create class MEMBER extends V;
create property MEMBER.name string;
alter property MEMBER.name min 3;
create property MEMBER.password string;
create property MEMBER.email string;

create class ARTICLE extends V;
create property ARTICLE.title string;
alter property ARTICLE.title min 3;
create property ARTICLE.content string;
create property ARTICLE.whenPublished date;
              
create class isFollowerOf extends E;
create class isReplyOf extends E;
create class isAuthorOf extends E";

Execute OSQL Script on MemberArticleDB

ODBapi[com->"addOSQL",db->"MemberArticleDB",sql-> osqlScriptCreateDB, mode->"BATCH"]//ODBgetDataset

Populate with a few MEMBERs and an ARTICLE

osqlScriptPopulateDB= "
	create vertex ARTICLE set title='OrientDB Tutorial', content='Some story about Orient DB';
	create vertex MEMBER set name='Petter graff',email='petter.graff@scispike.com',password='secret';
	insert into MEMBER content {name: 'suzy', email: 'suzy@hotmail.com'};
	insert into MEMBER (name,email) values ('groli','groli@yahoo.com'),('pat','pat@google.com')
	insert into MEMBER set name='athanassios',password='secret',email='hatzis@athanassios.gr'";

ODBapi[com->"addOSQLScript",db->"MemberArticleDB",sql-> osqlScriptPopulateDB]//ODBgetDataset

Create Edge - MEMBER isAuthorOf ARTICLE

osqlScriptCreateEdge="
BEGIN;
let member = CREATE VERTEX Member SET name = 'Jack Drovan';
let article = SELECT FROM Article WHERE title = 'OrientDB Tutorial';
CREATE EDGE isAuthorOf FROM $member TO $article;
COMMIT RETRY 100";

ODBapi[com->"addOSQLScript",db->"MemberArticleDB",sql-> osqlScriptCreateEdge]//ODBgetDataset

OrientDB - GET OSQL Script

Read-Only OrientDB SQL Command

These are idempotent commands like SQL SELECT and TRAVERSE

ODBapi[
com-> "getOSQL",
db-> "MemberArticleDB", 
class-> "Member", 
sql-> "select from Member"]//ODBgetDataset

ODBapi[
com-> "getOSQL",
db-> "MemberArticleDB", 
class-> "Article", 
sql-> "select from Article"]//ODBgetDataset