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 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 http://nodejs.org/ for more details.
Node.js is:
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 (www.cubrid.org). It features a complete callbacks and events models.
The official name of the driver is node-cubrid and the home is located on github: https://github.com/CUBRID/node-cubrid.
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:
These functions are intended mainly for private usage within the driver code; however, feel free to use them if you need such functionality.
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…! ☺