node-handlersocket is a pure JavaScript client for HandlerSocket.
HandlerSocket is a NoSQL plugin for MySQL. See auther's blog for more information.
- Node.js (> 0.3.0, tested with 0.3.1)
- HandlerSocket (tested with v1.0.6)
npm install node-handlersocket
var hs = require('node-handlersocket');
var con = hs.connect();
con.on('connect', function() {
con.openIndex('test', 'EMPLOYEE', 'PRIMARY', [ 'EMPLOYEE_ID', 'EMPLOYEE_NO', 'EMPLOYEE_NAME' ],
function(err, index) {
index.find('=', 1, function(err, results) {
console.log(results[0]);
con.end();
});
});
});
var hs = require('node-handlersocket');
var con = hs.connect({port : 9999});
con.on('connect', function() {
con.openIndex('test', 'EMPLOYEE', 'PRIMARY', [ 'EMPLOYEE_ID', 'EMPLOYEE_NO',
'EMPLOYEE_NAME' ], function(err, index) {
index.insert([100, 9999, 'KOICHIK'], function(err) {
con.end();
});
});
});
var hs = require('node-handlersocket');
var con = hs.connect({port : 9999});
con.on('connect', function() {
con.openIndex('test', 'EMPLOYEE', 'PRIMARY', [ 'EMPLOYEE_ID', 'EMPLOYEE_NO',
'EMPLOYEE_NAME' ], function(err, index) {
index.update('=', 100, [100, 9999, 'EBIYURI'], function(err, rows) {
console.log(rows);
con.end();
});
});
});
var hs = require('node-handlersocket');
var con = hs.connect({port : 9999});
con.on('connect', function() {
con.openIndex('test', 'EMPLOYEE', 'PRIMARY', [ 'EMPLOYEE_ID', 'EMPLOYEE_NO',
'EMPLOYEE_NAME' ], function(err, index) {
index.remove('=', 100, function(err, rows) {
console.log(rows);
con.end();
});
});
});
Open a connection to HandlerSocket server.
- Parameters
-
options(optional) : an object with the following properties:host: a host name or address (default is'localhost').port: a port number (default is9998).
Note, the port 9998 only allows read operations, and the port 9999 allows write operations also. See HandlerSocket installation document for more information.
-
- Returns
- a new
Connectionobject.
- a new
An object representing connection to HandlerSocket.
It is an instance of EventEmitter.
Emitted when a connection is established.
- Callback function:
function()
Emitted when the other end of the stream sends a FIN packet.
- Callback function:
function()
Emitted once the connection is fully closed.
- Callback function:
function(hadError)- Parameters
hadError:trueif the stream was closed due to a transmission error.
- Parameters
Emitted when an error occurs.
- Callback function:
function(err)- Parameters
err: an error that occurred.
- Parameters
Open an index.
- Parameters
database: a database name.table: a table name.index: an index name. If 'PRIMARY' is specified, the primary index is open.columns: an array of columns names.callback: a function to be called when the response received.
- Callback function :
function(err, index)- Parameters
err: anErrorobject when the request failed, otherwisenull.index: a newIndexobject.
- Parameters
Half-closes the connection.
An object representing MySQL's index.
To read a records from a table using the index.
- Parameters
op: a search operation, one of'=','>','>=','<'and'<='.keys: an array of index values.limit(optional) : a maximum number of records to be retrieved (default is 1).offset(optional) : a number of records skipped before retrieving records (default is 0).callback: a function to be called when the response received.
- Callback Function :
function(err, results)- Parameters
err: anErrorobject when the request failed, otherwisenull.results: an array of records. Each recored is array of column values which correspond tocolumnsparameter ofConnection.openIndex().
- Parameters
To add a records.
- Parametes
- values : an array of new column values which correspond to
columnsparameter ofConnection.openIndex(). callback: a function to be called when the response received.
- values : an array of new column values which correspond to
- Callback Function :
function(err)- Parameters
err: anErrorobject when the request failed, otherwisenull.
- Parameters
To update a records.
- Parametes
op: a search operation, one of'=','>','>=','<'and'<='.keys: an array of index values.limit(optional) : a maximum number of records to be retrieved (default is 1).offset(optional) : a number of records skipped before retrieving records (default is 0).- values : an array of new column values which correspond to
columnsparameter ofConnection.openIndex(). callback: a function to be called when the response received.
- Callback Function :
function(err, rows)- Parameters
err: anErrorobject when the request failed, otherwisenull.rows: a number of updated rows.
- Parameters
To delete a records.
- Parametes
op: a search operation, one of'=','>','>=','<'and'<='.keys: an array of index values.limit(optional) : a maximum number of records to be retrieved (default is 1).offset(optional) : a number of records skipped before retrieving records (default is 0).callback: a function to be called when the response received.
- Callback Function :
function(err, rows)- Parameters
err: anErrorobject when the request failed, otherwisenull.rows: a number of deleted rows.
- Parameters
node-handlersocket depends on Vows for testing.
mysql -u root -p test < sql/create.sql
vows test/*.js
mysql -u root -p test < sql/drop.sql
The encoding of MySQL server (default-character-set parameter in [mysqld] section)
which node-handlersocket supports is only UTF-8.
Binary data types are not supported.
node-handlersocket is licensed under the MIT license.