Firebird News

Sunday, January 30, 2011

#node.js and #firebird 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 (mine is the free one)


wget http://nodejs.org/dist/v0.10.25/node-v0.10.25.tar.gz
tar -zxvf node-v0.10.*.tar.gz
cd node-v0.10.*
./configure 
make ; sudo make install

start the node
node
it should give you the nice prompt
>
now is time to check one example
write a file example.js
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8080, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8080/');
launch it with
node example.js
it should look this way on http://localhost:8080




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 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

2 comments:

jono said...

Mariuz, thanks for this post.

very useful.
Tom

mariuz said...

I have updated the node guide to node js node-v0.4.4 also the driver is updated in the git version please check the changelog