2021-01-29 02:48:29 +13:00
const { Database , aql } = require ( "arangojs" )
2021-01-29 02:42:40 +13:00
const { FIELD _TYPES , QUERY _TYPES } = require ( "./Integration" )
const SCHEMA = {
2021-01-29 03:17:39 +13:00
docs : "https://github.com/arangodb/arangojs" ,
2021-02-19 05:58:10 +13:00
friendlyName : "ArangoDB" ,
2021-02-20 04:07:43 +13:00
description :
"ArangoDB is a scalable open-source multi-model database natively supporting graph, document and search. All supported data models & access patterns can be combined in queries allowing for maximal flexibility. " ,
2021-01-29 03:17:39 +13:00
datasource : {
url : {
type : FIELD _TYPES . STRING ,
default : "http://localhost:8529" ,
required : true ,
2021-01-29 02:42:40 +13:00
} ,
2021-01-29 03:17:39 +13:00
username : {
type : FIELD _TYPES . STRING ,
default : "root" ,
required : true ,
2021-01-29 02:42:40 +13:00
} ,
2021-01-29 03:17:39 +13:00
password : {
type : FIELD _TYPES . PASSWORD ,
required : true ,
} ,
databaseName : {
type : FIELD _TYPES . STRING ,
default : "_system" ,
required : true ,
} ,
collection : {
type : FIELD _TYPES . STRING ,
required : true ,
} ,
} ,
query : {
read : {
type : QUERY _TYPES . SQL ,
} ,
create : {
type : QUERY _TYPES . JSON ,
} ,
} ,
2021-01-29 02:42:40 +13:00
}
class ArangoDBIntegration {
2021-01-29 03:17:39 +13:00
constructor ( config ) {
config . auth = {
username : config . username ,
password : config . password ,
2021-01-29 02:42:40 +13:00
}
2021-01-29 03:17:39 +13:00
this . config = config
this . client = new Database ( config )
}
async read ( query ) {
try {
const result = await this . client . query ( query . sql )
2021-01-29 04:08:53 +13:00
return result . all ( )
2021-01-29 03:17:39 +13:00
} catch ( err ) {
console . error ( "Error querying arangodb" , err . message )
throw err
} finally {
this . client . close ( )
2021-01-29 02:42:40 +13:00
}
2021-01-29 03:17:39 +13:00
}
2021-01-29 02:42:40 +13:00
2021-01-29 03:17:39 +13:00
async create ( query ) {
const clc = this . client . collection ( this . config . collection )
try {
const result = await this . client . query (
2021-01-29 04:08:53 +13:00
aql ` INSERT ${ query . json } INTO ${ clc } RETURN NEW `
2021-01-29 03:17:39 +13:00
)
2021-01-29 04:08:53 +13:00
return result . all ( )
2021-01-29 03:17:39 +13:00
} catch ( err ) {
console . error ( "Error querying arangodb" , err . message )
throw err
} finally {
this . client . close ( )
2021-01-29 02:42:40 +13:00
}
2021-01-29 03:17:39 +13:00
}
2021-01-29 02:42:40 +13:00
}
module . exports = {
schema : SCHEMA ,
integration : ArangoDBIntegration ,
2021-01-29 03:17:39 +13:00
}