Merge pull request #113 from cie/node-remove-pre-api500-code

Remove old api version specific code, remove dbname from open/createDatabase
This commit is contained in:
Alec Grieser 2017-05-26 14:18:04 -07:00 committed by GitHub Enterprise
parent ad7c4708ec
commit 1e29aef09c
4 changed files with 17 additions and 87 deletions

View File

@ -23,25 +23,15 @@
var future = require('./future');
var Database = require('./database');
var apiVersion = require('./apiVersion');
var openDatabase = function(dbName) {
return new Database(this._cluster.openDatabase(dbName));
};
var openDatabase_v22 = function(dbName, cb) {
var database = new Database(this._cluster.openDatabase(dbName));
return future.resolve(database)(cb);
};
var Cluster = function(_cluster) {
this._cluster = _cluster;
this.options = _cluster.options;
if(apiVersion.value < 23)
this.openDatabase = openDatabase_v22;
else
this.openDatabase = openDatabase;
};
Cluster.prototype.openDatabase = function() {
return new Database(this._cluster.openDatabase());
};
module.exports = Cluster;

View File

@ -25,7 +25,6 @@ var Transaction = require('./transaction');
var future = require('./future');
var fdb = require('./fdbModule');
var fdbUtil = require('./fdbUtil');
var apiVersion = require('./apiVersion');
var onError = function(tr, err, func, cb) {
tr.onError(err, function(retryErr, retryRes) {
@ -125,10 +124,7 @@ Database.prototype.setAndWatch = function(key, value, cb) {
return this.doTransaction(function(tr, innerCb) {
tr.set(key, value);
var watchObj = tr.watch(key);
if(apiVersion.value >= 200)
innerCb(undefined, { watch: watchObj });
else
innerCb(undefined, watchObj);
innerCb(undefined, { watch: watchObj });
}, cb);
};
@ -136,10 +132,7 @@ Database.prototype.clearAndWatch = function(key, cb) {
return this.doTransaction(function(tr, innerCb) {
tr.clear(key);
var watchObj = tr.watch(key);
if(apiVersion.value >= 200)
innerCb(undefined, { watch: watchObj });
else
innerCb(undefined, watchObj);
innerCb(undefined, { watch: watchObj });
}, cb);
};

View File

@ -49,9 +49,6 @@ module.exports = {
if(!selectedApiVersion.value) {
fdb.apiVersion(version);
if(version < 23)
Cluster.prototype.createDatabase = Cluster.prototype.openDatabase;
fdbModule.FDBError = this.FDBError;
fdbModule.KeySelector = KeySelector;
fdbModule.future = future;
@ -67,7 +64,6 @@ module.exports = {
fdbModule.streamingMode = fdb.streamingMode;
var dbCache = {};
var clusterCache = {};
var doInit = function() {
fdb.startNetwork();
@ -75,7 +71,6 @@ module.exports = {
process.on('exit', function() {
//Clearing out the caches makes memory debugging a little easier
dbCache = null;
clusterCache = null;
fdb.stopNetwork();
});
@ -92,71 +87,23 @@ module.exports = {
if(!clusterFile)
clusterFile = '';
var cluster = new Cluster(fdb.createCluster(clusterFile));
if(version < 23)
return future.resolve(cluster)(cb);
else
return cluster;
return new Cluster(fdb.createCluster(clusterFile));
};
fdbModule.open = function(clusterFile, databaseName, cb) {
if(!databaseName)
databaseName = 'DB';
fdbModule.open = function(clusterFile, cb) {
if(clusterFile)
fdb.options.setClusterFile(clusterFile);
this.init();
var finish = function(err, database) {
if(version >= 23) //err will be undefined if version >= 23
return database;
else if(err)
return future.reject(err)(cb);
else
return future.resolve(database)(cb);
};
var updateDatabaseCacheAndFinish = function(err, database) {
if(!err)
dbCache[[clusterFile, databaseName]] = database;
return finish(err, database);
};
var getDatabase = function(cluster) {
var database = dbCache[[clusterFile, databaseName]];
if(database)
return finish(undefined, database);
else {
database = cluster.openDatabase(databaseName);
if(version >= 23)
return updateDatabaseCacheAndFinish(undefined, database);
else
return database(updateDatabaseCacheAndFinish);
}
};
var updateClusterCacheAndGetDatabase = function(err, cluster) {
if(err)
finish(err);
else {
clusterCache[clusterFile] = cluster;
return getDatabase(cluster);
}
};
var cluster = clusterCache[clusterFile];
if(cluster)
return getDatabase(cluster);
else {
cluster = fdbModule.createCluster(clusterFile);
if(version >= 23)
return updateClusterCacheAndGetDatabase(undefined, cluster);
else
return cluster(updateClusterCacheAndGetDatabase);
var database = dbCache[clusterFile];
if(!database) {
var cluster = fdbModule.createCluster(clusterFile);
database = cluster.openDatabase();
dbCache[clusterFile] = database;
}
return database;
};
}

View File

@ -45,8 +45,8 @@ Handle<Value> Cluster::OpenDatabase(const Arguments &args) {
Cluster *clusterPtr = ObjectWrap::Unwrap<Cluster>(args.Holder());
std::string dbName = *String::AsciiValue(args[0]->ToString());
FDBFuture *f = fdb_cluster_create_database(clusterPtr->cluster, (uint8_t*)dbName.c_str(), (int)strlen(dbName.c_str()));
const char *dbName = "DB";
FDBFuture *f = fdb_cluster_create_database(clusterPtr->cluster, (uint8_t*)dbName, (int)strlen(dbName));
fdb_error_t errorCode = fdb_future_block_until_ready(f);