xxxxxxxxxx
Firebird.attach(options, function(err, db) { if (err) throw err; // db = DATABASE db.query('SELECT * FROM TABLE', function(err, result) { // IMPORTANT: close the connection db.detach(); }); });
xxxxxxxxxx
var options = {}; options.host = '127.0.0.1';options.port = 3050;options.database = 'database.fdb';options.user = 'SYSDBA';options.password = 'masterkey';options.lowercase_keys = false; // set to true to lowercase keysoptions.role = null; // defaultoptions.pageSize = 4096; // default when creating database
xxxxxxxxxx
// 5 = the number is count of opened socketsvar pool = Firebird.pool(5, options); // Get a free poolpool.get(function(err, db) { if (err) throw err; // db = DATABASE db.query('SELECT * FROM TABLE', function(err, result) { // IMPORTANT: release the pool connection db.detach(); });}); // Destroy poolpool.destroy();
xxxxxxxxxx
Firebird.attach(options, function(err, db) { if (err) throw err; // db = DATABASE db.query('INSERT INTO USERS (ID, ALIAS, CREATED) VALUES(?, ?, ?) RETURNING ID', [1, 'Pe\'ter', new Date()], function(err, result) { console.log(result[0].id); db.query('SELECT * FROM USERS WHERE Alias=?', ['Peter'], function(err, result) { console.log(result); db.detach(); }); });});
xxxxxxxxxx
Firebird.attach(options, function(err, db) { if (err) throw err; // db = DATABASE // INSERT STREAM as BLOB db.query('INSERT INTO USERS (ID, ALIAS, FILE) VALUES(?, ?, ?)', [1, 'Peter', fs.createReadStream('/users/image.jpg')], function(err, result) { // IMPORTANT: close the connection db.detach(); });});
xxxxxxxxxx
Firebird.attach(options, function(err, db) { if (err) throw err; // db = DATABASE // INSERT BUFFER as BLOB db.query('INSERT INTO USERS (ID, ALIAS, FILE) VALUES(?, ?, ?)', [1, 'Peter', fs.readFileSync('/users/image.jpg')], function(err, result) { // IMPORTANT: close the connection db.detach(); });});
xxxxxxxxxx
Firebird.attach(options, function(err, db) { if (err) throw err; // db = DATABASE db.query('SELECT ID, ALIAS, USERPICTURE FROM USER', function(err, rows) { if (err) throw err; // first row rows[0].userpicture(function(err, name, e) { if (err) throw err; // +v0.2.4 // e.pipe(writeStream/Response); // e === EventEmitter e.on('data', function(chunk) { // reading data }); e.on('end', function() { // end reading // IMPORTANT: close the connection db.detach(); }); }); });});
xxxxxxxxxx
Firebird.attach(options, function(err, db) { if (err) throw err; // db = DATABASE db.sequentially('SELECT * FROM BIGTABLE', function(row, index) { // EXAMPLE stream.write(JSON.stringify(row)); }, function(err) { // END // IMPORTANT: close the connection db.detach(); });});
xxxxxxxxxx
Firebird.attach(options, function(err, db) { if (err) throw err; // db = DATABASE db.transaction(Firebird.ISOLATION_READ_COMMITED, function(err, transaction) { transaction.query('INSERT INTO users VALUE(?,?)', [1, 'Janko'], function(err, result) { if (err) { transaction.rollback(); return; } transaction.commit(function(err) { if (err) transaction.rollback(); else db.detach(); }); }); });});
xxxxxxxxxx
Firebird.attach(options, function(err, db) { if (err) throw err; db.on('row', function(row, index, isObject) { // index === Number // isObject === is row object or array? }); db.on('result', function(result) { // result === Array }); db.on('attach', function() { }); db.on('detach', function(isPoolConnection) { // isPoolConnection == Boolean }); db.on('reconnect', function() { }); db.on('error', function(err) { }); db.on('transaction', function(isolation) { // isolation === Number }); db.on('commit', function() { }); db.on('rollback', function() { }); db.detach();});