Node. js Firebird Database tutorial, node. jsfirebird

Source: Internet
Author: User
Tags firebird database interbase install node npm install node

Node. js Firebird Database tutorial, node. jsfirebird

Firebird is a cross-platform relational database system that currently runs on Windows, linux and a variety of Unix operating systems, providing most of the SQL-99 standard features. It can be used as a database server in a multi-user environment, as well as embedded database implementation.

Firebird originated from Borland's open-source database Interbase6.0. It is a completely non-commercial product developed using C and C ++.

A firebird Database Server can manage multiple independent databases. Each database supports multiple client connections at the same time. In short: it is an open-source, powerful, and free-to-use database (even for commercial use ).

Features

Firebird is a real relational database that supports all features of large relational databases, such as stored procedures, views, triggers, and transactions;

Firebird supports the vast majority of SQL92 commands and most SQL99 commands. The new Firebird 2.0 version provides more complete support for SQL99;

Firebird source code is based on mature commercial database Interbase, with good stability and good compatibility with Interbase;
You don't need to consider the authorization fee (free of charge), and you don't have to worry that one day you or your customers will be taken to court by database developers for piracy;

Easy to publish. The installation file is only a few MB and highly customizable. The client distribution is also very simple. Only one DLL file is required;
An Embedded Server version of Firebird that runs directly without installation. It is preferred for standalone development;

Firebird is highly efficient;

It is highly portable and can run in Linux, Unix, MacOS, Windows, and Solaris systems. The database format is the same and does not need to be modified;

The Development Environment supports well. Delphi and C ++ Builder do not use ODBC connections to directly develop Firebird-based programs using native development interfaces.

Why FireBird?

For small enterprise users, the current open source database has two shortcomings: either too large (such as MySQL and PostgreSQL) or too small, and lack of functions and documentation (such as HypersonicSQL and McKoi ). In many application environments, you need a database of moderate size and complete functions.

Firebird is relatively small, and its RPM version is only 2.6 MB. This makes it an ideal "Embedded Database" for bundling with other application servers and applications. Firebird has the functions of most mature databases, such as supporting stored procedures and SQL compatibility. If you have experience using DB2 or PostgreSQL, you will find that Firebird is very similar to their syntax, and the data type and data processing method are similar.

Install

I have discussed so much about FireBird. Now I will explain how to use Node to operate FireBird.

If you want to use Node to operate FireBird, first install the node-FireBird module. The following code:

npm install node-firebird

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

var FireBird = require('node-firebird');

Connection options

When we use node to operate FireBird, we must first set the database connection, including the connection IP address, port number, and database name (which can be the full name of the path) and the connection username and password. The following code:

Var options ={}; options. host = '2017. 0.0.1 '; // set the host address options. port = 3050; // port number options. database = '/home/user/test. fdb'; // database name options. user = 'sysdba '; // user name options. password = 'masterkey'; // password

In this way, the database connection settings are complete.

Escape

In the node-firebird module, there is a method named escape whose return value is of the String type. This method can prevent SQL injection. The following code:

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

Example:

var FireBird = require('node-firebird');var sql1 = 'SELECT * FROM a WHERE ID='+Firebird.escape(2) ;console.log(sql1);

Create

The create method is used to create a database. Its Syntax format is as follows:

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

The following code:

FireBird. create (options, function (err, db) {if (err) throw err; console. log ('database created successfully'); db. detach (); // closes the database connection });

Note: When a database exists, using this method to create a database will overwrite the original database, resulting in data loss.

Query

The usage of the db. query method has been described earlier. Here we will continue to explain the usage of db. query. When a query statement is a query statement, the returned result is an array of the object type (that is, the value of result ). We can use db. query () to add, modify, delete, and update Tables in the database. Db. query () can be used in either a query without parameters or a query with parameters.

Query with parameters:

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

The instance code is as follows:

FireBird.attach(options, function(err, db) {  if (err)    throw err;  // db = DATABASE  db.query('insert into a (id,name) values(?,?)',[1,'Tom'], function(err, result) {    if (err)      throw err;    console.log("insert success!");    db.detach();  });});

The instance code updates the data in Table:

FireBird.attach(options, function(err, db) {  if (err)  throw err;  // db = DATABASE  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 all the content of this article. It will teach you how to use Node. js to operate Firebird databases.

Articles you may be interested in:
  • Use nodejs to Access ActiveX objects.
  • Node. js Development Guide-Node. js connects to MySQL and performs database operations
  • Node. js instance for mongoDB operations
  • Example of operating mysql database in nodejs
  • Interaction between mongodb databases with amazing node. js Reading Notes
  • Node. js development-access Redis database tutorial
  • A Simple Method for reading and writing Redis databases in Node. js applications

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.