knex/lib/dialects/oracle/index.js

80 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-03-02 17:07:05 +01:00
// Oracle Client
// -------
const { inherits } = require('util');
const Client = require('../../client');
const SchemaCompiler = require('./schema/compiler');
const ColumnBuilder = require('./schema/columnbuilder');
const ColumnCompiler = require('./schema/columncompiler');
const TableCompiler = require('./schema/tablecompiler');
const { isConnectionError } = require('./utils');
2016-03-02 17:07:05 +01:00
// Always initialize with the "QueryBuilder" and "QueryCompiler"
// objects, which extend the base 'lib/query/builder' and
// 'lib/query/compiler', respectively.
function Client_Oracle(config) {
Client.call(this, config);
2016-03-02 17:07:05 +01:00
}
inherits(Client_Oracle, Client);
2016-03-02 17:07:05 +01:00
Object.assign(Client_Oracle.prototype, {
2016-03-02 17:07:05 +01:00
dialect: 'oracle',
driverName: 'oracle',
2016-09-13 08:15:58 -04:00
schemaCompiler() {
return new SchemaCompiler(this, ...arguments);
2016-09-13 08:15:58 -04:00
},
2016-03-02 17:07:05 +01:00
2016-09-13 08:15:58 -04:00
columnBuilder() {
return new ColumnBuilder(this, ...arguments);
2016-09-13 08:15:58 -04:00
},
2016-03-02 17:07:05 +01:00
2016-09-13 08:15:58 -04:00
columnCompiler() {
return new ColumnCompiler(this, ...arguments);
2016-09-13 08:15:58 -04:00
},
2016-03-02 17:07:05 +01:00
2016-09-13 08:15:58 -04:00
tableCompiler() {
return new TableCompiler(this, ...arguments);
2016-09-13 08:15:58 -04:00
},
2016-03-02 17:07:05 +01:00
// Return the database for the Oracle client.
database() {
return this.connectionSettings.database;
2016-03-02 17:07:05 +01:00
},
// Position the bindings for the query.
positionBindings(sql) {
let questionCount = 0;
2020-04-19 00:40:23 +02:00
return sql.replace(/\?/g, function () {
questionCount += 1;
return `:${questionCount}`;
});
2016-03-02 17:07:05 +01:00
},
_stream(connection, obj, stream, options) {
2020-04-19 00:40:23 +02:00
return new Promise(function (resolver, rejecter) {
2016-09-13 18:12:23 -04:00
stream.on('error', (err) => {
if (isConnectionError(err)) {
connection.__knex__disposed = err;
2016-09-13 18:12:23 -04:00
}
rejecter(err);
});
2016-03-02 17:07:05 +01:00
stream.on('end', resolver);
const queryStream = connection.queryStream(
obj.sql,
obj.bindings,
options
);
queryStream.pipe(stream);
2020-04-19 00:40:23 +02:00
queryStream.on('error', function (error) {
rejecter(error);
stream.emit('error', error);
});
});
2016-03-02 17:07:05 +01:00
},
});
2016-09-13 18:12:23 -04:00
module.exports = Client_Oracle;