Merge pull request #580 from llambda/master

Support strong-oracle driver.
This commit is contained in:
Tim Griesser 2014-12-18 23:52:57 -05:00
commit 5e0bcb1ea9
6 changed files with 89 additions and 33 deletions

View File

@ -11,6 +11,7 @@ var jshint = require('gulp-jshint');
var excluded = { var excluded = {
oracle: ['oracle'], oracle: ['oracle'],
"strong-oracle": ['strong-oracle'],
mariasql: ['mariasql'], mariasql: ['mariasql'],
sqlite3: ['sqlite3'], sqlite3: ['sqlite3'],
mysql: ['mysql'], mysql: ['mysql'],
@ -21,6 +22,7 @@ var excluded = {
var bases = { var bases = {
oracle: './lib/dialects/oracle', oracle: './lib/dialects/oracle',
"strong-oracle": './lib/dialects/strong-oracle',
mariasql: './lib/dialects/maria', mariasql: './lib/dialects/maria',
mysql: './lib/dialects/mysql', mysql: './lib/dialects/mysql',
mysql2: './lib/dialects/mysql2', mysql2: './lib/dialects/mysql2',

View File

@ -31,6 +31,7 @@ var maria = function() { return require('./lib/dialects/maria'); };
var oracle = function() { return require('./lib/dialects/oracle'); }; var oracle = function() { return require('./lib/dialects/oracle'); };
var pg = function() { return require('./lib/dialects/postgres'); }; var pg = function() { return require('./lib/dialects/postgres'); };
var sqlite3 = function() { return require('./lib/dialects/sqlite3'); }; var sqlite3 = function() { return require('./lib/dialects/sqlite3'); };
var strong_oracle = function() { return require('./lib/dialects/strong-oracle'); };
var websql = function() { return require('./lib/dialects/websql'); }; var websql = function() { return require('./lib/dialects/websql'); };
// The client names we'll allow in the `{name: lib}` pairing. // The client names we'll allow in the `{name: lib}` pairing.
@ -46,6 +47,7 @@ var Clients = Knex.Clients = {
'postgresql' : pg, 'postgresql' : pg,
'sqlite' : sqlite3, 'sqlite' : sqlite3,
'sqlite3' : sqlite3, 'sqlite3' : sqlite3,
'strong-oracle': strong_oracle,
'websql' : websql 'websql' : websql
}; };

View File

@ -3,9 +3,9 @@
// Oracle Client // Oracle Client
// ------- // -------
var inherits = require('inherits'); var inherits = require('inherits');
var _ = require('lodash'); var _ = require('lodash');
var Client = require('../../client'); var Client = require('../../client');
var Promise = require('../../promise'); var Promise = require('../../promise');
var oracle; var oracle;
@ -31,7 +31,8 @@ Client_Oracle.prototype.dialect = 'oracle';
// Lazy-load the oracle dependency, since we might just be // Lazy-load the oracle dependency, since we might just be
// using the client to generate SQL strings. // using the client to generate SQL strings.
Client_Oracle.prototype.initDriver = function() { Client_Oracle.prototype.initDriver = function() {
oracle = oracle || require('oracle'); Client_Oracle.prototype.driver = Client_Oracle.prototype.driver || require(
'oracle');
}; };
// Attach a `Formatter` constructor to the client object. // Attach a `Formatter` constructor to the client object.
@ -90,10 +91,15 @@ Client_Oracle.prototype.initSeeder = function() {
Client_Oracle.prototype.acquireRawConnection = function() { Client_Oracle.prototype.acquireRawConnection = function() {
var self = this; var self = this;
return new Promise(function(resolver, rejecter) { return new Promise(function(resolver, rejecter) {
oracle.connect(self.connectionSettings, function(err, connection) { self.driver.connect(self.connectionSettings,
if (err) return rejecter(err); function(err,
resolver(connection); connection) {
}); if (err) return rejecter(err);
if (self.connectionSettings.prefetchRowCount) {
connection.setPrefetchRowCount(self.connectionSettings.prefetchRowCount);
}
resolver(connection);
});
}); });
}; };
@ -120,13 +126,13 @@ Client_Oracle.prototype.positionBindings = function(sql) {
var ReturningHelper = require('./utils').ReturningHelper; var ReturningHelper = require('./utils').ReturningHelper;
Client_Oracle.prototype.preprocessBindings = function (bindings) { Client_Oracle.prototype.preprocessBindings = function(bindings) {
if (!bindings) { if (!bindings) {
return bindings; return bindings;
} }
return bindings.map(function (binding) { return bindings.map(function(binding) {
if (binding instanceof ReturningHelper && oracle) { if (binding instanceof ReturningHelper && oracle) {
// returning helper uses always ROWID as string // returning helper uses always ROWID as string
return new oracle.OutParam(oracle.OCCISTRING); return new oracle.OutParam(oracle.OCCISTRING);

View File

@ -7,36 +7,58 @@ var Readable = require('stream').Readable;
var _ = require('lodash'); var _ = require('lodash');
function OracleQueryStream(connection, sql, bindings, options) { function OracleQueryStream(connection, sql, bindings, options) {
try { try {
Readable.call(this, _.merge({}, { Readable.call(this, _.merge({}, {
objectMode: true, objectMode: true,
highWaterMark: 1000 highWaterMark: 1000
}, options)); }, options));
this.oracleReader = connection.reader(sql, bindings || []); this.oracleReader = connection.reader(sql, bindings || []);
} catch (err) { } catch (err) {
throw err; throw err;
} }
} }
inherits(OracleQueryStream, Readable); inherits(OracleQueryStream, Readable);
OracleQueryStream.prototype._read = function () { OracleQueryStream.prototype._read = function() {
var self = this; var self = this;
this.oracleReader.nextRow(function (err, row) { function pushNull() {
if (err) { process.nextTick(function() {
return self.emit('error', err); self.push(null);
}
if (!row) {
process.nextTick(function () {
self.push(null);
});
}
self.push(row);
}); });
}
try {
this.oracleReader.nextRows(function(err, rows) {
if (err) {
return self.emit('error', err);
}
if (rows.length === 0) {
pushNull();
} else {
for (var i = 0; i < rows.length; i++) {
if (rows[i]) {
self.push(rows[i]);
} else {
pushNull();
}
}
}
});
} catch (e) {
// Catch Error: invalid state: reader is busy with another nextRows call
// and return false to rate limit stream.
if (e.message ===
'invalid state: reader is busy with another nextRows call') {
return false;
} else {
this.emit('error', e);
}
}
}; };
module.exports = OracleQueryStream; module.exports = OracleQueryStream;

View File

@ -0,0 +1,23 @@
'use strict';
// Oracle Client
// -------
var inherits = require('inherits');
var Oracle = require('../oracle');
// Always initialize with the "QueryBuilder" and "QueryCompiler"
// objects, which extend the base 'lib/query/builder' and
// 'lib/query/compiler', respectively.
function Client_StrongOracle() {
Oracle.apply(this, arguments);
}
inherits(Client_StrongOracle, Oracle);
// Lazy-load the strong-oracle dependency, since we might just be
// using the client to generate SQL strings.
Client_StrongOracle.prototype.initDriver = function() {
Client_StrongOracle.prototype.driver = Client_StrongOracle.prototype.driver ||
require('strong-oracle')();
};
module.exports = Client_StrongOracle;

View File

@ -8,6 +8,7 @@
}, },
"browser": { "browser": {
"./lib/dialects/oracle": false, "./lib/dialects/oracle": false,
"./lib/dialects/strong-oracle": false,
"./lib/dialects/maria": false, "./lib/dialects/maria": false,
"./lib/dialects/mysql": false, "./lib/dialects/mysql": false,
"./lib/dialects/mysql2": false, "./lib/dialects/mysql2": false,