node js firebird example

Example 1: node js firebird example

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();            });        });     });});

Example 2: node js firebird example

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();    });});

Example 3: node js firebird example

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();    });});

Example 4: node js firebird example

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();    });});

Example 5: node js firebird example

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();        });    });});

Example 6: node js firebird example

// 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();

Example 7: node js firebird example

AuthServer = Srp, Legacy_AuthWireCrypt = DisabledUserManager = Legacy_UserManager

Example 8: node js firebird example

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();    }); });

Example 9: node js firebird example

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);        });});

Example 10: node js firebird example

const options = {...}; // Classic configuration with manager = trueFirebird.attach(options, function(err, svc) {    if (err)        return;    svc.backup(        {            database:'/DB/MYDB.FDB',            files: [                    {                     filename:'/DB/MYDB.FBK',                     sizefile:'0'                    }                   ]        },        function(err, data) {            data.on('data', line => console.log(line));            data.on('end', () => svc.detach());        }    );});

Tags:

Misc Example