@sqb/oracle-dialect 4.0.8 → 4.0.12
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/dist/OracleSerializer.d.ts +13 -0
- package/dist/OracleSerializer.js +102 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/package.json +3 -4
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SerializerExtension, SerializeContext, DefaultSerializeFunction, SerializationType } from '@sqb/builder';
|
|
2
|
+
export declare class OracleSerializer implements SerializerExtension {
|
|
3
|
+
dialect: string;
|
|
4
|
+
isReservedWord(ctx: any, s: any): any;
|
|
5
|
+
serialize(ctx: SerializeContext, type: SerializationType | string, o: any, defFn: DefaultSerializeFunction): string | undefined;
|
|
6
|
+
private _serializeSelect;
|
|
7
|
+
private _serializeFrom;
|
|
8
|
+
private _serializeComparison;
|
|
9
|
+
private _serializeStringValue;
|
|
10
|
+
private _serializeDateValue;
|
|
11
|
+
private _serializeBooleanValue;
|
|
12
|
+
private _serializeReturning;
|
|
13
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OracleSerializer = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const builder_1 = require("@sqb/builder");
|
|
6
|
+
const compareVersion = tslib_1.__importStar(require("compare-versions"));
|
|
7
|
+
const reservedWords = ['comment', 'dual'];
|
|
8
|
+
class OracleSerializer {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.dialect = 'oracle';
|
|
11
|
+
}
|
|
12
|
+
isReservedWord(ctx, s) {
|
|
13
|
+
return s && typeof s === 'string' &&
|
|
14
|
+
reservedWords.includes(s.toLowerCase());
|
|
15
|
+
}
|
|
16
|
+
serialize(ctx, type, o, defFn) {
|
|
17
|
+
switch (type) {
|
|
18
|
+
case builder_1.SerializationType.SELECT_QUERY:
|
|
19
|
+
return this._serializeSelect(ctx, o, defFn);
|
|
20
|
+
case builder_1.SerializationType.SELECT_QUERY_FROM:
|
|
21
|
+
return this._serializeFrom(ctx, o, defFn);
|
|
22
|
+
case builder_1.SerializationType.COMPARISON_EXPRESSION:
|
|
23
|
+
return this._serializeComparison(ctx, o, defFn);
|
|
24
|
+
case builder_1.SerializationType.STRING_VALUE:
|
|
25
|
+
return this._serializeStringValue(ctx, o, defFn);
|
|
26
|
+
case builder_1.SerializationType.DATE_VALUE:
|
|
27
|
+
return this._serializeDateValue(ctx, o, defFn);
|
|
28
|
+
case builder_1.SerializationType.BOOLEAN_VALUE:
|
|
29
|
+
return this._serializeBooleanValue(ctx, o);
|
|
30
|
+
case builder_1.SerializationType.RETURNING_BLOCK:
|
|
31
|
+
return this._serializeReturning();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
_serializeSelect(ctx, o, defFn) {
|
|
35
|
+
let out = defFn(ctx, o);
|
|
36
|
+
const limit = o.limit || 0;
|
|
37
|
+
const offset = Math.max((o.offset || 0), 0);
|
|
38
|
+
if (limit || offset) {
|
|
39
|
+
if (ctx.dialectVersion && compareVersion.compare(ctx.dialectVersion, '12', '>=')) {
|
|
40
|
+
if (offset)
|
|
41
|
+
out += '\nOFFSET ' + offset + ' ROWS' +
|
|
42
|
+
(limit ? ' FETCH NEXT ' + limit + ' ROWS ONLY' : '');
|
|
43
|
+
else
|
|
44
|
+
out += '\nFETCH FIRST ' + limit + ' ROWS ONLY';
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
if (offset || o.orderBy) {
|
|
48
|
+
out = 'select * from (\n\t' +
|
|
49
|
+
'select /*+ first_rows(' + (limit || 100) +
|
|
50
|
+
') */ t.*, rownum row$number from (\n\t' +
|
|
51
|
+
out + '\n\b' +
|
|
52
|
+
') t' +
|
|
53
|
+
(limit ? ' where rownum <= ' + (limit + offset) : '') + '\n\b)';
|
|
54
|
+
if (offset)
|
|
55
|
+
out += ' where row$number >= ' + (offset + 1);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
out = 'select * from (\n\t' +
|
|
59
|
+
out + '\n\b' +
|
|
60
|
+
') where rownum <= ' + limit;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
_serializeFrom(ctx, o, defFn) {
|
|
67
|
+
return defFn(ctx, o) || 'from dual';
|
|
68
|
+
}
|
|
69
|
+
_serializeComparison(ctx, o, defFn) {
|
|
70
|
+
if (o.right) {
|
|
71
|
+
if (o.right.expression.toLowerCase() === 'null') {
|
|
72
|
+
if (o.operatorType === 'eq')
|
|
73
|
+
return defFn(ctx, { ...o, operatorType: builder_1.OperatorType.is, symbol: 'is' });
|
|
74
|
+
if (o.operatorType === 'ne')
|
|
75
|
+
return defFn(ctx, { ...o, operatorType: builder_1.OperatorType.isNot, symbol: 'is not' });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return defFn(ctx, o);
|
|
79
|
+
}
|
|
80
|
+
_serializeStringValue(ctx, o, defFn) {
|
|
81
|
+
if (typeof o === 'string') {
|
|
82
|
+
if (o.match(/^\d{4}-\d{2}-\d{2}$/))
|
|
83
|
+
return 'to_date(' + o + ', \'yyyy-mm-dd\')';
|
|
84
|
+
if (o.match(/^\d{4}-\d{2}-\d{2}T/))
|
|
85
|
+
return `to_timestamp_tz('${o}','yyyy-mm-dd"T"hh24:mi:sstzh:tzm')`;
|
|
86
|
+
}
|
|
87
|
+
return defFn(ctx, o);
|
|
88
|
+
}
|
|
89
|
+
_serializeDateValue(ctx, o, defFn) {
|
|
90
|
+
const s = defFn(ctx, o);
|
|
91
|
+
return s && (s.length <= 12 ?
|
|
92
|
+
'to_date(' + s + ', \'yyyy-mm-dd\')' :
|
|
93
|
+
'to_date(' + s + ', \'yyyy-mm-dd hh24:mi:ss\')');
|
|
94
|
+
}
|
|
95
|
+
_serializeBooleanValue(_ctx, o) {
|
|
96
|
+
return o == null ? 'null' : (o ? '1' : '0');
|
|
97
|
+
}
|
|
98
|
+
_serializeReturning() {
|
|
99
|
+
return '';
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.OracleSerializer = OracleSerializer;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/oracle-dialect",
|
|
3
3
|
"description": "SQB serialization extension for Oracle database",
|
|
4
|
-
"version": "4.0.
|
|
5
|
-
"author": "Panates
|
|
4
|
+
"version": "4.0.12",
|
|
5
|
+
"author": "Panates",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Eray Hanoglu <e.hanoglu@panates.com>"
|
|
8
8
|
],
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
"clean:dist": "rimraf ../../build/oracle-dialect",
|
|
53
53
|
"compile": "tsc",
|
|
54
54
|
"lint": "eslint src/** --no-error-on-unmatched-pattern",
|
|
55
|
-
"test": "TS_NODE_PROJECT='./test/tsconfig.json' mocha -r ts-node/register -r tsconfig-paths/register --reporter spec test/**/*.spec.ts"
|
|
56
|
-
"version": "#version"
|
|
55
|
+
"test": "TS_NODE_PROJECT='./test/tsconfig.json' mocha -r ts-node/register -r tsconfig-paths/register --reporter spec test/**/*.spec.ts"
|
|
57
56
|
}
|
|
58
57
|
}
|