Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cleanup

commit 019a55c0ea57e9108ecbf6fda14426c0810f5db9 1 parent cb67d6c
@koichik authored
View
1  .gitignore
@@ -1 +1,2 @@
/.idea
+/node_modules
View
6 README.md
@@ -62,7 +62,7 @@ for more information.
});
});
-## remove (delete)
+## delete
var hs = require('node-handlersocket');
@@ -70,7 +70,7 @@ for more information.
con.on('connect', function() {
con.openIndex('test', 'EMPLOYEE', 'PRIMARY', [ 'EMPLOYEE_ID', 'EMPLOYEE_NO',
'EMPLOYEE_NAME' ], function(err, index) {
- index.remove('=', 100, function(err, rows) {
+ index.delete('=', 100, function(err, rows) {
console.log(rows);
con.end();
});
@@ -192,7 +192,7 @@ To update a records.
* `err` : an `Error` object when the request failed, otherwise `null`.
* `rows` : a number of updated rows.
-### Method : Index.remove(op, keys, [ limit, [ offset ] ], callback)
+### Method : Index.delete(op, keys, [ limit, [ offset ] ], callback)
To delete a records.
View
2  doc-ja/api.md
@@ -120,7 +120,7 @@ MySQL 上のインデックスを表すオブジェクトです.
* `err` : 操作が成功した場合は `null`,失敗した場合は `Error` オブジェクトが渡されます.
* `results` : 更新した行数が渡されます.
-### Index.remove(op, keys, [limit, [offset]], callback)
+### Index.delete(op, keys, [limit, [offset]], callback)
インデックスを使用して行を更新します.
View
1  index.js
@@ -0,0 +1 @@
+module.exports = require('./lib/node-handlersocket');
View
231 lib/node-handlersocket.js
@@ -0,0 +1,231 @@
+var events = require('events')
+var net = require('net')
+var util = require('util');
+
+exports.connect = connect;
+
+function connect(options_) {
+ var options = options_ || {};
+ var host = options.host || 'localhost';
+ var port = options.port || 9998;
+ return new Connection(host, port);
+}
+
+function Connection(host, port) {
+ events.EventEmitter.call(this);
+ var self = this;
+ var socket = net.connect(port, host);
+ socket.setEncoding('utf8');
+ socket.on('connect', function() {
+ self.emit('connect');
+ });
+ socket.on('data', function(data) {
+ if (data) {
+ var received = self._received += data;
+ var pos;
+ while ((pos = received.indexOf('\n')) !== -1) {
+ var response = received.substring(0, pos + 1);
+ received = self._received = received.substring(pos + 1);
+ var callback = self._callbacks.shift();
+ callback(response);
+ }
+ }
+ });
+ socket.on('end', function(error) {
+ self._notifyError(error);
+ self.emit('close', error);
+ });
+ socket.on('close', function(hadError) {
+ self.emit('close', hadError);
+ });
+ socket.on('error', function(error) {
+ self._notifyError(error);
+ self.emit('error', error);
+ });
+
+ this._socket = socket;
+ this._indexId = 0;
+ this._callbacks = [];
+ this._received = '';
+}
+util.inherits(Connection, events.EventEmitter);
+
+Connection.prototype.openIndex =
+ function openIndex(database, table, index, columns, callback) {
+ columns = Array.isArray(columns) ? columns : [columns];
+
+ var self = this;
+ var indexId = this._indexId++;
+ var request = ['P', indexId, database, table, index, columns.join(',')];
+ this._execute(request, _handleResponse(function(err, fields) {
+ if (err) {
+ return callback(err);
+ }
+ return callback(null, new Index(self, indexId, columns.length));
+ }));
+};
+
+Connection.prototype.close = function close() {
+ this._socket.end();
+};
+
+Connection.prototype._execute = function _execute(request, callback) {
+ if (this._socket.readyState !== 'open') {
+ return callback(new Error('connection closed'));
+ }
+ var data = _createRequest(request);
+ this._socket.write(data, 'utf8');
+ this._callbacks.push(callback);
+};
+
+Connection.prototype._notifyError = function _notifyError(error) {
+ error = error || new Error('connection closed');
+ var callbacks = this._callbacks;
+ this._callback = [];
+ for (var i = 0, len = callbacks.length; i < len; ++i) {
+ callbacks[i](err);
+ }
+}
+
+function Index(con, indexId, columnCount) {
+ events.EventEmitter.call(this);
+ this._con = con;
+ this._indexId = indexId;
+ this._columnCount = columnCount;
+}
+util.inherits(Index, events.EventEmitter);
+
+Index.prototype.find = function find(operator, keys, limit, offset, callback) {
+ var argc = arguments.length;
+ callback = argc >= 5 ? callback : arguments[argc - 1];
+ offset = argc > 4 ? offset : 0;
+ limit = argc > 3 ? limit : 1;
+ keys = Array.isArray(keys) ? keys : [keys];
+
+ var request = [this._indexId, operator, keys.length].
+ concat(keys, [limit, offset]);
+ this._con._execute(request, _handleResponse(function(error, response) {
+ if (error) {
+ return callback(error);
+ }
+ var numColumns = parseInt(response[1]);
+ var results = [];
+ for (var i = 2, len = response.length; i < len; i += numColumns) {
+ results.push(response.slice(i, i + numColumns));
+ }
+ return callback(null, results);
+ }));
+};
+
+Index.prototype.insert = function insert(values, callback) {
+ values = Array.isArray(values) ? values : [values];
+
+ var request = [this._indexId, '+', values.length].concat(values);
+ this._con._execute(request, _handleResponse(function(error, response) {
+ if (error) {
+ return callback(error);
+ }
+ return callback(null);
+ }));
+};
+
+Index.prototype.update =
+ function update(operator, keys, limit, offset, values, callback) {
+ var argc = arguments.length;
+ callback = argc >= 6 ? callback : arguments[argc - 1];
+ values = argc >= 5 ? values : arguments[argc - 2];
+ values = Array.isArray(values) ? values : [values];
+ offset = argc > 5 ? offset : 0;
+ limit = argc > 4 ? limit : 1;
+ keys = Array.isArray(keys) ? keys : [keys];
+
+ var request = [this._indexId, operator, keys.length ].
+ concat(keys, [limit, offset, 'U'], values);
+ this._con._execute(request, _handleResponse(function(error, response) {
+ if (error) {
+ return callback(error);
+ }
+ var rows = parseInt(response[2]);
+ return callback(null, rows);
+ }));
+};
+
+Index.prototype.delete =
+ function remove(operator, keys, limit, offset, callback) {
+ var argc = arguments.length;
+ callback = argc >= 5 ? callback : arguments[argc - 1];
+ offset = argc > 4 ? offset : 0;
+ limit = argc > 3 ? limit : 1;
+ keys = Array.isArray(keys) ? keys : [keys];
+
+ var request = [this._indexId, operator, keys.length].
+ concat(keys, [limit, offset, 'D']);
+ this._con._execute(request, _handleResponse(function(error, response) {
+ if (error) {
+ return callback(error, response[2]);
+ }
+ var rows = parseInt(response[2]);
+ return callback(null, rows);
+ }));
+};
+
+function _createRequest(fields) {
+ var request = fields.map(function(field) {
+ return _encodeField(field);
+ }).join('\t') + '\n';
+ if (exports._debug) {
+ console.error(util.inspect(request));
+ }
+ return request;
+}
+
+function _handleResponse(callback) {
+ return function(response) {
+ if (exports._debug) {
+ console.error(util.inspect(response));
+ }
+ response = response.substring(0, response.length - 1);
+ var fields = response.split('\t').map(function(field) {
+ return _decodeField(field);
+ });
+ var error = fields[0];
+ if (error === '0') {
+ return callback(null, fields);
+ }
+ var message = fields[2];
+ return callback(new Error(message ? error + ' ' + message : error));
+ };
+}
+
+function _encodeField(field) {
+ if (field === undefined || field === null) {
+ return '\0';
+ }
+ if (field === '') {
+ return '';
+ }
+ if (typeof field !== 'string') {
+ field = field.toString();
+ }
+ return field.replace(/[\x00-\x0F]/g, function(ch) {
+ return String.fromCharCode(0x01, ch.charCodeAt(0) + 0x40);
+ });
+}
+
+function _decodeField(field) {
+ if (field === '\0') {
+ return null;
+ }
+ return field.replace(/\u0001[\x40-\x4F]/g, function(ch) {
+ return String.fromCharCode(ch.charCodeAt(1) - 0x40);
+ });
+}
+
+// for tests
+exports._debug = false;
+exports._createRequest = _createRequest;
+exports._handleResponse = _handleResponse;
+exports._encodeField = _encodeField;
+exports._decodeField = _decodeField;
+exports.Connection = Connection;
+exports.Index = Index;
View
224 node-handlersocket.js
@@ -1,224 +0,0 @@
-var events = require('events'), net = require('net'), util = require('util');
-
-exports.connect = connect;
-exports.Connection = Connection;
-exports.Index = Index;
-
-function connect(options_) {
- var options = options_ || {};
- var host = options.host || 'localhost';
- var port = options.port || 9998;
- return new Connection(host, port);
-}
-
-function Connection(host, port) {
- events.EventEmitter.call(this);
- var self = this;
- var stream = net.createConnection(port, host);
- stream.setEncoding('utf8');
- stream.on('connect', function() {
- self.emit('connect');
- });
- stream.on('data', function(data) {
- if (data) {
- var received = self._received += data;
- var pos;
- while ((pos = received.indexOf('\n')) !== -1) {
- var response = received.substring(0, pos + 1);
- received = self._received = received.substring(pos + 1);
- var callback = self._callbacks.shift();
- callback(response);
- }
- }
- });
- stream.on('end', function(exception) {
- self._notifyError(exception);
- self.emit('end', exception);
- });
- stream.on('close', function(hadError) {
- self.emit('close', hadError);
- });
- stream.on('error', function(exception) {
- self._notifyError(exception);
- self.emit('error', exception);
- });
- this._stream = stream;
- this._indexId = 0;
- this._callbacks = [];
- this._received = '';
-}
-util.inherits(Connection, events.EventEmitter);
-
-Connection.prototype.openIndex = function(database, table, index, columns_, callback) {
- var self = this;
- var columns = Array.isArray(columns_) ? columns_ : [ columns_ ];
- var indexId = self._indexId++;
- var request = [ 'P', indexId, database, table, index, columns.join(',') ];
- self._execute(request, _handleResponse(function(err, fields) {
- if (err) {
- return callback(err);
- }
- return callback(null, new Index(self, indexId, columns.length));
- }));
-};
-
-Connection.prototype.end = function() {
- this._stream.end();
-};
-
-Connection.prototype._execute = function(request, callback) {
- if (this._stream.readyState !== 'open') {
- return callback(new Error('connection closed'));
- }
- var data = _createRequest(request);
- this._stream.write(data, 'utf8');
- this._callbacks.push(callback);
-};
-
-Connection.prototype._notifyError = function(err_) {
- var err = err_ || new Error('connection closed');
- var callbacks = this._callbacks;
- this._callback = [];
- var len = callbacks.length;
- for (var i = 0; i < len; ++i) {
- callbacks[i](err);
- }
-}
-
-function Index(con, indexId, columnCount) {
- events.EventEmitter.call(this);
- this._con = con;
- this._indexId = indexId;
- this._columnCount = columnCount;
-}
-util.inherits(Index, events.EventEmitter);
-
-Index.prototype.find = function(operator, keys_, limit_, offset_, callback_) {
- var self = this;
- var argc = arguments.length;
- var keys = Array.isArray(keys_) ? keys_ : [ keys_ ];
- var limit = argc > 3 ? limit_ : 1;
- var offset = argc > 4 ? offset_ : 0;
- var callback = argc > 5 ? callback_ : arguments[argc - 1];
- var request = [ self._indexId, operator, keys.length ].concat(keys, [ limit, offset ]);
- self._con._execute(request, _handleResponse(function(err, response) {
- if (err) {
- return callback(err);
- }
- var len = response.length;
- var numColumns = parseInt(response[1]);
- var results = [];
- for (var i = 2; i < len; i += numColumns) {
- results.push(response.slice(i, i + numColumns));
- }
- return callback(null, results);
- }));
-};
-
-Index.prototype.insert = function(values_, callback) {
- var self = this;
- var values = Array.isArray(values_) ? values_ : [ values_ ];
- var request = [ self._indexId, '+', values.length ].concat(values);
- self._con._execute(request, _handleResponse(function(err, response) {
- if (err) {
- return callback(err);
- }
- return callback(null);
- }));
-};
-
-Index.prototype.update = function(operator, keys_, limit_, offset_, values_, callback_) {
- var self = this;
- var argc = arguments.length;
- var keys = Array.isArray(keys_) ? keys_ : [ keys_ ];
- var limit = argc > 4 ? limit_ : 1;
- var offset = argc > 5 ? offset_ : 0;
- var values = argc < 5 ? arguments[argc - 2] : values_;
- values = Array.isArray(values) ? values : [ values ];
- var callback = argc < 6 ? arguments[argc - 1] : callback_;
- var request = [ self._indexId, operator, keys.length ].concat(keys, [ limit, offset,
- 'U' ], values);
- self._con._execute(request, _handleResponse(function(err, response) {
- if (err) {
- return callback(err);
- }
- var rows = parseInt(response[2]);
- return callback(null, rows);
- }));
-};
-
-Index.prototype.remove = function(operator, keys_, limit_, offset_, callback_) {
- var self = this;
- var argc = arguments.length;
- var keys = Array.isArray(keys_) ? keys_ : [ keys_ ];
- var limit = argc > 3 ? limit_ : 1;
- var offset = argc > 4 ? offset_ : 0;
- var callback = argc < 5 ? arguments[argc - 1] : callback_;
- var request = [ self._indexId, operator, keys.length ].concat(keys, [ limit, offset, 'D' ]);
- self._con._execute(request, _handleResponse(function(err, response) {
- if (err) {
- return callback(err, response[2]);
- }
- var rows = parseInt(response[2]);
- return callback(null, rows);
- }));
-};
-
-function _createRequest(fields) {
- var request = fields.map(function(field) {
- return _encodeField(field);
- }).join('\t');
- if (exports._debug) {
- util.debug(util.inspect(request));
- }
- return request + '\n';
-}
-
-function _handleResponse(callback) {
- return function(response) {
- if (exports._debug) {
- util.debug(util.inspect(response));
- }
- var fields = [];
- response.substring(0, response.length - 1).split('\t').forEach(function(field) {
- fields.push(_decodeField(field));
- });
- var err = fields[0];
- if (err === '0') {
- return callback(null, fields);
- }
- var message = fields[2];
- return callback(new Error(message ? err + ' ' + message : err));
- };
-}
-
-function _encodeField(field) {
- if (field === undefined || field === null) {
- return '\0';
- }
- if (field === '') {
- return '';
- }
- if (typeof field !== 'string') {
- field = field.toString();
- }
- return field.replace(/[\x00-\x0F]/g, function(ch) {
- return String.fromCharCode(0x01, ch.charCodeAt(0) + 0x40);
- });
-}
-
-function _decodeField(field) {
- if (field === '\0') {
- return null;
- }
- return field.replace(/\u0001[\x40-\x4F]/g, function(ch) {
- return String.fromCharCode(ch.charCodeAt(1) - 0x40);
- });
-}
-
-// for tests
-exports._debug = false;
-exports._createRequest = _createRequest;
-exports._handleResponse = _handleResponse;
-exports._encodeField = _encodeField;
-exports._decodeField = _decodeField;
View
198 sql/create.sql
@@ -1,28 +1,176 @@
-CREATE TABLE DEPARTMENT(DEPARTMENT_ID INTEGER NOT NULL PRIMARY KEY, DEPARTMENT_NO INTEGER NOT NULL UNIQUE,DEPARTMENT_NAME VARCHAR(20),LOCATION VARCHAR(20) DEFAULT 'TOKYO', VERSION INTEGER);
-CREATE TABLE ADDRESS(ADDRESS_ID INTEGER NOT NULL PRIMARY KEY, STREET VARCHAR(20), VERSION INTEGER);
-CREATE TABLE EMPLOYEE(EMPLOYEE_ID INTEGER NOT NULL PRIMARY KEY, EMPLOYEE_NO INTEGER NOT NULL ,EMPLOYEE_NAME VARCHAR(20),MANAGER_ID INTEGER,HIREDATE DATE,SALARY NUMERIC(7,2),DEPARTMENT_ID INTEGER,ADDRESS_ID INTEGER, VERSION INTEGER, CONSTRAINT FK_DEPARTMENT_ID FOREIGN KEY(DEPARTMENT_ID) REFERENCES DEPARTMENT(DEPARTMENT_ID),CONSTRAINT FK_ADDRESS_ID FOREIGN KEY(ADDRESS_ID) REFERENCES ADDRESS(ADDRESS_ID));
-
-CREATE TABLE COMP_KEY_DEPARTMENT(DEPARTMENT_ID1 INTEGER NOT NULL, DEPARTMENT_ID2 INTEGER NOT NULL, DEPARTMENT_NO INTEGER NOT NULL UNIQUE,DEPARTMENT_NAME VARCHAR(20),LOCATION VARCHAR(20) DEFAULT 'TOKYO', VERSION INTEGER, CONSTRAINT PK_COMP_KEY_DEPARTMENT PRIMARY KEY(DEPARTMENT_ID1, DEPARTMENT_ID2));
-CREATE TABLE COMP_KEY_ADDRESS(ADDRESS_ID1 INTEGER NOT NULL, ADDRESS_ID2 INTEGER NOT NULL, STREET VARCHAR(20), VERSION INTEGER, CONSTRAINT PK_COMP_KEY_ADDRESS PRIMARY KEY(ADDRESS_ID1, ADDRESS_ID2));
-CREATE TABLE COMP_KEY_EMPLOYEE(EMPLOYEE_ID1 INTEGER NOT NULL, EMPLOYEE_ID2 INTEGER NOT NULL, EMPLOYEE_NO INTEGER NOT NULL ,EMPLOYEE_NAME VARCHAR(20),MANAGER_ID1 INTEGER,MANAGER_ID2 INTEGER,HIREDATE DATE,SALARY NUMERIC(7,2),DEPARTMENT_ID1 INTEGER,DEPARTMENT_ID2 INTEGER,ADDRESS_ID1 INTEGER,ADDRESS_ID2 INTEGER,VERSION INTEGER, CONSTRAINT PK_COMP_KEY_EMPLOYEE PRIMARY KEY(EMPLOYEE_ID1, EMPLOYEE_ID2), CONSTRAINT FK_COMP_KEY_DEPARTMENT_ID FOREIGN KEY(DEPARTMENT_ID1, DEPARTMENT_ID2) REFERENCES COMP_KEY_DEPARTMENT(DEPARTMENT_ID1, DEPARTMENT_ID2), CONSTRAINT FK_COMP_KEY_ADDRESS_ID FOREIGN KEY(ADDRESS_ID1, ADDRESS_ID2) REFERENCES COMP_KEY_ADDRESS(ADDRESS_ID1, ADDRESS_ID2));
-
-CREATE TABLE LARGE_OBJECT(ID NUMERIC(8) NOT NULL PRIMARY KEY, NAME VARCHAR(20), LARGE_NAME TEXT, BYTES VARBINARY(2000), LARGE_BYTES BLOB, DTO VARBINARY(2000), LARGE_DTO BLOB);
-CREATE TABLE TENSE (ID INTEGER PRIMARY KEY,DATE_DATE DATE, DATE_TIME TIME, DATE_TIMESTAMP DATETIME, CAL_DATE DATE, CAL_TIME TIME, CAL_TIMESTAMP DATETIME, SQL_DATE DATE, SQL_TIME TIME, SQL_TIMESTAMP DATETIME);
-CREATE TABLE JOB (ID INTEGER NOT NULL PRIMARY KEY, JOB_TYPE VARCHAR(20));
-CREATE TABLE AUTHORITY (ID INTEGER NOT NULL PRIMARY KEY, AUTHORITY_TYPE INTEGER);
-CREATE TABLE NO_ID (VALUE1 INTEGER, VALUE2 INTEGER);
-CREATE TABLE OWNER_OF_NO_ID (ID INTEGER NOT NULL PRIMARY KEY, NO_ID_VALUE1 INTEGER);
-CREATE TABLE CONSTRAINT_CHECKING (PRIMARY_KEY INTEGER PRIMARY KEY, UNIQUE_KEY INTEGER UNIQUE, FOREIGN_KEY INTEGER, CHECK_CONSTRAINT INTEGER, NOT_NULL INTEGER NOT NULL, CONSTRAINT CK_CONSTRAINT_CHECKING_1 CHECK (CHECK_CONSTRAINT > 0), CONSTRAINT FK_JOB_ID FOREIGN KEY (FOREIGN_KEY) REFERENCES JOB (ID));
-CREATE TABLE PATTERN (VALUE VARCHAR(10));
-
-CREATE TABLE ID_GENERATOR(PK VARCHAR(20) NOT NULL PRIMARY KEY, VALUE INTEGER NOT NULL);
-CREATE TABLE MY_ID_GENERATOR(MY_PK VARCHAR(20) NOT NULL PRIMARY KEY, MY_VALUE INTEGER NOT NULL);
-CREATE TABLE AUTO_STRATEGY(ID INTEGER AUTO_INCREMENT PRIMARY KEY, VALUE VARCHAR(10));
-CREATE TABLE IDENTITY_STRATEGY(ID INTEGER AUTO_INCREMENT PRIMARY KEY, VALUE VARCHAR(10));
-CREATE TABLE SEQUENCE_STRATEGY(ID INTEGER NOT NULL PRIMARY KEY, VALUE VARCHAR(10));
-CREATE TABLE SEQUENCE_STRATEGY2(ID INTEGER NOT NULL PRIMARY KEY, VALUE VARCHAR(10));
-CREATE TABLE TABLE_STRATEGY(ID INTEGER NOT NULL PRIMARY KEY, VALUE VARCHAR(10));
-CREATE TABLE TABLE_STRATEGY2(ID INTEGER NOT NULL PRIMARY KEY, VALUE VARCHAR(10));
+CREATE TABLE DEPARTMENT(
+ DEPARTMENT_ID INTEGER NOT NULL PRIMARY KEY
+, DEPARTMENT_NO INTEGER NOT NULL UNIQUE
+, DEPARTMENT_NAME VARCHAR(20)
+, LOCATION VARCHAR(20) DEFAULT 'TOKYO'
+, VERSION INTEGER
+);
+
+CREATE TABLE ADDRESS(
+ ADDRESS_ID INTEGER NOT NULL PRIMARY KEY
+, STREET VARCHAR(20)
+, VERSION INTEGER
+);
+
+CREATE TABLE EMPLOYEE(
+ EMPLOYEE_ID INTEGER NOT NULL PRIMARY KEY
+, EMPLOYEE_NO INTEGER NOT NULL UNIQUE
+, EMPLOYEE_NAME VARCHAR(20)
+, MANAGER_ID INTEGER
+, HIREDATE DATE
+, SALARY NUMERIC(7,2)
+, DEPARTMENT_ID INTEGER
+, ADDRESS_ID INTEGER
+, VERSION INTEGER
+/*
+, CONSTRAINT FK_DEPARTMENT_ID
+ FOREIGN KEY(DEPARTMENT_ID)
+ REFERENCES DEPARTMENT(DEPARTMENT_ID)
+, CONSTRAINT FK_ADDRESS_ID
+ FOREIGN KEY(ADDRESS_ID)
+ REFERENCES ADDRESS(ADDRESS_ID)
+*/
+);
+
+CREATE TABLE COMP_KEY_DEPARTMENT(
+ DEPARTMENT_ID1 INTEGER NOT NULL
+, DEPARTMENT_ID2 INTEGER NOT NULL
+, DEPARTMENT_NO INTEGER NOT NULL UNIQUE
+, DEPARTMENT_NAME VARCHAR(20)
+, LOCATION VARCHAR(20) DEFAULT 'TOKYO'
+, VERSION INTEGER
+, CONSTRAINT PK_COMP_KEY_DEPARTMENT
+ PRIMARY KEY(DEPARTMENT_ID1, DEPARTMENT_ID2)
+);
+
+CREATE TABLE COMP_KEY_ADDRESS(
+ ADDRESS_ID1 INTEGER NOT NULL
+, ADDRESS_ID2 INTEGER NOT NULL
+, STREET VARCHAR(20)
+, VERSION INTEGER
+, CONSTRAINT PK_COMP_KEY_ADDRESS PRIMARY KEY(ADDRESS_ID1, ADDRESS_ID2)
+);
+
+CREATE TABLE COMP_KEY_EMPLOYEE(
+ EMPLOYEE_ID1 INTEGER NOT NULL
+, EMPLOYEE_ID2 INTEGER NOT NULL
+, EMPLOYEE_NO INTEGER NOT NULL
+, EMPLOYEE_NAME VARCHAR(20)
+, MANAGER_ID1 INTEGER
+, MANAGER_ID2 INTEGER
+, HIREDATE DATE
+, SALARY NUMERIC(7,2)
+, DEPARTMENT_ID1 INTEGER
+, DEPARTMENT_ID2 INTEGER
+, ADDRESS_ID1 INTEGER
+, ADDRESS_ID2 INTEGER
+, VERSION INTEGER
+, CONSTRAINT PK_COMP_KEY_EMPLOYEE
+ PRIMARY KEY(EMPLOYEE_ID1, EMPLOYEE_ID2)
+, CONSTRAINT FK_COMP_KEY_DEPARTMENT_ID
+ FOREIGN KEY(DEPARTMENT_ID1, DEPARTMENT_ID2)
+ REFERENCES COMP_KEY_DEPARTMENT(DEPARTMENT_ID1, DEPARTMENT_ID2)
+, CONSTRAINT FK_COMP_KEY_ADDRESS_ID
+ FOREIGN KEY(ADDRESS_ID1, ADDRESS_ID2)
+ REFERENCES COMP_KEY_ADDRESS(ADDRESS_ID1, ADDRESS_ID2)
+);
+
+CREATE TABLE LARGE_OBJECT(
+ ID NUMERIC(8) NOT NULL PRIMARY KEY
+, NAME VARCHAR(20)
+, LARGE_NAME TEXT
+, BYTES VARBINARY(2000)
+, LARGE_BYTES BLOB
+, DTO VARBINARY(2000)
+, LARGE_DTO BLOB
+);
+
+CREATE TABLE TENSE (
+ ID INTEGER PRIMARY KEY
+, DATE_DATE DATE
+, DATE_TIME TIME
+, DATE_TIMESTAMP DATETIME
+, CAL_DATE DATE
+, CAL_TIME TIME
+, CAL_TIMESTAMP DATETIME
+, SQL_DATE DATE
+, SQL_TIME TIME
+, SQL_TIMESTAMP DATETIME
+);
+
+CREATE TABLE JOB (
+ ID INTEGER NOT NULL PRIMARY KEY
+, JOB_TYPE VARCHAR(20)
+);
+
+CREATE TABLE AUTHORITY (
+ ID INTEGER NOT NULL PRIMARY KEY
+, AUTHORITY_TYPE INTEGER
+);
+
+CREATE TABLE NO_ID (
+ VALUE1 INTEGER
+, VALUE2 INTEGER
+);
+
+CREATE TABLE OWNER_OF_NO_ID (
+ ID INTEGER NOT NULL PRIMARY KEY
+, NO_ID_VALUE1 INTEGER
+);
+
+CREATE TABLE CONSTRAINT_CHECKING (
+ PRIMARY_KEY INTEGER PRIMARY KEY
+, UNIQUE_KEY INTEGER UNIQUE
+, FOREIGN_KEY INTEGER
+, CHECK_CONSTRAINT INTEGER
+, NOT_NULL INTEGER NOT NULL
+, CONSTRAINT CK_CONSTRAINT_CHECKING_1 CHECK (CHECK_CONSTRAINT > 0)
+, CONSTRAINT FK_JOB_ID FOREIGN KEY (FOREIGN_KEY) REFERENCES JOB (ID)
+);
+
+CREATE TABLE PATTERN (
+ VALUE VARCHAR(10)
+);
+
+CREATE TABLE ID_GENERATOR(
+ PK VARCHAR(20) NOT NULL PRIMARY KEY
+, VALUE INTEGER NOT NULL
+);
+
+CREATE TABLE MY_ID_GENERATOR(
+ MY_PK VARCHAR(20) NOT NULL PRIMARY KEY
+, MY_VALUE INTEGER NOT NULL
+);
+
+CREATE TABLE AUTO_STRATEGY(
+ ID INTEGER AUTO_INCREMENT PRIMARY KEY
+, VALUE VARCHAR(10)
+);
+
+CREATE TABLE IDENTITY_STRATEGY(
+ ID INTEGER AUTO_INCREMENT PRIMARY KEY
+, VALUE VARCHAR(10)
+);
+
+CREATE TABLE SEQUENCE_STRATEGY(
+ ID INTEGER NOT NULL PRIMARY KEY
+, VALUE VARCHAR(10)
+);
+
+CREATE TABLE SEQUENCE_STRATEGY2(
+ ID INTEGER NOT NULL PRIMARY KEY
+, VALUE VARCHAR(10)
+);
+
+CREATE TABLE TABLE_STRATEGY(
+ ID INTEGER NOT NULL PRIMARY KEY
+, VALUE VARCHAR(10)
+);
+
+CREATE TABLE TABLE_STRATEGY2(
+ ID INTEGER NOT NULL PRIMARY KEY
+, VALUE VARCHAR(10)
+);
INSERT INTO DEPARTMENT VALUES(1,10,'ACCOUNTING','NEW YORK',1);
INSERT INTO DEPARTMENT VALUES(2,20,'RESEARCH','DALLAS',1);
View
8 test/connect-test.js
@@ -1,5 +1,7 @@
-var vows = require('vows'), assert = require('assert'), events = require('events'),
- hs = require('../lib/node-handlersocket');
+var vows = require('vows');
+var assert = require('assert');
+var events = require('events');
+var hs = require('../index');
vows.describe('Connect').addBatch({
'connecting' : {
@@ -9,7 +11,7 @@ vows.describe('Connect').addBatch({
var con = hs.connect(options);
con.on('connect', function() {
emitter.emit('success', con);
- con.end();
+ con.close();
});
con.on('error', function(err) {
emitter.emit('success', err);
View
25 test/find-test.js
@@ -1,5 +1,8 @@
-var vows = require('vows'), assert = require('assert'), events = require('events'), util = require('util'),
- hs = require('../lib/node-handlersocket');
+var vows = require('vows');
+var assert = require('assert');
+var events = require('events');
+var util = require('util');
+var hs = require('../index');
//hs._debug = true;
var con;
@@ -15,8 +18,9 @@ vows.describe('Find').addBatch({
},
'openIndex =>' : {
topic : function(con) {
- con.openIndex('test', 'EMPLOYEE', 'PRIMARY', [ 'EMPLOYEE_ID', 'EMPLOYEE_NO',
- 'EMPLOYEE_NAME' ], this.callback);
+ con.openIndex('test', 'EMPLOYEE', 'PRIMARY',
+ ['EMPLOYEE_ID', 'EMPLOYEE_NO', 'EMPLOYEE_NAME'],
+ this.callback);
},
'find one record with = operator' : {
topic : function(index, con) {
@@ -26,13 +30,10 @@ vows.describe('Find').addBatch({
assert.isNull(err);
},
'should pass an array with 1 record' : function(err, results) {
- assert.length(results, 1);
+ assert.lengthOf(results, 1);
},
'should results equal to' : function(err, results) {
assert.deepEqual(results[0], [ '1', '7369', 'SMITH' ]);
- },
- 'after' : function(err, index) {
- con.end();
}
},
'find some records with < operator' : {
@@ -43,16 +44,16 @@ vows.describe('Find').addBatch({
assert.isNull(err);
},
'should pass an array with 2 records' : function(err, results) {
- assert.length(results, 2);
+ assert.lengthOf(results, 2);
},
'should results equal to' : function(err, results) {
assert.deepEqual(results[0], [ '2', '7499', 'ALLEN' ]);
assert.deepEqual(results[1], [ '1', '7369', 'SMITH' ]);
- },
- 'after' : function(err, index) {
- con.end();
}
}
+ },
+ teardown : function(con) {
+ con.close();
}
}
}).export(module);
View
56 test/modify-test.js
@@ -1,17 +1,22 @@
-var vows = require('vows'), assert = require('assert'), events = require('events'), util = require('util'),
- hs = require('../lib/node-handlersocket');
+var vows = require('vows');
+var assert = require('assert');
+var events = require('events');
+var util = require('util');
+var hs = require('../index');
-//hs._debug = true;
+hs._debug = false;
var con;
function openIndex(port, callback) {
con = hs.connect({'port': port});
con.on('connect', function() {
- con.openIndex('test', 'EMPLOYEE', 'PRIMARY', [ 'EMPLOYEE_ID', 'EMPLOYEE_NO',
- 'EMPLOYEE_NAME' ], callback);
+ con.openIndex('test', 'EMPLOYEE', 'PRIMARY',
+ ['EMPLOYEE_ID', 'EMPLOYEE_NO', 'EMPLOYEE_NAME'],
+ callback);
});
}
function find(callback) {
openIndex(9998, function(err, index) {
+ if (err) return callback(err);
index.find('=', [ 100 ], callback);
});
}
@@ -23,9 +28,11 @@ suite.addBatch({
find(this.callback);
},
'should pass an empty array' : function(err, results) {
- con.end();
assert.isNull(err);
- assert.length(results, 0);
+ assert.lengthOf(results, 0);
+ },
+ teardown : function() {
+ con.close();
}
}
});
@@ -34,11 +41,14 @@ suite.addBatch({
topic : function() {
var self = this;
openIndex(9999, function(err, index) {
+ if (err) return self.callback(err);
index.insert([ '100', '9999', 'KOICHIK' ], self.callback);
})
},
'should not be error' : function() {
- con.end();
+ },
+ teardown : function() {
+ con.close();
}
}
});
@@ -48,10 +58,12 @@ suite.addBatch({
find(this.callback);
},
'should pass an array which contains one record' : function(err, results) {
- con.end();
assert.isNull(err);
- assert.length(results, 1);
+ assert.lengthOf(results, 1);
assert.deepEqual(results[0], [ '100', '9999', 'KOICHIK' ]);
+ },
+ teardown : function() {
+ con.close();
}
}
});
@@ -60,13 +72,16 @@ suite.addBatch({
topic : function() {
var self = this;
openIndex(9999, function(err, index) {
+ if (err) return self.callback(err);
index.update('=', [100], [ '100', '9999', 'EBIYURI' ], self.callback);
})
},
'should update one row' : function(err, rows) {
- con.end();
assert.isNull(err);
assert.equal(rows, 1);
+ },
+ teardown : function() {
+ con.close();
}
}
});
@@ -76,10 +91,12 @@ suite.addBatch({
find(this.callback);
},
'should pass an array which contains one record' : function(err, results) {
- con.end();
assert.isNull(err);
- assert.length(results, 1);
+ assert.lengthOf(results, 1);
assert.deepEqual(results[0], [ '100', '9999', 'EBIYURI' ]);
+ },
+ teardown : function() {
+ con.close();
}
}
});
@@ -88,13 +105,16 @@ suite.addBatch({
topic : function() {
var self = this;
openIndex(9999, function(err, index) {
- index.remove('=', [100], self.callback);
+ if (err) return self.callback(err);
+ index.delete('=', [100], self.callback);
})
},
'should delete one row' : function(err, rows) {
- con.end();
assert.isNull(err);
assert.equal(rows, 1);
+ },
+ teardown : function() {
+ con.close();
}
}
});
@@ -104,9 +124,11 @@ suite.addBatch({
find(this.callback);
},
'should pass an empty array' : function(err, results) {
- con.end();
assert.isNull(err);
- assert.length(results, 0);
+ assert.lengthOf(results, 0);
+ },
+ teardown : function() {
+ con.close();
}
}
});
View
13 test/open-index-test.js
@@ -1,5 +1,8 @@
-var vows = require('vows'), assert = require('assert'), events = require('events'), util = require('util'),
- hs = require('../lib/node-handlersocket');
+var vows = require('vows');
+var assert = require('assert');
+var events = require('events');
+var util = require('util');
+var hs = require('../index');
//hs._debug = true;
var con;
@@ -26,10 +29,10 @@ vows.describe('OpenIndex').addBatch({
},
'shoud have 3 columns' : function(err, index) {
assert.equal(index._columnCount, 3);
- },
- 'after' : function(err, index) {
- con.end();
}
+ },
+ teardown : function(con) {
+ con.close();
}
}
}).export(module);
View
4 test/util-test.js
@@ -1,4 +1,6 @@
-var vows = require('vows'), assert = require('assert'), hs = require('../lib/node-handlersocket');
+var vows = require('vows');
+var assert = require('assert');
+var hs = require('../index');
vows.describe('Utilities').addBatch({
'encodeField' : {
Please sign in to comment.
Something went wrong with that request. Please try again.