@sqb/oracle 4.2.1 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -0
- package/{dist → cjs}/helpers.js +0 -0
- package/{dist → cjs}/index.js +2 -2
- package/{dist/OraAdapter.js → cjs/ora-adapter.js} +11 -13
- package/{dist/OraConnection.js → cjs/ora-connection.js} +6 -3
- package/{dist/OraCursor.js → cjs/ora-cursor.js} +4 -0
- package/cjs/package.json +3 -0
- package/{dist → esm}/helpers.d.ts +0 -0
- package/esm/helpers.js +30 -0
- package/{dist → esm}/index.d.ts +0 -0
- package/esm/index.js +4 -0
- package/{dist/OraAdapter.d.ts → esm/ora-adapter.d.ts} +0 -0
- package/esm/ora-adapter.js +35 -0
- package/{dist/OraConnection.d.ts → esm/ora-connection.d.ts} +0 -0
- package/esm/ora-connection.js +199 -0
- package/{dist/OraCursor.d.ts → esm/ora-cursor.d.ts} +0 -0
- package/esm/ora-cursor.js +54 -0
- package/package.json +67 -50
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
|
|
2
|
+
<p style="text-align:center">
|
|
3
|
+
<img src="https://user-images.githubusercontent.com/3836517/32965280-1a2b63ce-cbe7-11e7-8ee1-ba47313503c5.png" width="500px" alt="SQB Logo"/>
|
|
4
|
+
</p>
|
|
5
|
+
|
|
6
|
+
<br>
|
|
7
|
+
|
|
8
|
+
[![NPM Version][npm-image]][npm-url]
|
|
9
|
+
[![NPM Downloads][downloads-image]][downloads-url]
|
|
10
|
+
[![Build Status][travis-image]][travis-url]
|
|
11
|
+
[![Test Coverage][coveralls-image]][coveralls-url]
|
|
12
|
+
[![Dependencies][dependencies-image]][dependencies-url]
|
|
13
|
+
[![DevDependencies][devdependencies-image]][devdependencies-url]
|
|
14
|
+
[![Package Quality][quality-image]][quality-url]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## About SQB
|
|
18
|
+
|
|
19
|
+
SQB is an extensible, multi-dialect SQL query builder and Database connection wrapper for NodeJS.
|
|
20
|
+
|
|
21
|
+
## Main goals
|
|
22
|
+
|
|
23
|
+
- Single code base for any sql based database
|
|
24
|
+
- Powerful and simplified query coding scheme
|
|
25
|
+
- Fast applications with low memory requirements
|
|
26
|
+
- Let applications work with large data tables efficiently
|
|
27
|
+
- Support latest JavaScript language standards
|
|
28
|
+
- Lightweight and extensible framework.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
You can report bugs and discuss features on the [GitHub issues](https://github.com/sqbjs/sqb/issues) page
|
|
32
|
+
|
|
33
|
+
Thanks to all of the great [contributions](https://github.com/sqbjs/sqb/graphs/contributors) to the project.
|
|
34
|
+
|
|
35
|
+
You may want to check detailed [DOCUMENTATION](https://sqbjs.github.io/sqb/)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
$ npm install @sqb/oracle --save
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Node Compatibility
|
|
45
|
+
|
|
46
|
+
- node >= 16.x
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### License
|
|
50
|
+
SQB is available under [MIT](LICENSE) license.
|
|
51
|
+
|
|
52
|
+
[npm-image]: https://img.shields.io/npm/v/@sqb/oracle.svg
|
|
53
|
+
[npm-url]: https://npmjs.org/package/@sqb/oracle
|
|
54
|
+
[travis-image]: https://img.shields.io/travis/sqbjs/@sqb/oracle/master.svg
|
|
55
|
+
[travis-url]: https://travis-ci.org/sqbjs/@sqb/oracle
|
|
56
|
+
[coveralls-image]: https://img.shields.io/coveralls/sqbjs/@sqb/oracle/master.svg
|
|
57
|
+
[coveralls-url]: https://coveralls.io/r/sqbjs/@sqb/oracle
|
|
58
|
+
[downloads-image]: https://img.shields.io/npm/dm/@sqb/oracle.svg
|
|
59
|
+
[downloads-url]: https://npmjs.org/package/@sqb/oracle
|
|
60
|
+
[gitter-image]: https://badges.gitter.im/sqbjs/@sqb/oracle.svg
|
|
61
|
+
[gitter-url]: https://gitter.im/sqbjs/@sqb/oracle?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
|
62
|
+
[dependencies-image]: https://david-dm.org/sqbjs/@sqb/oracle/status.svg
|
|
63
|
+
[dependencies-url]:https://david-dm.org/sqbjs/@sqb/oracle
|
|
64
|
+
[devdependencies-image]: https://david-dm.org/sqbjs/@sqb/oracle/dev-status.svg
|
|
65
|
+
[devdependencies-url]:https://david-dm.org/sqbjs/@sqb/oracle?type=dev
|
|
66
|
+
[quality-image]: http://npm.packagequality.com/shield/@sqb/oracle.png
|
|
67
|
+
[quality-url]: http://packagequality.com/#?package=@sqb/oracle
|
package/{dist → cjs}/helpers.js
RENAMED
|
File without changes
|
package/{dist → cjs}/index.js
RENAMED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
require("@sqb/oracle-dialect");
|
|
4
4
|
const connect_1 = require("@sqb/connect");
|
|
5
|
-
const
|
|
6
|
-
(0, connect_1.registerAdapter)(new
|
|
5
|
+
const ora_adapter_js_1 = require("./ora-adapter.js");
|
|
6
|
+
(0, connect_1.registerAdapter)(new ora_adapter_js_1.OraAdapter());
|
|
@@ -4,20 +4,18 @@ exports.OraAdapter = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
require("@sqb/oracle-dialect");
|
|
6
6
|
const oracledb_1 = tslib_1.__importDefault(require("oracledb"));
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const helpers_js_1 = require("./helpers.js");
|
|
8
|
+
const ora_connection_js_1 = require("./ora-connection.js");
|
|
9
9
|
class OraAdapter {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
}
|
|
10
|
+
driver = 'oracledb';
|
|
11
|
+
dialect = 'oracle';
|
|
12
|
+
features = {
|
|
13
|
+
cursor: true,
|
|
14
|
+
schema: true,
|
|
15
|
+
// fetchAsString: [DataType.DATE, DataType.TIMESTAMP, DataType.TIMESTAMPTZ]
|
|
16
|
+
};
|
|
19
17
|
async connect(config) {
|
|
20
|
-
const cfg = (0,
|
|
18
|
+
const cfg = (0, helpers_js_1.clientConfigurationToDriver)(config);
|
|
21
19
|
// Get oracle connection
|
|
22
20
|
const connection = await oracledb_1.default.getConnection(cfg);
|
|
23
21
|
try {
|
|
@@ -26,7 +24,7 @@ class OraAdapter {
|
|
|
26
24
|
const r = await connection.execute('select sid from v$mystat where rownum <= 1', [], {});
|
|
27
25
|
if (r && r.rows)
|
|
28
26
|
sessionId = r.rows[0][0];
|
|
29
|
-
const oracon = new
|
|
27
|
+
const oracon = new ora_connection_js_1.OraConnection(connection, sessionId);
|
|
30
28
|
/* Set default schema */
|
|
31
29
|
if (config.schema)
|
|
32
30
|
await oracon.setSchema(config.schema);
|
|
@@ -4,7 +4,7 @@ exports.OraConnection = exports.dataTypeNames = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
6
|
const oracledb_1 = tslib_1.__importDefault(require("oracledb"));
|
|
7
|
-
const
|
|
7
|
+
const ora_cursor_js_1 = require("./ora-cursor.js");
|
|
8
8
|
exports.dataTypeNames = {
|
|
9
9
|
[oracledb_1.default.DB_TYPE_BFILE]: 'BFILE',
|
|
10
10
|
[oracledb_1.default.DB_TYPE_BINARY_DOUBLE]: 'BINARY_DOUBLE',
|
|
@@ -60,9 +60,12 @@ const fetchTypeMap = {
|
|
|
60
60
|
[oracledb_1.default.DB_TYPE_VARCHAR]: 'string'
|
|
61
61
|
};
|
|
62
62
|
class OraConnection {
|
|
63
|
+
sessionId;
|
|
64
|
+
intlcon;
|
|
65
|
+
serverVersion;
|
|
66
|
+
_inTransaction = false;
|
|
63
67
|
constructor(conn, sessionId) {
|
|
64
68
|
this.sessionId = sessionId;
|
|
65
|
-
this._inTransaction = false;
|
|
66
69
|
this.intlcon = conn;
|
|
67
70
|
this.serverVersion = '' + conn.oracleServerVersion;
|
|
68
71
|
}
|
|
@@ -190,7 +193,7 @@ class OraConnection {
|
|
|
190
193
|
else if (response.resultSet) {
|
|
191
194
|
out.rowType = request.objectRows ? 'object' : 'array';
|
|
192
195
|
out.cursor =
|
|
193
|
-
new
|
|
196
|
+
new ora_cursor_js_1.OraCursor(response.resultSet, {
|
|
194
197
|
rowType: request.objectRows ? 'object' : 'array',
|
|
195
198
|
rowNumberIdx, rowNumberName
|
|
196
199
|
});
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OraCursor = void 0;
|
|
4
4
|
class OraCursor {
|
|
5
|
+
_resultSet;
|
|
6
|
+
_rowType;
|
|
7
|
+
_rowNumberIdx;
|
|
8
|
+
_rowNumberName;
|
|
5
9
|
constructor(resultSet, opts) {
|
|
6
10
|
this._rowType = opts.rowType;
|
|
7
11
|
this._resultSet = resultSet;
|
package/cjs/package.json
ADDED
|
File without changes
|
package/esm/helpers.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import url from "url";
|
|
2
|
+
export function clientConfigurationToDriver(config) {
|
|
3
|
+
const cfg = {
|
|
4
|
+
user: config.user,
|
|
5
|
+
password: config.password,
|
|
6
|
+
...config.driverOptions
|
|
7
|
+
};
|
|
8
|
+
if (config.host) {
|
|
9
|
+
let hostUrl = config.host || 'localhost';
|
|
10
|
+
if (!hostUrl.includes('://'))
|
|
11
|
+
hostUrl = 'oracle://' + hostUrl;
|
|
12
|
+
const parsed = url.parse(hostUrl, true);
|
|
13
|
+
const host = decodeURI(parsed.hostname || '');
|
|
14
|
+
const port = config.port ||
|
|
15
|
+
(parsed.port && parseInt(parsed.port, 10)) || 1521;
|
|
16
|
+
const database = config.database ||
|
|
17
|
+
(parsed.pathname && decodeURI(parsed.pathname.substring(1)));
|
|
18
|
+
cfg.connectString = `${host}:${port}${(database ? '/' + database : '')}`;
|
|
19
|
+
if (!cfg.externalAuth) {
|
|
20
|
+
if (parsed.auth) {
|
|
21
|
+
const a = parsed.auth.split(':');
|
|
22
|
+
if (!cfg.user && a[0])
|
|
23
|
+
cfg.user = a[0];
|
|
24
|
+
if (!cfg.password && a[1])
|
|
25
|
+
cfg.password = a[1];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return cfg;
|
|
30
|
+
}
|
package/{dist → esm}/index.d.ts
RENAMED
|
File without changes
|
package/esm/index.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import '@sqb/oracle-dialect';
|
|
2
|
+
import oracledb from 'oracledb';
|
|
3
|
+
import { clientConfigurationToDriver } from './helpers.js';
|
|
4
|
+
import { OraConnection } from './ora-connection.js';
|
|
5
|
+
export class OraAdapter {
|
|
6
|
+
driver = 'oracledb';
|
|
7
|
+
dialect = 'oracle';
|
|
8
|
+
features = {
|
|
9
|
+
cursor: true,
|
|
10
|
+
schema: true,
|
|
11
|
+
// fetchAsString: [DataType.DATE, DataType.TIMESTAMP, DataType.TIMESTAMPTZ]
|
|
12
|
+
};
|
|
13
|
+
async connect(config) {
|
|
14
|
+
const cfg = clientConfigurationToDriver(config);
|
|
15
|
+
// Get oracle connection
|
|
16
|
+
const connection = await oracledb.getConnection(cfg);
|
|
17
|
+
try {
|
|
18
|
+
/* Retrieve sessionId */
|
|
19
|
+
let sessionId;
|
|
20
|
+
const r = await connection.execute('select sid from v$mystat where rownum <= 1', [], {});
|
|
21
|
+
if (r && r.rows)
|
|
22
|
+
sessionId = r.rows[0][0];
|
|
23
|
+
const oracon = new OraConnection(connection, sessionId);
|
|
24
|
+
/* Set default schema */
|
|
25
|
+
if (config.schema)
|
|
26
|
+
await oracon.setSchema(config.schema);
|
|
27
|
+
return oracon;
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
if (connection)
|
|
31
|
+
await connection.close();
|
|
32
|
+
throw e;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import oracledb from 'oracledb';
|
|
3
|
+
import { OraCursor } from './ora-cursor.js';
|
|
4
|
+
export const dataTypeNames = {
|
|
5
|
+
[oracledb.DB_TYPE_BFILE]: 'BFILE',
|
|
6
|
+
[oracledb.DB_TYPE_BINARY_DOUBLE]: 'BINARY_DOUBLE',
|
|
7
|
+
[oracledb.DB_TYPE_BINARY_FLOAT]: 'BINARY_FLOAT',
|
|
8
|
+
[oracledb.DB_TYPE_BINARY_INTEGER]: 'BINARY_INTEGER',
|
|
9
|
+
[oracledb.DB_TYPE_BLOB]: 'BLOB',
|
|
10
|
+
[oracledb.DB_TYPE_BOOLEAN]: 'BOOLEAN',
|
|
11
|
+
[oracledb.DB_TYPE_CHAR]: 'CHAR',
|
|
12
|
+
[oracledb.DB_TYPE_CLOB]: 'CLOB',
|
|
13
|
+
[oracledb.DB_TYPE_CURSOR]: 'CURSOR',
|
|
14
|
+
[oracledb.DB_TYPE_DATE]: 'DATE',
|
|
15
|
+
[oracledb.DB_TYPE_INTERVAL_DS]: 'INTERVAL_DS',
|
|
16
|
+
[oracledb.DB_TYPE_INTERVAL_YM]: 'INTERVAL_YM',
|
|
17
|
+
[oracledb.DB_TYPE_LONG]: 'LONG',
|
|
18
|
+
[oracledb.DB_TYPE_LONG_RAW]: 'LONG_RAW',
|
|
19
|
+
[oracledb.DB_TYPE_NCHAR]: 'NCHAR',
|
|
20
|
+
[oracledb.DB_TYPE_NCLOB]: 'NCLOB',
|
|
21
|
+
[oracledb.DB_TYPE_NUMBER]: 'NUMBER',
|
|
22
|
+
[oracledb.DB_TYPE_NVARCHAR]: 'NVARCHAR',
|
|
23
|
+
[oracledb.DB_TYPE_OBJECT]: 'OBJECT',
|
|
24
|
+
[oracledb.DB_TYPE_RAW]: 'RAW',
|
|
25
|
+
[oracledb.DB_TYPE_ROWID]: 'ROWID',
|
|
26
|
+
[oracledb.DB_TYPE_TIMESTAMP]: 'TIMESTAMP',
|
|
27
|
+
[oracledb.DB_TYPE_TIMESTAMP_LTZ]: 'TIMESTAMP_LTZ',
|
|
28
|
+
[oracledb.DB_TYPE_TIMESTAMP_TZ]: 'TIMESTAMP_TZ',
|
|
29
|
+
[oracledb.DB_TYPE_VARCHAR]: 'VARCHAR'
|
|
30
|
+
};
|
|
31
|
+
const fetchTypeMap = {
|
|
32
|
+
[oracledb.DB_TYPE_BFILE]: 'object',
|
|
33
|
+
[oracledb.DB_TYPE_BINARY_DOUBLE]: 'number',
|
|
34
|
+
[oracledb.DB_TYPE_BINARY_FLOAT]: 'number',
|
|
35
|
+
[oracledb.DB_TYPE_BINARY_INTEGER]: 'number',
|
|
36
|
+
[oracledb.DB_TYPE_BLOB]: 'object',
|
|
37
|
+
[oracledb.DB_TYPE_BOOLEAN]: 'boolean',
|
|
38
|
+
[oracledb.DB_TYPE_CHAR]: 'string',
|
|
39
|
+
[oracledb.DB_TYPE_CLOB]: 'object',
|
|
40
|
+
[oracledb.DB_TYPE_CURSOR]: 'object',
|
|
41
|
+
[oracledb.DB_TYPE_DATE]: 'Date',
|
|
42
|
+
[oracledb.DB_TYPE_INTERVAL_DS]: 'string',
|
|
43
|
+
[oracledb.DB_TYPE_INTERVAL_YM]: 'string',
|
|
44
|
+
[oracledb.DB_TYPE_LONG]: 'number',
|
|
45
|
+
[oracledb.DB_TYPE_LONG_RAW]: 'Buffer',
|
|
46
|
+
[oracledb.DB_TYPE_NCHAR]: 'string',
|
|
47
|
+
[oracledb.DB_TYPE_NCLOB]: 'object',
|
|
48
|
+
[oracledb.DB_TYPE_NUMBER]: 'number',
|
|
49
|
+
[oracledb.DB_TYPE_NVARCHAR]: 'string',
|
|
50
|
+
[oracledb.DB_TYPE_OBJECT]: 'object',
|
|
51
|
+
[oracledb.DB_TYPE_RAW]: 'Buffer',
|
|
52
|
+
[oracledb.DB_TYPE_ROWID]: 'number',
|
|
53
|
+
[oracledb.DB_TYPE_TIMESTAMP]: 'Date',
|
|
54
|
+
[oracledb.DB_TYPE_TIMESTAMP_LTZ]: 'Date',
|
|
55
|
+
[oracledb.DB_TYPE_TIMESTAMP_TZ]: 'Date',
|
|
56
|
+
[oracledb.DB_TYPE_VARCHAR]: 'string'
|
|
57
|
+
};
|
|
58
|
+
export class OraConnection {
|
|
59
|
+
sessionId;
|
|
60
|
+
intlcon;
|
|
61
|
+
serverVersion;
|
|
62
|
+
_inTransaction = false;
|
|
63
|
+
constructor(conn, sessionId) {
|
|
64
|
+
this.sessionId = sessionId;
|
|
65
|
+
this.intlcon = conn;
|
|
66
|
+
this.serverVersion = '' + conn.oracleServerVersion;
|
|
67
|
+
}
|
|
68
|
+
async close() {
|
|
69
|
+
if (!this.intlcon)
|
|
70
|
+
return;
|
|
71
|
+
await this.intlcon.close();
|
|
72
|
+
this.intlcon = undefined;
|
|
73
|
+
}
|
|
74
|
+
async reset() {
|
|
75
|
+
return this.rollback();
|
|
76
|
+
}
|
|
77
|
+
async startTransaction() {
|
|
78
|
+
assert.ok(this.intlcon, 'Can not start transaction for a closed db session');
|
|
79
|
+
this._inTransaction = true;
|
|
80
|
+
}
|
|
81
|
+
async commit() {
|
|
82
|
+
assert.ok(this.intlcon, 'Can not commit transaction for a closed db session');
|
|
83
|
+
await this.intlcon.commit();
|
|
84
|
+
this._inTransaction = false;
|
|
85
|
+
}
|
|
86
|
+
async rollback() {
|
|
87
|
+
if (!this.intlcon)
|
|
88
|
+
return;
|
|
89
|
+
await this.intlcon.rollback();
|
|
90
|
+
this._inTransaction = false;
|
|
91
|
+
}
|
|
92
|
+
async test() {
|
|
93
|
+
assert.ok(this.intlcon, 'DB session is closed');
|
|
94
|
+
await this.intlcon.execute('select 1 from dual', [], {});
|
|
95
|
+
}
|
|
96
|
+
async getSchema() {
|
|
97
|
+
assert.ok(this.intlcon, 'DB session is closed');
|
|
98
|
+
const r = await this.intlcon.execute('select sys_context( \'userenv\', \'current_schema\' ) from dual', [], { autoCommit: true });
|
|
99
|
+
if (r && r.rows && r.rows[0])
|
|
100
|
+
return r.rows[0][0];
|
|
101
|
+
return '';
|
|
102
|
+
}
|
|
103
|
+
async setSchema(schema) {
|
|
104
|
+
assert.ok(this.intlcon, 'Can not set schema of a closed db session');
|
|
105
|
+
await this.intlcon.execute('alter SESSION set CURRENT_SCHEMA = ' + schema, [], { autoCommit: true });
|
|
106
|
+
}
|
|
107
|
+
onGenerateQuery(prepared) {
|
|
108
|
+
prepared.dialect = 'oracle';
|
|
109
|
+
prepared.dialectVersion = this.serverVersion;
|
|
110
|
+
}
|
|
111
|
+
async execute(request) {
|
|
112
|
+
assert.ok(this.intlcon, 'Can not execute query with a closed db session');
|
|
113
|
+
const oraOptions = {
|
|
114
|
+
autoCommit: request.autoCommit,
|
|
115
|
+
extendedMetaData: true,
|
|
116
|
+
resultSet: request.cursor,
|
|
117
|
+
outFormat: request.objectRows ? oracledb.OUT_FORMAT_OBJECT : oracledb.OUT_FORMAT_ARRAY
|
|
118
|
+
};
|
|
119
|
+
if (request.cursor)
|
|
120
|
+
oraOptions.fetchArraySize = request.fetchRows;
|
|
121
|
+
else
|
|
122
|
+
oraOptions.maxRows = request.fetchRows;
|
|
123
|
+
const out = {};
|
|
124
|
+
this.intlcon.action = request.action || '';
|
|
125
|
+
let response = await this.intlcon.execute(request.sql, request.params || [], oraOptions);
|
|
126
|
+
if (response.rowsAffected)
|
|
127
|
+
out.rowsAffected = response.rowsAffected;
|
|
128
|
+
if (out.rowsAffected === 1 && request.returningFields) {
|
|
129
|
+
const m = request.sql.match(/\b(insert into|update)\b ("?\w+\.?\w+"?)/i);
|
|
130
|
+
if (m) {
|
|
131
|
+
const selectFields = request.returningFields.map(x => x.field + (x.alias ? ' as ' + x.alias : ''));
|
|
132
|
+
let sql = `select ${selectFields.join(',')} from ${m[2]}\n`;
|
|
133
|
+
if (m[1].toLowerCase() === 'insert into') {
|
|
134
|
+
sql += 'where rowid=\'' + response.lastRowid + '\'';
|
|
135
|
+
response = await this.intlcon.execute(sql);
|
|
136
|
+
}
|
|
137
|
+
else
|
|
138
|
+
// Emulate update ... returning
|
|
139
|
+
if (m[1].toLowerCase() === 'update') {
|
|
140
|
+
const m2 = request.sql.match(/where (.+)/);
|
|
141
|
+
sql += (m2 ? ' where ' + m2[1] : '');
|
|
142
|
+
response = await this.intlcon.execute(sql, request.params || [], oraOptions);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
let fields;
|
|
147
|
+
let rowNumberIdx = -1;
|
|
148
|
+
let rowNumberName = '';
|
|
149
|
+
if (response.metaData) {
|
|
150
|
+
fields = out.fields = [];
|
|
151
|
+
for (const [idx, v] of response.metaData.entries()) {
|
|
152
|
+
if (v.name.toLowerCase() === 'row$number') {
|
|
153
|
+
rowNumberIdx = idx;
|
|
154
|
+
rowNumberName = v.name;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const fieldInfo = {
|
|
158
|
+
_inf: v,
|
|
159
|
+
fieldName: v.name,
|
|
160
|
+
dataType: v.dbTypeName || 'UNKNOWN',
|
|
161
|
+
jsType: fetchTypeMap[v.fetchType || 2001]
|
|
162
|
+
};
|
|
163
|
+
if (v.dbTypeName === 'CHAR')
|
|
164
|
+
fieldInfo.fixedLength = true;
|
|
165
|
+
// others
|
|
166
|
+
if (v.byteSize)
|
|
167
|
+
fieldInfo.size = v.byteSize;
|
|
168
|
+
if (v.nullable)
|
|
169
|
+
fieldInfo.nullable = v.nullable;
|
|
170
|
+
if (v.precision)
|
|
171
|
+
fieldInfo.precision = v.precision;
|
|
172
|
+
fields.push(fieldInfo);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (response.rows) {
|
|
176
|
+
out.rowType = request.objectRows ? 'object' : 'array';
|
|
177
|
+
out.rows = response.rows;
|
|
178
|
+
// remove row$number fields
|
|
179
|
+
if (out.rows && rowNumberIdx >= 0) {
|
|
180
|
+
for (const row of out.rows) {
|
|
181
|
+
if (Array.isArray(row))
|
|
182
|
+
row.splice(rowNumberIdx, 1);
|
|
183
|
+
else
|
|
184
|
+
delete row[rowNumberName];
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
else if (response.resultSet) {
|
|
190
|
+
out.rowType = request.objectRows ? 'object' : 'array';
|
|
191
|
+
out.cursor =
|
|
192
|
+
new OraCursor(response.resultSet, {
|
|
193
|
+
rowType: request.objectRows ? 'object' : 'array',
|
|
194
|
+
rowNumberIdx, rowNumberName
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export class OraCursor {
|
|
2
|
+
_resultSet;
|
|
3
|
+
_rowType;
|
|
4
|
+
_rowNumberIdx;
|
|
5
|
+
_rowNumberName;
|
|
6
|
+
constructor(resultSet, opts) {
|
|
7
|
+
this._rowType = opts.rowType;
|
|
8
|
+
this._resultSet = resultSet;
|
|
9
|
+
this._rowNumberIdx = opts.rowNumberIdx;
|
|
10
|
+
this._rowNumberName = opts.rowNumberName;
|
|
11
|
+
}
|
|
12
|
+
get isClosed() {
|
|
13
|
+
return !this._resultSet;
|
|
14
|
+
}
|
|
15
|
+
get rowType() {
|
|
16
|
+
return this._rowType;
|
|
17
|
+
}
|
|
18
|
+
async close() {
|
|
19
|
+
if (!this._resultSet)
|
|
20
|
+
return;
|
|
21
|
+
const resultSet = this._resultSet;
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
resultSet.close(err => {
|
|
24
|
+
if (err)
|
|
25
|
+
return reject(err);
|
|
26
|
+
this._resultSet = undefined;
|
|
27
|
+
resolve();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
fetch(nRows) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
if (!this._resultSet)
|
|
34
|
+
return resolve(undefined);
|
|
35
|
+
const resultSet = this._resultSet;
|
|
36
|
+
resultSet.getRows(nRows, (err, rows) => {
|
|
37
|
+
if (err)
|
|
38
|
+
return reject(err);
|
|
39
|
+
if (!(rows && rows.length))
|
|
40
|
+
return resolve(undefined);
|
|
41
|
+
/* remove row$number fields */
|
|
42
|
+
if (this._rowNumberName) {
|
|
43
|
+
for (const row of rows) {
|
|
44
|
+
if (Array.isArray(row))
|
|
45
|
+
row.splice(this._rowNumberIdx || 0, 1);
|
|
46
|
+
else
|
|
47
|
+
delete row[this._rowNumberName];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
resolve(rows);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,59 +1,76 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "@sqb/oracle",
|
|
3
|
-
"description": "SQB serialization extension for Oracle database",
|
|
4
|
-
"version": "4.
|
|
5
|
-
"author": "Panates",
|
|
6
|
-
"contributors": [
|
|
7
|
-
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
2
|
+
"name" : "@sqb/oracle",
|
|
3
|
+
"description" : "SQB serialization extension for Oracle database",
|
|
4
|
+
"version" : "4.5.0",
|
|
5
|
+
"author" : "Panates",
|
|
6
|
+
"contributors" : [
|
|
7
|
+
"Eray Hanoglu <e.hanoglu@panates.com>",
|
|
8
|
+
"Ilker Gurelli <i.gurelli@panates.com>"
|
|
8
9
|
],
|
|
9
|
-
"license": "Apache-2.0",
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "https://github.com/sqbjs/sqb.git",
|
|
13
|
-
"directory": "packages/oracle"
|
|
10
|
+
"license" : "Apache-2.0",
|
|
11
|
+
"repository" : {
|
|
12
|
+
"type" : "git",
|
|
13
|
+
"url" : "https://github.com/sqbjs/sqb.git",
|
|
14
|
+
"directory" : "packages/oracle"
|
|
14
15
|
},
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
"
|
|
16
|
+
"scripts" : {
|
|
17
|
+
"compile" : "tsc",
|
|
18
|
+
"prebuild" : "npm run lint && npm run clean",
|
|
19
|
+
"build" : "npm run build:cjs && npm run build:esm",
|
|
20
|
+
"build:cjs" : "tsc -b tsconfig-build-cjs.json",
|
|
21
|
+
"build:esm" : "tsc -b tsconfig-build-esm.json",
|
|
22
|
+
"postbuild" : "cp README.md package.json ../../LICENSE ../../build/oracle && cp ../../package.cjs.json ../../build/oracle/cjs/package.json",
|
|
23
|
+
"lint" : "eslint .",
|
|
24
|
+
"test" : "jest",
|
|
25
|
+
"cover" : "jest --collect-coverage",
|
|
26
|
+
"clean" : "npm run clean:src | npm run clean:dist | npm run clean:cover",
|
|
27
|
+
"clean:src" : "ts-cleanup -s src --all",
|
|
28
|
+
"clean:dist" : "rimraf ../../build/oracle",
|
|
29
|
+
"clean:cover" : "rimraf ../../coverage/oracle"
|
|
28
30
|
},
|
|
29
|
-
"
|
|
30
|
-
"@
|
|
31
|
-
"
|
|
32
|
-
"@sqb/oracle-dialect": "^4.2.0",
|
|
33
|
-
"oracledb": "^5.x.x"
|
|
31
|
+
"devDependencies" : {
|
|
32
|
+
"@types/oracledb" : "^5.2.3",
|
|
33
|
+
"oracledb" : "^5.4.0"
|
|
34
34
|
},
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
35
|
+
"peerDependencies" : {
|
|
36
|
+
"@sqb/builder" : "^4.5.0",
|
|
37
|
+
"@sqb/connect" : "^4.5.0",
|
|
38
|
+
"@sqb/oracle-dialect" : "^4.5.0",
|
|
39
|
+
"oracledb" : "^5.x.x"
|
|
39
40
|
},
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
"type" : "module",
|
|
42
|
+
"main" : "cjs/index.js",
|
|
43
|
+
"module" : "esm/index.js",
|
|
44
|
+
"types" : "esm/index.d.ts",
|
|
45
|
+
"exports" : {
|
|
46
|
+
"." : {
|
|
47
|
+
"require" : "./cjs/index.js",
|
|
48
|
+
"default" : "./esm/index.js"
|
|
49
|
+
},
|
|
50
|
+
"./cjs" : "./cjs/index.js",
|
|
51
|
+
"./esm" : "./esm/index.js"
|
|
43
52
|
},
|
|
44
|
-
"
|
|
53
|
+
"engines" : {
|
|
54
|
+
"node" : ">=16.0",
|
|
55
|
+
"npm" : ">=7.0.0"
|
|
56
|
+
},
|
|
57
|
+
"files" : [
|
|
58
|
+
"bin/",
|
|
59
|
+
"cjs/",
|
|
60
|
+
"esm/",
|
|
45
61
|
"LICENSE",
|
|
46
|
-
"README"
|
|
47
|
-
"dist/"
|
|
62
|
+
"README.md"
|
|
48
63
|
],
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
"keywords" : [
|
|
65
|
+
"sqb",
|
|
66
|
+
"oracle",
|
|
67
|
+
"oracledb",
|
|
68
|
+
"pg",
|
|
69
|
+
"sql",
|
|
70
|
+
"query",
|
|
71
|
+
"builder",
|
|
72
|
+
"dialect",
|
|
73
|
+
"serializer",
|
|
74
|
+
"database"
|
|
75
|
+
]
|
|
76
|
+
}
|