node-firebird
Advanced tools
Comparing version 0.0.2 to 0.0.3
109
lib/index.js
@@ -622,3 +622,5 @@ var | ||
if (!data.readInt()) { | ||
return new Date((ret - DateOffset) * TimeCoeff); | ||
var d = new Date(0); | ||
d.setMilliseconds((ret - DateOffset) * TimeCoeff + d.getTimezoneOffset() * MsPerMinute) | ||
return d; | ||
} | ||
@@ -639,3 +641,5 @@ return null; | ||
if (!data.readInt()) { | ||
return new Date(Math.floor(ret / 10)); | ||
var d = new Date(0); | ||
d.setMilliseconds(Math.floor(ret / 10) + d.getTimezoneOffset() * MsPerMinute) | ||
return d; | ||
} | ||
@@ -657,3 +661,5 @@ return null; | ||
if (!data.readInt()) { | ||
return new Date((date - DateOffset) * TimeCoeff + Math.floor(time / 10)); | ||
var d = new Date(0); | ||
d.setMilliseconds((date - DateOffset) * TimeCoeff + Math.floor(time / 10) + d.getTimezoneOffset() * MsPerMinute); | ||
return d; | ||
} | ||
@@ -959,12 +965,10 @@ return null; | ||
var Database = exports.Database = function(host, port, database, user, password, callback, error) { | ||
var cnx = this.connection = new Connection(host, port); | ||
cnx.connect(database, function(){ | ||
cnx.attach(database, user, password, callback, error); | ||
}, error); | ||
}; | ||
function Database(connection) { | ||
this.connection = connection; | ||
} | ||
Database.prototype.detach = function(callback, error) { | ||
this.connection.detach(callback, error) | ||
} | ||
this.connection.detach(callback, error); | ||
this.connection.disconnect(); | ||
}; | ||
@@ -1008,2 +1012,37 @@ Database.prototype.startTransaction = function(isolation, callback, error) { | ||
exports.attach = function(host, port, database, user, password, callback, error){ | ||
var cnx = this.connection = new Connection(host, port); | ||
cnx.connect(database, function(ret){ | ||
if (!ret.status) { | ||
cnx.attach(database, user, password, callback, error); | ||
} else { | ||
doCallback(ret, callback, error) | ||
} | ||
}, error); | ||
}; | ||
exports.create = function(host, port, database, user, password, pageSize, callback, error) { | ||
var cnx = this.connection = new Connection(host, port); | ||
cnx.connect(database, function(ret){ | ||
if (!ret.status) { | ||
cnx.createDatabase(filename, user, password, pageSize, callback, error); | ||
} else { | ||
doCallback(ret, callback, error) | ||
} | ||
}, error); | ||
}; | ||
exports.attachOrCreate = function(host, port, database, user, password, pageSize, callback, error) { | ||
var cnx = this.connection = new Connection(host, port); | ||
cnx.connect(database, function(ret){ | ||
if (!ret.status) { | ||
cnx.attach(database, user, password, callback, function() { | ||
cnx.createDatabase(database, user, password, pageSize, callback, error); | ||
}); | ||
} else { | ||
doCallback(ret, callback, error) | ||
} | ||
}, error); | ||
}; | ||
/*************************************** | ||
@@ -1038,3 +1077,3 @@ * | ||
cb = self._queue[0]; | ||
obj = decodeResponse(xdr, cb.callback, cb.error); | ||
obj = decodeResponse(xdr, cb.callback); | ||
} catch(err) { | ||
@@ -1054,3 +1093,7 @@ buf = new Buffer(xdr.buffer.length - pos); | ||
function decodeResponse(data, callback, error){ | ||
exports.Connection.prototype.disconnect = function() { | ||
this._socket.end(); | ||
}; | ||
function decodeResponse(data, callback){ | ||
do {var r = data.readInt()} while (r == op_dummy); | ||
@@ -1135,14 +1178,2 @@ var item, op; | ||
} | ||
/* | ||
if (statement.rows) { | ||
for (var j = 0; j < rows.length; j++) { | ||
statement.rows.push(rows[j]) | ||
} | ||
} else { | ||
statement.rows = rows | ||
} | ||
if (status == 100) | ||
statement.fetched = true; | ||
*/ | ||
return {data: rows, fetched: Boolean(status == 100)}; | ||
@@ -1157,3 +1188,3 @@ case op_accept: | ||
} | ||
return; | ||
return {}; | ||
default: | ||
@@ -1216,6 +1247,8 @@ throw new Error('unexpected:' + r) | ||
var self = this; | ||
this._queueEvent(function (ret) { | ||
function cb(ret) { | ||
self.dbhandle = ret.handle; | ||
if (callback) {callback(ret)} | ||
}, error); | ||
doCallback(ret, callback, error); | ||
} | ||
cb.response = new Database(this); | ||
this._queueEvent(cb, error); | ||
}; | ||
@@ -1231,3 +1264,3 @@ | ||
delete(self.dbhandle); | ||
if (callback) {callback(ret)} | ||
doCallback(ret, callback, error); | ||
}, error); | ||
@@ -1257,6 +1290,8 @@ }; | ||
var self = this; | ||
this._queueEvent(function (ret) { | ||
function cb(ret) { | ||
self.dbhandle = ret.handle; | ||
if (callback) {callback(ret)} | ||
}, error); | ||
doCallback(ret, callback, error); | ||
} | ||
cb.response = new Database(this); | ||
this._queueEvent(cb, error); | ||
}; | ||
@@ -1465,5 +1500,3 @@ | ||
} | ||
if (callback) { | ||
callback(ret); | ||
} | ||
doCallback(ret, callback, error); | ||
}, error); | ||
@@ -1519,3 +1552,3 @@ }; | ||
case 'number': | ||
ret[i] = new SQLParamDouble(value) | ||
ret[i] = new SQLParamDouble(value); | ||
break; | ||
@@ -1689,3 +1722,3 @@ case 'string': | ||
fetchBlobs(statement, transaction, ret, callback, error) | ||
} | ||
}; | ||
cb.statement = statement; | ||
@@ -1692,0 +1725,0 @@ this._queueEvent(cb, error); |
@@ -223,5 +223,6 @@ | ||
XdrWriter.prototype.getData = function () { | ||
var buffer = new Buffer(this.pos); | ||
this.buffer.copy(buffer, 0); | ||
return buffer; | ||
//var buffer = new Buffer(this.pos); | ||
//this.buffer.copy(buffer, 0); | ||
//return buffer; | ||
return this.buffer.slice(0, this.pos); | ||
}; | ||
@@ -305,4 +306,5 @@ | ||
if (len) { | ||
var r = new Buffer(len); | ||
this.buffer.copy(r, 0, this.pos); | ||
//var r = new Buffer(len); | ||
//this.buffer.copy(r, 0, this.pos); | ||
var r = this.buffer.slice(this.pos, this.pos + len); | ||
this.pos += align(len); | ||
@@ -317,6 +319,11 @@ return r; | ||
} | ||
var r = new Buffer(len); | ||
this.buffer.copy(r, 0, this.pos); | ||
this.pos += align(len); | ||
return r; | ||
if (len) { | ||
//var r = new Buffer(len); | ||
//this.buffer.copy(r, 0, this.pos); | ||
var r = this.buffer.slice(this.pos, this.pos + len); | ||
this.pos += align(len); | ||
console.log(r.length); | ||
console.log(r); | ||
return r; | ||
} | ||
}; | ||
@@ -323,0 +330,0 @@ |
{ | ||
"name": "node-firebird", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Firebird client - pure javascript", | ||
@@ -19,3 +19,9 @@ "keywords": [ | ||
}, | ||
"main": "./lib" | ||
"main": "./lib", | ||
"readme": "# node-firebird\n\nPure javascript and asynchronous Firebird client for Node.js\n\n## Install\n\n\tnpm install node-firebird\n\n## Examples\n\n### Connecting\n\n\tfb = require(\"node-firebird\");\n\tfb.attach('127.0.0.1', 3050, db, 'SYSDBA', 'masterkey', \n\t\tfunction(db){\n database = db;\n\t\t\tconsole.log(\"connected\");\n\t\t}, \n\t\tfunction(error){\n\t\t\tconsole.log(\"can't connect\");\n\t\t}\n\t);\n\n### Querying\n\n#### Simple query\n\n\tdatabase.execute(\"select cast(? as integer) from rdb$database\", [123],\n\t\tfunction (result) {\n\t\t\tconsole.log(result.data)\n\t\t}\n\t);\n\nThe transaction automatically started and commited/rollbacked.\n\n- query is a non optional string.\n- params is optional, can be a single value or an array.\n- callback & error are optional.\n\n\n### Using transaction\n\n\tvar tr;\n\n\tfunction fail(err) {\n\t\ttr.rollback();\n\t\tconsole.log(err.status);\n\t}\n\n\tdatabase.startTransaction(function(transaction) {\n\t\ttr = transaction;\n\t\ttr.execute(\"select cast(? as integer) from rdb$database\", 123, function(result1) {\n\t\t\ttr.execute(\"select cast(? as integer) from rdb$database\", 456, function(result2) {\n\t\t\t\ttr.commit(function(ret) {\n\t\t\t\t\tconsole.log(result1.data[0]);\n\t\t\t\t\tconsole.log(result2.data[0]);\n\t\t\t\t}, fail)\n\t\t\t}, fail);\n\t\t}, fail);\n\t})\n\n### Errors handling\n\nMost async methods can trigger a callback and an error event, they are optionnals. If an error occur the error event will be called, if no error event is provided, the error will be sent to the callback event and you will have to check if the result is an error. An error object have a status property.\n\n\tfunction CheckResult(obj) {\n\t\tif (obj.status) {\n\t\t\tthrow new Error('oups')\n\t\t}\n\t}\n\n\tdatabase.startTransaction(function(transaction) {\n\t\ttransaction.execute(\"select cast(? as integer) from rdb$database\", 123, function(result) {\n\t\t\ttransaction.commit(function(ret) { // commit in all situations for a single query\n\t\t\t\tCheckResult(result); // error executing query ?\n\t\t\t\tCheckResult(ret); // error commiting ?\n\t\t\t\tconsole.log(result.data);\n\t\t\t})\n\t\t});\n\t})\n", | ||
"_id": "node-firebird@0.0.3", | ||
"dist": { | ||
"shasum": "0836eef393e350350e2f3772c544d59ea75a93a3" | ||
}, | ||
"_from": "node-firebird" | ||
} |
@@ -14,4 +14,5 @@ # node-firebird | ||
fb = require("node-firebird"); | ||
var database = new fb.Database('127.0.0.1', 3050, db, 'SYSDBA', 'masterkey', | ||
function(){ | ||
fb.attach('127.0.0.1', 3050, db, 'SYSDBA', 'masterkey', | ||
function(db){ | ||
database = db; | ||
console.log("connected"); | ||
@@ -18,0 +19,0 @@ }, |
@@ -8,4 +8,10 @@ fb = require("../lib"); | ||
host = '127.0.0.1'; | ||
port = 3050; | ||
user = 'SYSDBA'; | ||
password = 'masterkey'; | ||
pagesize = 4096; | ||
quit = function() { | ||
database.detach(function(ret){ | ||
database.detach(function(){ | ||
console.log('database detached'); | ||
@@ -33,3 +39,3 @@ }); | ||
function (result) { | ||
console.log(result.data); | ||
console.log(result.data[0][0]); | ||
}, | ||
@@ -67,3 +73,3 @@ // error | ||
tr.execute("select cast(? as integer) from rdb$database", 456, function(result2) { | ||
tr.commit(function(ret) { | ||
tr.commit(function() { | ||
console.log(result1.data[0]); | ||
@@ -81,11 +87,10 @@ console.log(result2.data[0]); | ||
var pool = []; | ||
var done = count; | ||
while (count > 0) { | ||
pool[--count] = new fb.Database('127.0.0.1', 3050, db, 'SYSDBA', 'masterkey', function() { | ||
done--; | ||
if (done == 0) { | ||
for(var i = 0; i < count; i++) { | ||
fb.attach(host, port, db, user, password, function(db) { | ||
pool[--count] = db; | ||
if (count == 0) { | ||
callback(pool); | ||
} | ||
} | ||
}, function(err) { | ||
callback(err) | ||
callback(err); | ||
callback = null; | ||
@@ -102,3 +107,3 @@ }) | ||
for (var i = 0; i < max; i++) { | ||
pool[i % poolsize].execute("select * from rdb$database", function(){ | ||
pool[i % poolsize].execute("select * from rdb$relations", function(){ | ||
if (--count == 0) { | ||
@@ -149,15 +154,12 @@ console.log(max + " queries"); | ||
}, error) | ||
} | ||
connect = function(callback, error){ | ||
database = new fb.Database('127.0.0.1', 3050, db, 'SYSDBA', 'masterkey', callback, error) | ||
}; | ||
repl.start(); | ||
connect( | ||
function() { | ||
console.log('connected'); | ||
}, | ||
logerror | ||
fb.attachOrCreate(host, port, db, user, password, pagesize, | ||
function (db) { | ||
database = db; | ||
test1() | ||
}, logerror | ||
); |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
2762
81
97002
6
1