-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbReader.js
49 lines (39 loc) · 1.14 KB
/
dbReader.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
42
43
44
45
46
47
48
const r = require('rethinkdb');
module.exports = function() {
let connection = null;
const dbName = 'mirror';
return {
init() {
return r
.connect({host: process.env.RETHINKDB_HOST, port: 28015})
.then((conn) => {
connection = conn;
connection.use(dbName);
});
},
readNodes() {
return r.table('nodes').orderBy('node_id', {index: 'node_id'}).run(connection);
},
readTempRevisions() {
return r.table('temp_revisions').orderBy({index: 'revision_id'}).run(connection);
},
readDatasets() {
return r.table('datasets').orderBy({index: 'dataset_node_id'}).run(connection);
},
readMetadata() {
return r
.table("files")
.orderBy({index:"revision_id"})
.eqJoin('revision_id', r.table("revisions"),
{index:'revision_id', ordered: true}
).zip().orderBy('revision_id')
.run(connection);
},
readOrganizations() {
return r.table('organizations').orderBy({index: 'organization_id'}).run(connection);
},
finish() {
return connection.close().then(() => { connection = null; });
},
}
};