typeorm 0.3.26-dev.5904ac3 → 0.3.26-dev.66ee307

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 CHANGED
@@ -215,11 +215,8 @@ await timber.remove()
215
215
 
216
216
  ```
217
217
  npm install @sap/hana-client
218
- npm install hdb-pool
219
218
  ```
220
219
 
221
- _SAP Hana support made possible by the sponsorship of [Neptune Software](https://www.neptune-software.com/)._
222
-
223
220
  - for **Google Cloud Spanner**
224
221
 
225
222
  ```
@@ -14,40 +14,66 @@ export interface SapConnectionOptions extends BaseDataSourceOptions, SapConnecti
14
14
  readonly schema?: string;
15
15
  /**
16
16
  * The driver objects
17
- * This defaults to require("hdb-pool")
17
+ * This defaults to require("@sap/hana-client")
18
18
  */
19
19
  readonly driver?: any;
20
20
  /**
21
- * The driver objects
22
- * This defaults to require("@sap/hana-client")
21
+ * @deprecated Use {@link driver} instead.
23
22
  */
24
23
  readonly hanaClientDriver?: any;
25
24
  /**
26
25
  * Pool options.
27
26
  */
28
27
  readonly pool?: {
28
+ /**
29
+ * Maximum number of open connections created by the pool, each of which
30
+ * may be in the pool waiting to be reused or may no longer be in the
31
+ * pool and actively being used (default: 10).
32
+ */
33
+ readonly maxConnectedOrPooled?: number;
34
+ /**
35
+ * Defines the maximum time, in seconds, that connections are allowed to
36
+ * remain in the pool before being marked for eviction (default: 30).
37
+ */
38
+ readonly maxPooledIdleTime?: number;
39
+ /**
40
+ * Determines whether or not the pooled connection should be tested for
41
+ * viability before being reused (default: false).
42
+ */
43
+ readonly pingCheck?: boolean;
44
+ /**
45
+ * Maximum number of connections allowed to be in the pool, waiting to
46
+ * be reused (default: 0, no limit).
47
+ */
48
+ readonly poolCapacity?: number;
29
49
  /**
30
50
  * Max number of connections.
51
+ * @deprecated Use {@link maxConnectedOrPooled} instead.
31
52
  */
32
53
  readonly max?: number;
33
54
  /**
34
55
  * Minimum number of connections.
56
+ * @deprecated Obsolete, no alternative exists.
35
57
  */
36
58
  readonly min?: number;
37
59
  /**
38
- * Maximum number of waiting requests allowed. (default=0, no limit).
60
+ * Maximum number of waiting requests allowed.
61
+ * @deprecated Obsolete, no alternative exists.
39
62
  */
40
63
  readonly maxWaitingRequests?: number;
41
64
  /**
42
- * Max milliseconds a request will wait for a resource before timing out. (default=5000)
65
+ * Max milliseconds a request will wait for a resource before timing out.
66
+ * @deprecated Obsolete, no alternative exists.
43
67
  */
44
68
  readonly requestTimeout?: number;
45
69
  /**
46
- * How often to run resource timeout checks. (default=0, disabled)
70
+ * How often to run resource timeout checks.
71
+ * @deprecated Obsolete, no alternative exists.
47
72
  */
48
73
  readonly checkInterval?: number;
49
74
  /**
50
- * Idle timeout
75
+ * Idle timeout (in milliseconds).
76
+ * @deprecated Use {@link maxPooledIdleTime} (in seconds) instead .
51
77
  */
52
78
  readonly idleTimeout?: number;
53
79
  /**
@@ -56,5 +82,4 @@ export interface SapConnectionOptions extends BaseDataSourceOptions, SapConnecti
56
82
  */
57
83
  readonly poolErrorHandler?: (err: any) => any;
58
84
  };
59
- readonly poolSize?: never;
60
85
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/driver/sap/SapConnectionOptions.ts"],"names":[],"mappings":"","file":"SapConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { SapConnectionCredentialsOptions } from \"./SapConnectionCredentialsOptions\"\n\n/**\n * SAP Hana specific connection options.\n */\nexport interface SapConnectionOptions\n extends BaseDataSourceOptions,\n SapConnectionCredentialsOptions {\n /**\n * Database type.\n */\n readonly type: \"sap\"\n\n /**\n * Database schema.\n */\n readonly schema?: string\n\n /**\n * The driver objects\n * This defaults to require(\"hdb-pool\")\n */\n readonly driver?: any\n\n /**\n * The driver objects\n * This defaults to require(\"@sap/hana-client\")\n */\n readonly hanaClientDriver?: any\n\n /**\n * Pool options.\n */\n readonly pool?: {\n /**\n * Max number of connections.\n */\n readonly max?: number\n\n /**\n * Minimum number of connections.\n */\n readonly min?: number\n\n /**\n * Maximum number of waiting requests allowed. (default=0, no limit).\n */\n readonly maxWaitingRequests?: number\n /**\n * Max milliseconds a request will wait for a resource before timing out. (default=5000)\n */\n readonly requestTimeout?: number\n /**\n * How often to run resource timeout checks. (default=0, disabled)\n */\n readonly checkInterval?: number\n /**\n * Idle timeout\n */\n readonly idleTimeout?: number\n\n /**\n * Function handling errors thrown by drivers pool.\n * Defaults to logging error with `warn` level.\n */\n readonly poolErrorHandler?: (err: any) => any\n }\n\n readonly poolSize?: never\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../browser/src/driver/sap/SapConnectionOptions.ts"],"names":[],"mappings":"","file":"SapConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { SapConnectionCredentialsOptions } from \"./SapConnectionCredentialsOptions\"\n\n/**\n * SAP Hana specific connection options.\n */\nexport interface SapConnectionOptions\n extends BaseDataSourceOptions,\n SapConnectionCredentialsOptions {\n /**\n * Database type.\n */\n readonly type: \"sap\"\n\n /**\n * Database schema.\n */\n readonly schema?: string\n\n /**\n * The driver objects\n * This defaults to require(\"@sap/hana-client\")\n */\n readonly driver?: any\n\n /**\n * @deprecated Use {@link driver} instead.\n */\n readonly hanaClientDriver?: any\n\n /**\n * Pool options.\n */\n readonly pool?: {\n /**\n * Maximum number of open connections created by the pool, each of which\n * may be in the pool waiting to be reused or may no longer be in the\n * pool and actively being used (default: 10).\n */\n readonly maxConnectedOrPooled?: number\n\n /**\n * Defines the maximum time, in seconds, that connections are allowed to\n * remain in the pool before being marked for eviction (default: 30).\n */\n readonly maxPooledIdleTime?: number\n\n /**\n * Determines whether or not the pooled connection should be tested for\n * viability before being reused (default: false).\n */\n readonly pingCheck?: boolean\n\n /**\n * Maximum number of connections allowed to be in the pool, waiting to\n * be reused (default: 0, no limit).\n */\n readonly poolCapacity?: number\n\n /**\n * Max number of connections.\n * @deprecated Use {@link maxConnectedOrPooled} instead.\n */\n readonly max?: number\n\n /**\n * Minimum number of connections.\n * @deprecated Obsolete, no alternative exists.\n */\n readonly min?: number\n\n /**\n * Maximum number of waiting requests allowed.\n * @deprecated Obsolete, no alternative exists.\n */\n readonly maxWaitingRequests?: number\n\n /**\n * Max milliseconds a request will wait for a resource before timing out.\n * @deprecated Obsolete, no alternative exists.\n */\n readonly requestTimeout?: number\n\n /**\n * How often to run resource timeout checks.\n * @deprecated Obsolete, no alternative exists.\n */\n readonly checkInterval?: number\n\n /**\n * Idle timeout (in milliseconds).\n * @deprecated Use {@link maxPooledIdleTime} (in seconds) instead .\n */\n readonly idleTimeout?: number\n\n /**\n * Function handling errors thrown by drivers pool.\n * Defaults to logging error with `warn` level.\n */\n readonly poolErrorHandler?: (err: any) => any\n }\n}\n"],"sourceRoot":"../.."}
@@ -1,15 +1,15 @@
1
1
  import { ColumnType, DataSource, EntityMetadata, ObjectLiteral, Table, TableColumn, TableForeignKey } from "../..";
2
2
  import { ColumnMetadata } from "../../metadata/ColumnMetadata";
3
3
  import { RdbmsSchemaBuilder } from "../../schema-builder/RdbmsSchemaBuilder";
4
+ import { View } from "../../schema-builder/view/View";
4
5
  import { Driver } from "../Driver";
5
6
  import { CteCapabilities } from "../types/CteCapabilities";
6
7
  import { DataTypeDefaults } from "../types/DataTypeDefaults";
7
8
  import { MappedColumnTypes } from "../types/MappedColumnTypes";
8
- import { SapConnectionOptions } from "./SapConnectionOptions";
9
- import { SapQueryRunner } from "./SapQueryRunner";
10
9
  import { ReplicationMode } from "../types/ReplicationMode";
11
- import { View } from "../../schema-builder/view/View";
12
10
  import { UpsertType } from "../types/UpsertType";
11
+ import { SapConnectionOptions } from "./SapConnectionOptions";
12
+ import { SapQueryRunner } from "./SapQueryRunner";
13
13
  /**
14
14
  * Organizes communication with SAP Hana DBMS.
15
15
  *
@@ -21,11 +21,11 @@ export declare class SapDriver implements Driver {
21
21
  */
22
22
  connection: DataSource;
23
23
  /**
24
- * Hana Pool instance.
24
+ * SAP HANA Client Pool instance.
25
25
  */
26
26
  client: any;
27
27
  /**
28
- * Hana Client streaming extension.
28
+ * SAP HANA Client streaming extension.
29
29
  */
30
30
  streamClient: any;
31
31
  /**
@@ -33,10 +33,9 @@ export declare class SapDriver implements Driver {
33
33
  */
34
34
  master: any;
35
35
  /**
36
- * Pool for slave databases.
37
- * Used in replication.
36
+ * Function handling errors thrown by drivers pool.
38
37
  */
39
- slaves: any[];
38
+ poolErrorHandler: (error: any) => void;
40
39
  /**
41
40
  * Connection options.
42
41
  */
@@ -104,7 +103,7 @@ export declare class SapDriver implements Driver {
104
103
  dataTypeDefaults: DataTypeDefaults;
105
104
  /**
106
105
  * Max length allowed by SAP HANA for aliases (identifiers).
107
- * @see https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.03/en-US/20a760537519101497e3cfe07b348f3c.html
106
+ * @see https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-sql-reference-guide/system-limitations
108
107
  */
109
108
  maxAliasLength: number;
110
109
  cteCapabilities: CteCapabilities;
@@ -124,6 +123,18 @@ export declare class SapDriver implements Driver {
124
123
  * Closes connection with the database.
125
124
  */
126
125
  disconnect(): Promise<void>;
126
+ /**
127
+ * Obtains a new database connection to a master server.
128
+ * Used for replication.
129
+ * If replication is not setup then returns default connection's database connection.
130
+ */
131
+ obtainMasterConnection(): Promise<any>;
132
+ /**
133
+ * Obtains a new database connection to a slave server.
134
+ * Used for replication.
135
+ * If replication is not setup then returns master (default) connection's database connection.
136
+ */
137
+ obtainSlaveConnection(): Promise<any>;
127
138
  /**
128
139
  * Creates a schema builder used to build and sync a schema.
129
140
  */
@@ -187,18 +198,6 @@ export declare class SapDriver implements Driver {
187
198
  * Creates column type definition including length, precision and scale
188
199
  */
189
200
  createFullType(column: TableColumn): string;
190
- /**
191
- * Obtains a new database connection to a master server.
192
- * Used for replication.
193
- * If replication is not setup then returns default connection's database connection.
194
- */
195
- obtainMasterConnection(): Promise<any>;
196
- /**
197
- * Obtains a new database connection to a slave server.
198
- * Used for replication.
199
- * If replication is not setup then returns master (default) connection's database connection.
200
- */
201
- obtainSlaveConnection(): Promise<any>;
202
201
  /**
203
202
  * Creates generated map of values generated or returned by database after INSERT query.
204
203
  */
@@ -1,3 +1,4 @@
1
+ import { promisify } from "node:util";
1
2
  import { ConnectionIsNotSetError, } from "../..";
2
3
  import { DriverPackageNotInstalledError } from "../../error/DriverPackageNotInstalledError";
3
4
  import { TypeORMError } from "../../error/TypeORMError";
@@ -5,10 +6,10 @@ import { PlatformTools } from "../../platform/PlatformTools";
5
6
  import { RdbmsSchemaBuilder } from "../../schema-builder/RdbmsSchemaBuilder";
6
7
  import { ApplyValueTransformers } from "../../util/ApplyValueTransformers";
7
8
  import { DateUtils } from "../../util/DateUtils";
9
+ import { InstanceChecker } from "../../util/InstanceChecker";
8
10
  import { OrmUtils } from "../../util/OrmUtils";
9
- import { SapQueryRunner } from "./SapQueryRunner";
10
11
  import { DriverUtils } from "../DriverUtils";
11
- import { InstanceChecker } from "../../util/InstanceChecker";
12
+ import { SapQueryRunner } from "./SapQueryRunner";
12
13
  /**
13
14
  * Organizes communication with SAP Hana DBMS.
14
15
  *
@@ -19,11 +20,6 @@ export class SapDriver {
19
20
  // Constructor
20
21
  // -------------------------------------------------------------------------
21
22
  constructor(connection) {
22
- /**
23
- * Pool for slave databases.
24
- * Used in replication.
25
- */
26
- this.slaves = [];
27
23
  /**
28
24
  * Indicates if replication is enabled.
29
25
  */
@@ -151,7 +147,7 @@ export class SapDriver {
151
147
  };
152
148
  /**
153
149
  * Max length allowed by SAP HANA for aliases (identifiers).
154
- * @see https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.03/en-US/20a760537519101497e3cfe07b348f3c.html
150
+ * @see https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-sql-reference-guide/system-limitations
155
151
  */
156
152
  this.maxAliasLength = 128;
157
153
  this.cteCapabilities = {
@@ -174,50 +170,55 @@ export class SapDriver {
174
170
  */
175
171
  async connect() {
176
172
  // HANA connection info
177
- const dbParams = {
178
- hostName: this.options.host,
173
+ const connectionOptions = {
174
+ host: this.options.host,
179
175
  port: this.options.port,
180
- userName: this.options.username,
176
+ user: this.options.username,
181
177
  password: this.options.password,
182
- ...this.options.extra,
178
+ database: this.options.database,
179
+ currentSchema: this.options.schema,
180
+ encrypt: this.options.encrypt,
181
+ sslValidateCertificate: this.options.sslValidateCertificate,
182
+ key: this.options.key,
183
+ cert: this.options.cert,
184
+ ca: this.options.ca,
183
185
  };
184
- if (this.options.database)
185
- dbParams.databaseName = this.options.database;
186
- if (this.options.schema)
187
- dbParams.currentSchema = this.options.schema;
188
- if (this.options.encrypt)
189
- dbParams.encrypt = this.options.encrypt;
190
- if (this.options.sslValidateCertificate)
191
- dbParams.validateCertificate = this.options.sslValidateCertificate;
192
- if (this.options.key)
193
- dbParams.key = this.options.key;
194
- if (this.options.cert)
195
- dbParams.cert = this.options.cert;
196
- if (this.options.ca)
197
- dbParams.ca = this.options.ca;
186
+ Object.keys(connectionOptions).forEach((key) => {
187
+ if (connectionOptions[key] === undefined) {
188
+ delete connectionOptions[key];
189
+ }
190
+ });
191
+ Object.assign(connectionOptions, this.options.extra ?? {});
198
192
  // pool options
199
- const options = {
200
- min: this.options.pool && this.options.pool.min
201
- ? this.options.pool.min
202
- : 1,
203
- max: this.options.pool && this.options.pool.max
204
- ? this.options.pool.max
205
- : 10,
193
+ const poolOptions = {
194
+ maxConnectedOrPooled: this.options.pool?.maxConnectedOrPooled ??
195
+ this.options.pool?.max ??
196
+ this.options.poolSize ??
197
+ 10,
198
+ maxPooledIdleTime: this.options.pool?.maxPooledIdleTime ??
199
+ (this.options.pool?.idleTimeout
200
+ ? this.options.pool.idleTimeout / 1000
201
+ : 30),
206
202
  };
207
- if (this.options.pool && this.options.pool.checkInterval)
208
- options.checkInterval = this.options.pool.checkInterval;
209
- if (this.options.pool && this.options.pool.maxWaitingRequests)
210
- options.maxWaitingRequests = this.options.pool.maxWaitingRequests;
211
- if (this.options.pool && this.options.pool.requestTimeout)
212
- options.requestTimeout = this.options.pool.requestTimeout;
213
- if (this.options.pool && this.options.pool.idleTimeout)
214
- options.idleTimeout = this.options.pool.idleTimeout;
215
- const { logger } = this.connection;
216
- const poolErrorHandler = options.poolErrorHandler ||
217
- ((error) => logger.log("warn", `SAP Hana pool raised an error. ${error}`));
218
- this.client.eventEmitter.on("poolError", poolErrorHandler);
203
+ if (this.options.pool?.pingCheck) {
204
+ poolOptions.pingCheck = this.options.pool.pingCheck;
205
+ }
206
+ if (this.options.pool?.poolCapacity) {
207
+ poolOptions.poolCapacity = this.options.pool.poolCapacity;
208
+ }
209
+ this.poolErrorHandler =
210
+ this.options.pool?.poolErrorHandler ??
211
+ ((error) => {
212
+ this.connection.logger.log("warn", `SAP HANA pool raised an error: ${error}`);
213
+ });
219
214
  // create the pool
220
- this.master = this.client.createPool(dbParams, options);
215
+ try {
216
+ this.master = this.client.createPool(connectionOptions, poolOptions);
217
+ }
218
+ catch (error) {
219
+ this.poolErrorHandler(error);
220
+ throw error;
221
+ }
221
222
  const queryRunner = this.createQueryRunner("master");
222
223
  const { version, database } = await queryRunner.getDatabaseAndVersion();
223
224
  this.version = version;
@@ -242,7 +243,39 @@ export class SapDriver {
242
243
  throw new ConnectionIsNotSetError("sap");
243
244
  }
244
245
  this.master = undefined;
245
- await pool.clear();
246
+ try {
247
+ await promisify(pool.clear).call(pool);
248
+ }
249
+ catch (error) {
250
+ this.poolErrorHandler(error);
251
+ throw error;
252
+ }
253
+ }
254
+ /**
255
+ * Obtains a new database connection to a master server.
256
+ * Used for replication.
257
+ * If replication is not setup then returns default connection's database connection.
258
+ */
259
+ async obtainMasterConnection() {
260
+ const pool = this.master;
261
+ if (!pool) {
262
+ throw new TypeORMError("Driver not Connected");
263
+ }
264
+ try {
265
+ return await promisify(pool.getConnection).call(pool);
266
+ }
267
+ catch (error) {
268
+ this.poolErrorHandler(error);
269
+ throw error;
270
+ }
271
+ }
272
+ /**
273
+ * Obtains a new database connection to a slave server.
274
+ * Used for replication.
275
+ * If replication is not setup then returns master (default) connection's database connection.
276
+ */
277
+ async obtainSlaveConnection() {
278
+ return this.obtainMasterConnection();
246
279
  }
247
280
  /**
248
281
  * Creates a schema builder used to build and sync a schema.
@@ -553,25 +586,6 @@ export class SapDriver {
553
586
  type += " array";
554
587
  return type;
555
588
  }
556
- /**
557
- * Obtains a new database connection to a master server.
558
- * Used for replication.
559
- * If replication is not setup then returns default connection's database connection.
560
- */
561
- obtainMasterConnection() {
562
- if (!this.master) {
563
- throw new TypeORMError("Driver not Connected");
564
- }
565
- return this.master.getConnection();
566
- }
567
- /**
568
- * Obtains a new database connection to a slave server.
569
- * Used for replication.
570
- * If replication is not setup then returns master (default) connection's database connection.
571
- */
572
- obtainSlaveConnection() {
573
- return this.obtainMasterConnection();
574
- }
575
589
  /**
576
590
  * Creates generated map of values generated or returned by database after INSERT query.
577
591
  */
@@ -651,21 +665,16 @@ export class SapDriver {
651
665
  * If driver dependency is not given explicitly, then try to load it via "require".
652
666
  */
653
667
  loadDependencies() {
654
- try {
655
- const client = this.options.driver || PlatformTools.load("hdb-pool");
668
+ const client = this.options.driver ?? this.options.hanaClientDriver;
669
+ if (client) {
656
670
  this.client = client;
657
- }
658
- catch (e) {
659
- // todo: better error for browser env
660
- throw new DriverPackageNotInstalledError("SAP Hana", "hdb-pool");
671
+ return;
661
672
  }
662
673
  try {
663
- if (!this.options.hanaClientDriver) {
664
- PlatformTools.load("@sap/hana-client");
665
- this.streamClient = PlatformTools.load("@sap/hana-client/extension/Stream");
666
- }
674
+ this.client = PlatformTools.load("@sap/hana-client");
675
+ this.streamClient = PlatformTools.load("@sap/hana-client/extension/Stream");
667
676
  }
668
- catch (e) {
677
+ catch {
669
678
  // todo: better error for browser env
670
679
  throw new DriverPackageNotInstalledError("SAP Hana", "@sap/hana-client");
671
680
  }