Friday, November 21, 2014

Node.JS and Firebird driver (node-firebird-libfbclient) installing on Amazon EC2 instance

Here are the notes on Installing node.js module for firebird
I assume Firebird was installed from source or from tar.gz and in a linux instance


wget https://nodejs.org/dist/v4.6.0/node-v4.6.0.tar.gz
tar -zxvf node-v4.6.0.tar.gz
cd  node-v4.6.*
./configure 
sudo make install

Next is time to install the firebird module (Firebird was installed from source in /opt/firebird2.5.x)

git clone git://github.com/xdenser/node-firebird-libfbclient.git
cd node-firebird-lib
export PATH=$PATH:/opt/firebird2.5.x/binfbclient/

npm -g install

create firebird db and test table in /tmp/nodedb.fdb with isql or isql-fb

SQL>CREATE DATABASE "localhost:/tmp/nodedb.fdb" user 'SYSDBA' password '*********';
SQL> CREATE TABLE TEST (ID INT NOT NULL PRIMARY KEY, NAME VARCHAR(20));
SQL> create generator gen_test_id;
SQL> SET GENERATOR gen_test_id TO 10;
SQL> set term !! ;
SQL> CREATE TRIGGER TEST_BI FOR TEST
CON> ACTIVE BEFORE INSERT POSITION 0
CON> AS
CON> BEGIN
CON> if (NEW.ID is NULL) then NEW.ID = GEN_ID(GEN_TEST_ID, 1);
CON> END!!
SQL> set term ; !!

Then write the test.js script to connect to it



you can observe that the id is auto incremented if you run it multiple time

node test.js 
[ { ID: 5, NAME: 'new one' },
  { ID: 11, NAME: 'new one' },
  { ID: 12, NAME: 'new one' },
  { ID: 13, NAME: 'new one' },
  { ID: 14, NAME: 'new one' } ]

also in the name you can put later the
browser or the ip in one of the columns


We build now the version for the web modifying the hello world version adding the firebird database glue



you can run it with
 node firebird_example.js

No comments: