Pure JavaScript Firebird client for Node.js.
Pure JavaScript and Asynchronous Firebird client for Node.js. Firebird forum on Google Groups.
Firebird database on social networks
Changelog for version v0.2.x
- added auto-reconnect
- added sequentially selects
- events for connection (attach, detach, row, result, transaction, commit, rollback, error, etc.)
- performance improvements
- supports inserting/updating buffers and streams
- reading blobs (sequentially)
- pooling
database.detach()
waits for last command- better unit-test
- best of use with total.js - web application framework for node.js
Installation
npm install firebird-cli
Usage
var Firebird = ;
Methods
Firebird.escape(value) -> return {String}
- prevent for SQL InjectionsFirebird.attach(options, function(err, db))
attach a databaseFirebird.create(options, function(err, db))
create a databaseFirebird.attachOrCreate(options, function(err, db))
attach or create databaseFirebird.pool(max, options, function(err, db)) -> return {Object}
create a connection pooling
Connection types
Connection options
var options = {}; optionshost = '127.0.0.1';optionsport = 3050;optionsdatabase = 'database.fdb';optionsuser = 'SYSDBA';optionspassword = 'masterkey';optionslowercase_keys = false; // set to true to lowercase keysoptionsrole = null; // defaultoptionspageSize = 4096; // default when creating database
Classic
Firebird;
Pooling
// 5 = the number is count of opened socketsvar pool = Firebird; // Get a free poolpool; // Destroy poolpool;
Database object (db)
Methods
db.query(query, [params], function(err, result))
- classic query, returns Array of Objectdb.execute(query, [params], function(err, result))
- classic query, returns Array of Arraydb.sequentially(query, [params], function(row, index), function(err))
- sequentially querydb.detach(function(err))
detach a databasedb.transaction(isolation, function(err, transaction))
create transaction
Transaction methods
transaction.query(query, [params], function(err, result))
- classic query, returns Array of Objecttransaction.execute(query, [params], function(err, result))
- classic query, returns Array of Arraytransaction.commit(function(err))
commit current transactiontransaction.rollback(function(err))
rollback current transaction
Examples
PARAMETRIZED QUERIES
Parameters
Firebird;
BLOB (stream)
Firebird;
BLOB (buffer)
Firebird;
READING BLOBS (ASYNCHRONOUS)
Firebird;
STREAMING A BIG DATA
Firebird;
TRANSACTIONS
Transaction types:
Firebird.ISOLATION_READ_UNCOMMITTED
Firebird.ISOLATION_READ_COMMITED
Firebird.ISOLATION_REPEATABLE_READ
Firebird.ISOLATION_SERIALIZABLE
Firebird.ISOLATION_READ_COMMITED_READ_ONLY
Firebird;
EVENTS
Firebird;
Escaping query values
var sql1 = 'SELECT * FROM TBL_USER WHERE ID>' + Firebird;var sql2 = 'SELECT * FROM TBL_USER WHERE NAME=' + Firebird;var sql3 = 'SELECT * FROM TBL_USER WHERE CREATED<=' + Firebird;var sql4 = 'SELECT * FROM TBL_USER WHERE NEWSLETTER=' + Firebird; // or db.escape() console;console;console;console;
Service Manager functions
- backup
- restore
- fixproperties
- serverinfo
- database validation
- commit transaction
- rollback transaction
- recover transaction
- database stats
- users infos
- user actions (add modify remove)
- get firebird file log
- tracing
// each row : fctname : [params], typeofreturnvar fbsvc = "backup" : "options" "stream" "nbackup" : "options" "stream" "restore" : "options" "stream" "nrestore" : "options" "stream" "setDialect": "database""dialect" "stream" "setSweepinterval": "database""sweepinterval" "stream" "setCachebuffer" : "database""nbpagebuffers" "stream" "BringOnline" : "database" "stream" "Shutdown" : "database""shutdown""shutdowndelay""shutdownmode" "stream" "setShadow" : "database""activateshadow" "stream" "setForcewrite" : "database""forcewrite" "stream" "setReservespace" : "database""reservespace" "stream" "setReadonlyMode" : "database" "stream" "setReadwriteMode" : "database" "stream" "validate" : "options" "stream" "commit" : "database" "transactid" "stream" "rollback" : "database" "transactid" "stream" "recover" : "database" "transactid" "stream" "getStats" : "options" "stream" "getLog" : "options" "stream" "getUsers" : "username" "object" "addUser" : "username" "password" "options" "stream" "editUser" : "username" "options" "stream" "removeUser" : "username""rolename" "stream" "getFbserverInfos" : "options" "options" "object" "startTrace" : "options" "stream" "suspendTrace" : "options" "stream" "resumeTrace" : "options" "stream" "stopTrace" : "options" "stream" "getTraceList" : "options" "stream" "hasActionRunning" : "options" "object"
Backup Service example
Firebird
getLog and getFbserverInfos Service examples with use of stream and object return
fb.attach(_connection, function(err, svc) {
if (err)
return;
// all function that return a stream take two optional parameter
// optread => byline or buffer byline use isc_info_svc_line and buffer use isc_info_svc_to_eof
// buffersize => is the buffer for service manager it can't exceed 8ko (i'm not sure)
svc.getLog({optread:'buffer', buffersize:2048}, function (err, data) {
// data is a readablestream that contain the firebird.log file
console.log(err);
data.on('data', function (data) {
console.log(data.toString());
});
data.on('end', function() {
console.log('finish');
});
});
// an other exemple to use function that return object
svc.getFbserverInfos(
{
"dbinfo" : true,
"fbconfig" : true,
"svcversion" : true,
"fbversion" : true,
"fbimplementation" : true,
"fbcapatibilities" : true,
"pathsecuritydb" : true,
"fbenv" : true,
"fbenvlock" : true,
"fbenvmsg" : true
}, {}, function (err, data) {
console.log(err);
console.log(data);
});
});
Charset for database connection is always WIN1251
AuthServer = Legacy_Auth
WireCrypt = Disabled
Contributors
- Henri Gourvest, https://github.com/hgourvest
- Popa Marius Adrian, https://github.com/mariuz
- Peter Širka, https://github.com/petersirka