Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

CUBRID Node.js API Overview

The scope of this tutorial is to provide an introduction to node-cubrid, a CUBRID Node.js driver. We will show you where to get and how to install the driver, how to setup a connection and how to develop some simple database-enabled JavaScript code.


Node.js Overview

Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. See for more details.

Node.js is:

  • Evented Server-side JavaScript
  • Good at handling lots of different kinds of I/O at the same time.
  • Achieves this all by making almost all network and file I/O non-blocking.

node-cubrid – a CUBRID Node.js driver

CUBRID Node.js driver is an open-source project with the goal of implementing a 100% native node.js driver for the CUBRID database engine ( It features a complete callbacks and events models.

The official name of the driver is node-cubrid and the home is located on github:

Here is a summary of the main functions implemented in the node-cubrid driver:

Function name Scope
CUBRIDConnection(brokerServer, brokerPort, user, password, database, cacheTimeout) Initializes the driver module
connect(callback) Connect to a database
getEngineVersion(callback) Get database version
query(sql, callback) Executes a query which returns records
fetch(queryHandle, callback) Fetch more records from a query
closeQuery(queryHandle, callback) Close a query
queryWithParams(sql, arrParamsValues, callback) Executes a query which returns records, using parameters in the query SQL statement
batchExecuteNoQuery(sqlsArray, callback) Execute queries in batch mode
batchExecute(sqlsArray, callback) Execute a single SQL statement
batchExecuteWithParams(sqlsArray, arrParamsValues , callback) Execute a single SQL statement, with paramaters
beginTransaction(callback) Begin a transaction
setAutoCommitMode(autoCommitMode, callback) Set the auto-commit session mode
rollback(callback) Rollback a transaction
commit(callback) Commit a transaction
getSchema(schemaType, callback) Gets database schema information
close(callback) Disconnect from the database

Beside the functions listed above, there are other utility-related functions provided by the driver; for example:

  • src\utils\Helpers.js: provides various utilities, from code formatting to input parameters validation and logging.
  • src\utils\ActionQueue.js: provides support for executing functions in sequence and for a while-do loop.

These functions are intended mainly for private usage within the driver code; however, feel free to use them if you need such functionality.

Driver Event model

node-cubrid implements, in addition to the standard callbacks model functionality, a rich event model:

Event name Notes
EVENT_ERROR Raised when an error is encountered
EVENT_CONNECTED Raised when a connection was established
EVENT_ENGINE_VERSION_AVAILABLE Raised when the database version is returned to the client
EVENT_BATCH_COMMANDS_COMPLETED Raised when the commands batch execution is completed
EVENT_QUERY_DATA_AVAILABLE Raised when the data from the query is available to the client
EVENT_SCHEMA_DATA_AVAILABLE Raised when the database schema is available to the client
EVENT_FETCH_DATA_AVAILABLE Raised when more query data is available to the client through successive fetch command(s)
EVENT_FETCH_NO_MORE_DATA_AVAILABLE Raised when no more data is available from the query
EVENT_BEGIN_TRANSACTION Raised when a transaction was started
EVENT_SET_AUTOCOMMIT_MODE_COMPLETED Raised when auto-commit mode was set
EVENT_COMMIT_COMPLETED Raised when commit was completed
EVENT_ROLLBACK_COMPLETED Raised when rollback was completed
EVENT_QUERY_CLOSED Raised when the query was closed
EVENT_CONNECTION_CLOSED Raised when the connection to the database was closed

The logical chain between events, for a query, is described in the below diagram:


For more details about the events parameters, please consult the driver documentation, or look at the code examples and the tests included in the driver released code.

And, why not, look directly at the driver code…! ☺

comments powered by Disqus
Page info
viewed 6593 times
translations en
posted 3 years ago by
Esen Sagynov
updated 2 years ago by
View revisions
Share this article