@sqb/oracle 4.21.1 → 4.23.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/helpers.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { ClientConfiguration } from '@sqb/connect';
2
- import { ConnectionAttributes } from 'oracledb';
1
+ import type { ClientConfiguration } from '@sqb/connect';
2
+ import type { ConnectionAttributes } from 'oracledb';
3
3
  export declare function clientConfigurationToDriver(config: ClientConfiguration): ConnectionAttributes;
package/helpers.js CHANGED
@@ -1,9 +1,10 @@
1
+ import { omit } from '@jsopen/objects';
1
2
  import url from 'url';
2
3
  export function clientConfigurationToDriver(config) {
3
4
  const cfg = {
4
5
  user: config.user,
5
6
  password: config.password,
6
- ...config.driverOptions,
7
+ ...omit(config.driverOptions, ['dateParamFormat']),
7
8
  };
8
9
  if (config.host) {
9
10
  let hostUrl = config.host || 'localhost';
package/ora-adapter.d.ts CHANGED
@@ -1,5 +1,12 @@
1
1
  import '@sqb/oracle-dialect';
2
- import { Adapter, ClientConfiguration } from '@sqb/connect';
2
+ import type { Adapter, ClientConfiguration } from '@sqb/connect';
3
+ export interface OraClientConfiguration extends ClientConfiguration {
4
+ driverOptions?: {
5
+ direct?: boolean;
6
+ /** Format from date-fns. https://date-fns.org/ */
7
+ dateParamFormat?: string;
8
+ };
9
+ }
3
10
  export declare class OraAdapter implements Adapter {
4
11
  driver: string;
5
12
  dialect: string;
@@ -7,5 +14,5 @@ export declare class OraAdapter implements Adapter {
7
14
  cursor: boolean;
8
15
  schema: boolean;
9
16
  };
10
- connect(config: ClientConfiguration): Promise<Adapter.Connection>;
17
+ connect(config: OraClientConfiguration): Promise<Adapter.Connection>;
11
18
  }
@@ -1,4 +1,4 @@
1
- import { Adapter, QueryRequest } from '@sqb/connect';
1
+ import type { Adapter, QueryRequest } from '@sqb/connect';
2
2
  import oracledb from 'oracledb';
3
3
  export declare const dataTypeNames: {
4
4
  DB_TYPE_BFILE: string;
@@ -27,12 +27,16 @@ export declare const dataTypeNames: {
27
27
  DB_TYPE_TIMESTAMP_TZ: string;
28
28
  DB_TYPE_VARCHAR: string;
29
29
  };
30
+ export interface OraConnectionOptions {
31
+ dateParamFormat?: string;
32
+ }
30
33
  export declare class OraConnection implements Adapter.Connection {
31
34
  sessionId: string;
32
35
  private intlcon?;
33
36
  serverVersion: string;
34
37
  private _inTransaction;
35
- constructor(conn: oracledb.Connection, sessionId: string);
38
+ dateParamFormat?: string;
39
+ constructor(conn: oracledb.Connection, sessionId: string, options?: OraConnectionOptions);
36
40
  close(): Promise<void>;
37
41
  reset(): Promise<void>;
38
42
  startTransaction(): Promise<void>;
package/ora-connection.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import assert from 'assert';
2
+ import * as dateFns from 'date-fns';
2
3
  import oracledb from 'oracledb';
3
4
  import { OraCursor } from './ora-cursor.js';
4
5
  export const dataTypeNames = {
@@ -60,10 +61,12 @@ export class OraConnection {
60
61
  intlcon;
61
62
  serverVersion;
62
63
  _inTransaction = false;
63
- constructor(conn, sessionId) {
64
+ dateParamFormat;
65
+ constructor(conn, sessionId, options = {}) {
64
66
  this.sessionId = sessionId;
65
67
  this.intlcon = conn;
66
68
  this.serverVersion = '' + conn.oracleServerVersion;
69
+ this.dateParamFormat = options.dateParamFormat;
67
70
  }
68
71
  async close() {
69
72
  if (!this.intlcon)
@@ -124,6 +127,27 @@ export class OraConnection {
124
127
  else
125
128
  oraOptions.maxRows = request.fetchRows;
126
129
  const out = {};
130
+ const params = request.params;
131
+ if (this.dateParamFormat) {
132
+ const wrapDate = (v) => {
133
+ if (v instanceof Date)
134
+ return dateFns.format(v, this.dateParamFormat);
135
+ if (v.value instanceof Date)
136
+ v.value = dateFns.format(v.value, this.dateParamFormat);
137
+ return v;
138
+ };
139
+ if (params && typeof params === 'object') {
140
+ if (Array.isArray(params)) {
141
+ params.forEach((v, i) => {
142
+ params[i] = wrapDate(v);
143
+ });
144
+ }
145
+ else
146
+ Object.keys(params).forEach(k => {
147
+ params[k] = wrapDate(params[k]);
148
+ });
149
+ }
150
+ }
127
151
  this.intlcon.action = request.action || '';
128
152
  let response = await this.intlcon.execute(request.sql, request.params || [], oraOptions);
129
153
  if (response.rowsAffected)
package/ora-cursor.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Adapter, RowType } from '@sqb/connect';
1
+ import type { Adapter, RowType } from '@sqb/connect';
2
2
  import { ResultSet } from 'oracledb';
3
3
  export declare class OraCursor implements Adapter.Cursor {
4
4
  private _resultSet?;
package/package.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "name": "@sqb/oracle",
3
3
  "description": "SQB serialization extension for Oracle database",
4
- "version": "4.21.1",
4
+ "version": "4.23.0",
5
5
  "author": "Panates",
6
6
  "license": "Apache-2.0",
7
7
  "dependencies": {
8
+ "date-fns": "^4.1.0",
9
+ "@jsopen/objects": "^2.2.0",
8
10
  "tslib": "^2.8.1"
9
11
  },
10
12
  "peerDependencies": {
11
- "@sqb/builder": "^4.21.1",
12
- "@sqb/connect": "^4.21.1",
13
- "@sqb/oracle-dialect": "^4.21.1",
13
+ "@sqb/builder": "^4.23.0",
14
+ "@sqb/connect": "^4.23.0",
15
+ "@sqb/oracle-dialect": "^4.23.0",
14
16
  "oracledb": ">= 6.4.0"
15
17
  },
16
18
  "type": "module",