-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_indexes.js
45 lines (40 loc) · 1.14 KB
/
create_indexes.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
var r = require('rethinkdbdash')({
pool: false,
cursor: true
});
function main() {
r.connect({host: 'localhost', port: 28015}, function(err, connection) {
if (err) throw err;
createIndices(connection);
});
}
function createIndices(connection) {
createIndex(connection, "credit");
createIndex(connection, "name");
//reql = reql.indexCreate("subjectArea", { multi: true });
createFunctionIndex(connection, "autumn", function(doc) {
return doc("semester")("autumn");
});
createFunctionIndex(connection, "spring", function(doc) {
return doc("semester")("spring");
});
}
function createIndex(connection, key) {
var reql = r.db('courses').table('ntnu_courses');
reql = reql.indexCreate(key);
reql.run(connection, function(err, res) {
console.log(err);
console.log(res);
console.log("Done.")
});
}
function createFunctionIndex(connection, name, callback) {
var reql = r.db('courses').table('ntnu_courses');
reql = reql.indexCreate(name, callback);
reql.run(connection, function(err, res) {
console.log(err);
console.log(res);
console.log("Done.")
});
}
main();