-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (33 loc) · 961 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* CLAY BASE SDK
*/
var API = require('./api.js')
var Table = require('./table.js')
function ClayBaseSDK(key, server) {
this.api = API(server, key);
this.tables = {}
/**
* Do a raw SQL query against the clay base
*/
this.query = function(rawQuery) {
return this.api.post('/bases/query').send({
query: rawQuery
}).then((res) => {
var result = res.body.result
return Promise.resolve(result);
})
}.bind(this)
this.getTable = function(table) {
if(!this.tables[table]) {
this.tables[table] = new Table(table, this);
}
return this.tables[table]
}.bind(this)
}
module.exports = function(key, server) {
if(!key) {
throw new Error('CLAY BASE: Use: new Base("<private key>"). Missing private key.');
}
server = server || 'https://base.clay.run/v1'
return new ClayBaseSDK(key, server);
};