-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
102 lines (87 loc) · 1.97 KB
/
Copy pathindex.js
File metadata and controls
102 lines (87 loc) · 1.97 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"use strict";
var fdb = require('fdb').apiVersion(200);
var _ = require('lodash');
var indexes = require('./lib/indexes');
var Transaction = require('./lib/transaction');
var Query = require('./lib/query');
//
// Globals
//
var db;
var indexMeta = {};
function transaction(){
return new Transaction(fdb, db, indexMeta);
}
function query(keyPath, fields, opts){
return new Query(keyPath, fields, opts)
}
exports.open = function(clusterFile, dbName)
{
db = fdb.open(clusterFile, dbName);
var tr = transaction();
indexes.readMeta(tr).then(function(meta){
indexMeta = meta || {};
});
tr.commit();
}
exports.options = fdb.options;
exports.transaction = transaction;
exports.query = query;
/**
Add a index
*/
exports.addIndex = function(keyPath, fields)
{
fields = _.isArray(fields) ? fields : [fields];
var tr = transaction();
for(var i=0; i<fields.length; i++){
indexes.makeIndex(tr, keyPath, fields[i]);
indexMeta[keyPath.join('/')] = true;
}
return tr.commit();
}
/**
Rebuilds a index.
*/
exports.rebuildIndex = function(keyPath, fields)
{
// TO IMPLEMENT
}
/**
Single operations bluebird no transactions needed.
*/
exports.create = function(keyPath, args){
var tr = transaction();
var res = tr.create(keyPath, args);
return tr.commit().then(function(){
return res;
});
}
exports.put = function(keyPath, args){
var tr = transaction();
var res = tr.put(keyPath, args);
return tr.commit().then(function(){
return res;
});
}
exports.get = function(keyPath){
var tr = transaction();
var res = tr.get(keyPath);
return tr.commit().then(function(){
return res;
});
}
exports.remove = function(keyPath){
var tr = transaction();
var res = tr.remove(keyPath);
return tr.commit().then(function(){
return res;
});
}
exports.find = function(keyPath, where, fields, options){
var tr = transaction();
var res = tr.find(keyPath, where, fields, options);
return tr.commit().then(function(){
return res;
});
}