add arangodb integration
This commit is contained in:
parent
1b6eb426c6
commit
8996200d8d
|
@ -2,84 +2,86 @@ const { Database, aql } = require("arangojs")
|
||||||
const { FIELD_TYPES, QUERY_TYPES } = require("./Integration")
|
const { FIELD_TYPES, QUERY_TYPES } = require("./Integration")
|
||||||
|
|
||||||
const SCHEMA = {
|
const SCHEMA = {
|
||||||
docs: "https://github.com/arangodb/arangojs",
|
docs: "https://github.com/arangodb/arangojs",
|
||||||
datasource: {
|
datasource: {
|
||||||
url: {
|
url: {
|
||||||
type: FIELD_TYPES.STRING,
|
type: FIELD_TYPES.STRING,
|
||||||
default: "http://localhost:8529",
|
default: "http://localhost:8529",
|
||||||
required: true,
|
required: true,
|
||||||
},
|
|
||||||
username: {
|
|
||||||
type: FIELD_TYPES.STRING,
|
|
||||||
default: "root",
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
password: {
|
|
||||||
type: FIELD_TYPES.PASSWORD,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
databaseName: {
|
|
||||||
type: FIELD_TYPES.STRING,
|
|
||||||
default: "_system",
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
collection: {
|
|
||||||
type: FIELD_TYPES.STRING,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
query: {
|
username: {
|
||||||
read: {
|
type: FIELD_TYPES.STRING,
|
||||||
type: QUERY_TYPES.SQL,
|
default: "root",
|
||||||
},
|
required: true,
|
||||||
create: {
|
|
||||||
type: QUERY_TYPES.JSON,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
class ArangoDBIntegration {
|
class ArangoDBIntegration {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
config.auth = {
|
config.auth = {
|
||||||
username: config.username,
|
username: config.username,
|
||||||
password: config.password,
|
password: config.password,
|
||||||
}
|
|
||||||
|
|
||||||
this.config = config
|
|
||||||
this.client = new Database(config)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async read(query) {
|
this.config = config
|
||||||
try {
|
this.client = new Database(config)
|
||||||
const result = await this.client.query(query.sql)
|
}
|
||||||
let rl = []
|
|
||||||
await result.forEach((r)=> rl.push(r))
|
|
||||||
return rl
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Error querying arangodb",err.message)
|
|
||||||
throw err
|
|
||||||
} finally {
|
|
||||||
this.client.close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async create(query) {
|
async read(query) {
|
||||||
const clc = this.client.collection(this.config.collection)
|
try {
|
||||||
try {
|
const result = await this.client.query(query.sql)
|
||||||
const result = await this.client.query(aql`INSERT ${query.json} INTO ${clc} LET n = NEW RETURN NEW`)
|
let rl = []
|
||||||
let rl = []
|
await result.forEach(r => rl.push(r))
|
||||||
await result.forEach((r)=> rl.push(r))
|
return rl
|
||||||
return rl
|
} catch (err) {
|
||||||
} catch (err) {
|
console.error("Error querying arangodb", err.message)
|
||||||
console.error("Error querying arangodb",err.message)
|
throw err
|
||||||
throw err
|
} finally {
|
||||||
} finally {
|
this.client.close()
|
||||||
this.client.close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(query) {
|
||||||
|
const clc = this.client.collection(this.config.collection)
|
||||||
|
try {
|
||||||
|
const result = await this.client.query(
|
||||||
|
aql`INSERT ${query.json} INTO ${clc} LET n = NEW RETURN NEW`
|
||||||
|
)
|
||||||
|
let rl = []
|
||||||
|
await result.forEach(r => rl.push(r))
|
||||||
|
return rl
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error querying arangodb", err.message)
|
||||||
|
throw err
|
||||||
|
} finally {
|
||||||
|
this.client.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
schema: SCHEMA,
|
schema: SCHEMA,
|
||||||
integration: ArangoDBIntegration,
|
integration: ArangoDBIntegration,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue