Node.js Operation Firebird Database tutorial _node.js

Source: Internet
Author: User

Firebird is a cross-platform relational database system that can now run on Windows, Linux, and a variety of UNIX operating systems, providing most of the SQL-99 standard functionality. It can be used as a database server in multi-user environment, and also provide the implementation of embedded database.

Firebird is a completely non-commercial product, developed in C and C + +, which originated in Borland's Open source version of the database Interbase6.0.

A Firebird database server can manage multiple independent databases, each of which can support multiple client links at the same time. In short: It is an open source, powerful, freely available database (even commercially available).


Firebird is a true relational database that supports all the features of large relational databases such as stored procedures, views, triggers, transactions, and so on.

Firebird supports most of the SQL92 commands and supports most SQL99 commands, and the new version of Firebird 2.0 is more complete with SQL99 support;

Firebird source code based on the mature business database InterBase, has a good stability, and interbase have good compatibility;
No need to consider the licensing fee (free), do not worry about one day you or your customers because of the use of piracy and the database developers to court;

Easy release, installation files only a few m, and highly customizable, the distribution of the client is also very simple, just a DLL file;
Firebird of an embedded server version, without installation, direct operation, based on the first choice of single development;

The operation efficiency of Firebird is very high;

Highly portable, can operate under Linux,unix,macos,windows,solaris system, and the database format is exactly the same, without modification;

The development environment is well supported, Delphi,c++builder is not used to connect through ODBC, and develops the Firebird based program directly with the native development interface.

Why Use Firebird?

For small business users, there are now two deficiencies in the open source database: either too large (such as MySQL, PostgreSQL), too small, and lack of functionality and documentation (such as Hypersonicsql and Mckoi). In many application environments, users need to have a database of moderate size and full-featured.

Firebird relatively small, its RPM version is only 2.6MB. This makes it an ideal "embedded database" that can be used to bundle with other application servers and applications. Firebird has the functionality of most mature databases, such as supporting stored procedures, SQL compatibility, and so on. If users have the experience of using DB2 or PostgreSQL, they will find that Firebird is very similar to their syntax, and the data types are similar to the way they are processed.


With so much to say about Firebird, let's start by explaining how to use node to manipulate Firebird.

If you want to manipulate Firebird through node, you first install the module--node-firebird that operates Firebird. The following code:

NPM Install Node-firebird

After the installation is complete, we can use node in the program to manipulate Firebird, the following code:

var firebird = require (' Node-firebird ');

Connection Options

When we manipulate Firebird through node, we first set the database connection, including the IP address of the connection, the port number, the database name (which can be the full name of the path), the user name of the connection, and the password. The following code:

 var options = {}; = ' ';          Set host address
 options.port = 3050;              Port number
 options.database = '/home/user/test.fdb ';   Database name
 options.user = ' SYSDBA ';            User name
 Options.password = ' masterkey ';        Password

The connection to the database is set to complete.


There is a method named Escape in the Node-firebird module, and its return value is of type string. Use this method to prevent SQL injection, the following code:

Firebird.escape (value)-> return {String}

Examples are as follows:

var firebird = require (' Node-firebird ');
var sql1 = ' SELECT * from a WHERE id= ' +firebird.escape (2);
Console.log (SQL1);


The Create method is used to create a database with the following syntax format:

Firebird.create (options, function (err, db));

The following code:

Firebird.create (Options,function (err,db) {
  if (err)
    throw err;
  Console.log (' Create database Success ');
  Db.detach (); Close database Connection

Note: When a database is present, building a database with this method overwrites the original database, resulting in data loss.


The use of the Db.query method is described earlier, and will continue to be used here to explain the use of db.query (). The result returned is an array of object types (that is, the value of results) when the query statement is in the queries statement. We can use Db.query () to add, modify, delete, update the tables in the database. Db.query () has two uses, one is a query without parameters, the other is a query with parameters.

Queries with parameters:

Db.query (query, [params], function (err, result)

The instance code follows the insertion of data into table A:

Firebird.attach (options, function (err, db) {
  if (err)
    throw err;
  db.query (' insert into a (id,name) values (?,?) ', [1, ' Tom '], function (err, result) {
    if (err)
      t Hrow err;
    Console.log ("Insert success!");
    Db.detach ();

The instance code updates the data in table A:

Firebird.attach (options, function (err, db) {
  if (err)
  throw err;
  db.query ("Update a set name= ' Ann ' where id=1", function (err, result) {
    if (err)
      throw err;
    console.log ("Update success!");
    Db.detach ();

The above is the whole content of this article, teach everybody how to use Node.js Operation Firebird Database, hope everybody likes.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: