typeorm 0.3.10-dev.e3aac27 → 0.3.10
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/browser/cli-ts-node-commonjs.js +0 -0
- package/browser/cli-ts-node-esm.js +0 -0
- package/browser/data-source/BaseDataSourceOptions.d.ts +4 -0
- package/browser/data-source/BaseDataSourceOptions.js.map +1 -1
- package/browser/data-source/DataSource.d.ts +1 -1
- package/browser/data-source/DataSource.js.map +1 -1
- package/browser/decorator/options/RelationOptions.d.ts +5 -2
- package/browser/decorator/options/RelationOptions.js.map +1 -1
- package/browser/driver/aurora-mysql/AuroraMysqlConnectionOptions.d.ts +1 -0
- package/browser/driver/aurora-mysql/AuroraMysqlConnectionOptions.js.map +1 -1
- package/browser/driver/aurora-postgres/AuroraPostgresConnectionOptions.d.ts +1 -0
- package/browser/driver/aurora-postgres/AuroraPostgresConnectionOptions.js.map +1 -1
- package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +1 -0
- package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
- package/browser/driver/capacitor/CapacitorConnectionOptions.d.ts +1 -0
- package/browser/driver/capacitor/CapacitorConnectionOptions.js.map +1 -1
- package/browser/driver/cockroachdb/CockroachDriver.js +1 -0
- package/browser/driver/cockroachdb/CockroachDriver.js.map +1 -1
- package/browser/driver/cordova/CordovaConnectionOptions.d.ts +1 -0
- package/browser/driver/cordova/CordovaConnectionOptions.js.map +1 -1
- package/browser/driver/expo/ExpoConnectionOptions.d.ts +1 -0
- package/browser/driver/expo/ExpoConnectionOptions.js.map +1 -1
- package/browser/driver/mongodb/MongoConnectionOptions.d.ts +0 -4
- package/browser/driver/mongodb/MongoConnectionOptions.js.map +1 -1
- package/browser/driver/mongodb/typings.d.ts +2 -0
- package/browser/driver/mysql/MysqlDriver.js +1 -1
- package/browser/driver/mysql/MysqlDriver.js.map +1 -1
- package/browser/driver/nativescript/NativescriptConnectionOptions.d.ts +1 -0
- package/browser/driver/nativescript/NativescriptConnectionOptions.js.map +1 -1
- package/browser/driver/oracle/OracleDriver.js +2 -0
- package/browser/driver/oracle/OracleDriver.js.map +1 -1
- package/browser/driver/postgres/PostgresDriver.js +1 -0
- package/browser/driver/postgres/PostgresDriver.js.map +1 -1
- package/browser/driver/react-native/ReactNativeConnectionOptions.d.ts +1 -0
- package/browser/driver/react-native/ReactNativeConnectionOptions.js.map +1 -1
- package/browser/driver/sap/SapConnectionOptions.d.ts +1 -0
- package/browser/driver/sap/SapConnectionOptions.js.map +1 -1
- package/browser/driver/spanner/SpannerConnectionOptions.d.ts +1 -0
- package/browser/driver/spanner/SpannerConnectionOptions.js.map +1 -1
- package/browser/driver/sqlite/SqliteConnectionOptions.d.ts +1 -0
- package/browser/driver/sqlite/SqliteConnectionOptions.js.map +1 -1
- package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +2 -0
- package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
- package/browser/driver/sqljs/SqljsConnectionOptions.d.ts +1 -0
- package/browser/driver/sqljs/SqljsConnectionOptions.js.map +1 -1
- package/browser/driver/sqljs/SqljsDriver.d.ts +1 -0
- package/browser/driver/sqljs/SqljsDriver.js +3 -1
- package/browser/driver/sqljs/SqljsDriver.js.map +1 -1
- package/browser/driver/sqljs/SqljsQueryRunner.js +3 -1
- package/browser/driver/sqljs/SqljsQueryRunner.js.map +1 -1
- package/browser/driver/sqlserver/SqlServerConnectionOptions.d.ts +1 -0
- package/browser/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
- package/browser/entity-manager/EntityManager.d.ts +20 -20
- package/browser/entity-manager/EntityManager.js.map +1 -1
- package/browser/entity-schema/EntitySchemaColumnOptions.d.ts +4 -0
- package/browser/entity-schema/EntitySchemaColumnOptions.js.map +1 -1
- package/browser/entity-schema/EntitySchemaRelationOptions.d.ts +4 -2
- package/browser/entity-schema/EntitySchemaRelationOptions.js.map +1 -1
- package/browser/entity-schema/EntitySchemaTransformer.js +1 -0
- package/browser/entity-schema/EntitySchemaTransformer.js.map +1 -1
- package/browser/find-options/FindOptionsUtils.d.ts +2 -1
- package/browser/find-options/FindOptionsUtils.js.map +1 -1
- package/browser/metadata/RelationMetadata.d.ts +4 -2
- package/browser/metadata/RelationMetadata.js.map +1 -1
- package/browser/persistence/subject-builder/OneToManySubjectBuilder.js +30 -27
- package/browser/persistence/subject-builder/OneToManySubjectBuilder.js.map +1 -1
- package/browser/query-builder/DeleteQueryBuilder.d.ts +2 -2
- package/browser/query-builder/DeleteQueryBuilder.js.map +1 -1
- package/browser/query-builder/InsertQueryBuilder.d.ts +2 -2
- package/browser/query-builder/InsertQueryBuilder.js.map +1 -1
- package/browser/query-builder/QueryBuilder.d.ts +3 -3
- package/browser/query-builder/QueryBuilder.js.map +1 -1
- package/browser/query-builder/QueryPartialEntity.d.ts +5 -2
- package/browser/query-builder/QueryPartialEntity.js.map +1 -1
- package/browser/query-builder/RelationIdLoader.js +15 -14
- package/browser/query-builder/RelationIdLoader.js.map +1 -1
- package/browser/query-builder/RelationQueryBuilder.d.ts +2 -1
- package/browser/query-builder/RelationQueryBuilder.js.map +1 -1
- package/browser/query-builder/SelectQueryBuilder.d.ts +5 -5
- package/browser/query-builder/SelectQueryBuilder.js +1 -1
- package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
- package/browser/repository/BaseEntity.js.map +1 -1
- package/cli-ts-node-commonjs.js +0 -0
- package/cli-ts-node-esm.js +0 -0
- package/cli.js +0 -0
- package/commands/InitCommand.js +5 -5
- package/commands/InitCommand.js.map +1 -1
- package/data-source/BaseDataSourceOptions.d.ts +4 -0
- package/data-source/BaseDataSourceOptions.js.map +1 -1
- package/data-source/DataSource.d.ts +1 -1
- package/data-source/DataSource.js.map +1 -1
- package/decorator/options/RelationOptions.d.ts +5 -2
- package/decorator/options/RelationOptions.js.map +1 -1
- package/driver/aurora-mysql/AuroraMysqlConnectionOptions.d.ts +1 -0
- package/driver/aurora-mysql/AuroraMysqlConnectionOptions.js.map +1 -1
- package/driver/aurora-postgres/AuroraPostgresConnectionOptions.d.ts +1 -0
- package/driver/aurora-postgres/AuroraPostgresConnectionOptions.js.map +1 -1
- package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +1 -0
- package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
- package/driver/capacitor/CapacitorConnectionOptions.d.ts +1 -0
- package/driver/capacitor/CapacitorConnectionOptions.js.map +1 -1
- package/driver/cockroachdb/CockroachDriver.js +1 -0
- package/driver/cockroachdb/CockroachDriver.js.map +1 -1
- package/driver/cordova/CordovaConnectionOptions.d.ts +1 -0
- package/driver/cordova/CordovaConnectionOptions.js.map +1 -1
- package/driver/expo/ExpoConnectionOptions.d.ts +1 -0
- package/driver/expo/ExpoConnectionOptions.js.map +1 -1
- package/driver/mongodb/MongoConnectionOptions.d.ts +0 -4
- package/driver/mongodb/MongoConnectionOptions.js.map +1 -1
- package/driver/mongodb/typings.d.ts +2 -0
- package/driver/mysql/MysqlDriver.js +1 -1
- package/driver/mysql/MysqlDriver.js.map +1 -1
- package/driver/nativescript/NativescriptConnectionOptions.d.ts +1 -0
- package/driver/nativescript/NativescriptConnectionOptions.js.map +1 -1
- package/driver/oracle/OracleDriver.js +2 -0
- package/driver/oracle/OracleDriver.js.map +1 -1
- package/driver/postgres/PostgresDriver.js +1 -0
- package/driver/postgres/PostgresDriver.js.map +1 -1
- package/driver/react-native/ReactNativeConnectionOptions.d.ts +1 -0
- package/driver/react-native/ReactNativeConnectionOptions.js.map +1 -1
- package/driver/sap/SapConnectionOptions.d.ts +1 -0
- package/driver/sap/SapConnectionOptions.js.map +1 -1
- package/driver/spanner/SpannerConnectionOptions.d.ts +1 -0
- package/driver/spanner/SpannerConnectionOptions.js.map +1 -1
- package/driver/sqlite/SqliteConnectionOptions.d.ts +1 -0
- package/driver/sqlite/SqliteConnectionOptions.js.map +1 -1
- package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +2 -0
- package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
- package/driver/sqljs/SqljsConnectionOptions.d.ts +1 -0
- package/driver/sqljs/SqljsConnectionOptions.js.map +1 -1
- package/driver/sqljs/SqljsDriver.d.ts +1 -0
- package/driver/sqljs/SqljsDriver.js +3 -1
- package/driver/sqljs/SqljsDriver.js.map +1 -1
- package/driver/sqljs/SqljsQueryRunner.js +3 -1
- package/driver/sqljs/SqljsQueryRunner.js.map +1 -1
- package/driver/sqlserver/SqlServerConnectionOptions.d.ts +1 -0
- package/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
- package/entity-manager/EntityManager.d.ts +20 -20
- package/entity-manager/EntityManager.js.map +1 -1
- package/entity-schema/EntitySchemaColumnOptions.d.ts +4 -0
- package/entity-schema/EntitySchemaColumnOptions.js.map +1 -1
- package/entity-schema/EntitySchemaRelationOptions.d.ts +4 -2
- package/entity-schema/EntitySchemaRelationOptions.js.map +1 -1
- package/entity-schema/EntitySchemaTransformer.js +1 -0
- package/entity-schema/EntitySchemaTransformer.js.map +1 -1
- package/find-options/FindOptionsUtils.d.ts +2 -1
- package/find-options/FindOptionsUtils.js.map +1 -1
- package/metadata/RelationMetadata.d.ts +4 -2
- package/metadata/RelationMetadata.js.map +1 -1
- package/package.json +274 -1
- package/persistence/subject-builder/OneToManySubjectBuilder.js +30 -27
- package/persistence/subject-builder/OneToManySubjectBuilder.js.map +1 -1
- package/query-builder/DeleteQueryBuilder.d.ts +2 -2
- package/query-builder/DeleteQueryBuilder.js.map +1 -1
- package/query-builder/InsertQueryBuilder.d.ts +2 -2
- package/query-builder/InsertQueryBuilder.js.map +1 -1
- package/query-builder/QueryBuilder.d.ts +3 -3
- package/query-builder/QueryBuilder.js.map +1 -1
- package/query-builder/QueryPartialEntity.d.ts +5 -2
- package/query-builder/QueryPartialEntity.js.map +1 -1
- package/query-builder/RelationIdLoader.js +15 -14
- package/query-builder/RelationIdLoader.js.map +1 -1
- package/query-builder/RelationQueryBuilder.d.ts +2 -1
- package/query-builder/RelationQueryBuilder.js.map +1 -1
- package/query-builder/SelectQueryBuilder.d.ts +5 -5
- package/query-builder/SelectQueryBuilder.js +1 -1
- package/query-builder/SelectQueryBuilder.js.map +1 -1
- package/repository/BaseEntity.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/driver/sqljs/SqljsConnectionOptions.ts"],"names":[],"mappings":"","file":"SqljsConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\n\n/**\n * Sql.js-specific connection options.\n */\nexport interface SqljsConnectionOptions extends BaseDataSourceOptions {\n /**\n * Database type.\n */\n readonly type: \"sqljs\"\n\n /**\n * A Uint8Array that gets imported when the connection is opened.\n */\n readonly database?: Uint8Array\n\n /**\n * The driver object\n * This defaults to require(\"sql.js\")\n */\n readonly driver?: any\n\n /**\n * Config that's used to initialize sql.js.\n */\n readonly sqlJsConfig?: any\n\n /**\n * Enables the autoSave mechanism which either saves to location\n * or calls autoSaveCallback every time a change to the database is made.\n */\n readonly autoSave?: boolean\n\n /**\n * A function that gets called on every change instead of the internal autoSave function.\n * autoSave has to be enabled for this to work.\n */\n readonly autoSaveCallback?: Function\n\n /**\n * File path (Node.js) or local storage key (browser) to load and save database from.\n * If this is specified without autoSave, the database is loaded from the location\n * and can be saved manually via the SqljsEntityManager. If autoSave is enabled,\n * location is used to automatically save the database.\n */\n readonly location?: string\n\n /**\n * Enables the usage of the localforage library to save & load the database asynchronously from the\n * indexedDB instead of using the synchron local storage methods in a browser environment.\n */\n readonly useLocalForage?: boolean\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../../src/driver/sqljs/SqljsConnectionOptions.ts"],"names":[],"mappings":"","file":"SqljsConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\n\n/**\n * Sql.js-specific connection options.\n */\nexport interface SqljsConnectionOptions extends BaseDataSourceOptions {\n /**\n * Database type.\n */\n readonly type: \"sqljs\"\n\n /**\n * A Uint8Array that gets imported when the connection is opened.\n */\n readonly database?: Uint8Array\n\n /**\n * The driver object\n * This defaults to require(\"sql.js\")\n */\n readonly driver?: any\n\n /**\n * Config that's used to initialize sql.js.\n */\n readonly sqlJsConfig?: any\n\n /**\n * Enables the autoSave mechanism which either saves to location\n * or calls autoSaveCallback every time a change to the database is made.\n */\n readonly autoSave?: boolean\n\n /**\n * A function that gets called on every change instead of the internal autoSave function.\n * autoSave has to be enabled for this to work.\n */\n readonly autoSaveCallback?: Function\n\n /**\n * File path (Node.js) or local storage key (browser) to load and save database from.\n * If this is specified without autoSave, the database is loaded from the location\n * and can be saved manually via the SqljsEntityManager. If autoSave is enabled,\n * location is used to automatically save the database.\n */\n readonly location?: string\n\n /**\n * Enables the usage of the localforage library to save & load the database asynchronously from the\n * indexedDB instead of using the synchron local storage methods in a browser environment.\n */\n readonly useLocalForage?: boolean\n\n readonly poolSize?: never\n}\n"],"sourceRoot":"../.."}
|
|
@@ -35,6 +35,7 @@ export declare class SqljsDriver extends AbstractSqliteDriver {
|
|
|
35
35
|
* If a custom autoSaveCallback is specified, it get's called with the database as Uint8Array,
|
|
36
36
|
* otherwise the save method is called which saves it to file (Node.js), local storage (browser)
|
|
37
37
|
* or indexedDB (browser with enabled useLocalForage option).
|
|
38
|
+
* Don't auto-save when in transaction as the call to export will end the current transaction
|
|
38
39
|
*/
|
|
39
40
|
autoSave(): Promise<void>;
|
|
40
41
|
/**
|
|
@@ -154,9 +154,11 @@ class SqljsDriver extends AbstractSqliteDriver_1.AbstractSqliteDriver {
|
|
|
154
154
|
* If a custom autoSaveCallback is specified, it get's called with the database as Uint8Array,
|
|
155
155
|
* otherwise the save method is called which saves it to file (Node.js), local storage (browser)
|
|
156
156
|
* or indexedDB (browser with enabled useLocalForage option).
|
|
157
|
+
* Don't auto-save when in transaction as the call to export will end the current transaction
|
|
157
158
|
*/
|
|
158
159
|
async autoSave() {
|
|
159
|
-
|
|
160
|
+
var _a;
|
|
161
|
+
if (this.options.autoSave && !((_a = this.queryRunner) === null || _a === void 0 ? void 0 : _a.isTransactionActive)) {
|
|
160
162
|
if (this.options.autoSaveCallback) {
|
|
161
163
|
await this.options.autoSaveCallback(this.export());
|
|
162
164
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/driver/sqljs/SqljsDriver.ts"],"names":[],"mappings":";;;AAAA,kFAA8E;AAE9E,yDAAqD;AAGrD,+FAA2F;AAC3F,iFAA6E;AAC7E,gEAA4D;AAE5D,kDAA8C;AAG9C,uCAA0C;AAS1C,MAAa,WAAY,SAAQ,2CAAoB;IAIjD,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,UAAsB;QAC9B,KAAK,CAAC,UAAU,CAAC,CAAA;QAEjB,8EAA8E;QAC9E,uEAAuE;QACvE,IACI,IAAI,CAAC,OAAO,CAAC,QAAQ;YACrB,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ;YACtB,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAChC;YACE,MAAM,IAAI,iDAAuB,CAAC,8BAA8B,CAAC,CAAA;SACpE;QAED,sBAAsB;QACtB,IAAI,CAAC,gBAAgB,EAAE,CAAA;IAC3B,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,KAAK,CAAC,OAAO;QACT,IAAI,CAAC,kBAAkB,GAAG,MAAM,IAAI,CAAC,wBAAwB,EAAE,CAAA;IACnE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU;QACZ,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;QAC5B,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAA;IACnC,CAAC;IAED;;OAEG;IACH,iBAAiB,CAAC,IAAqB;QACnC,IAAI,CAAC,IAAI,CAAC,WAAW;YAAE,IAAI,CAAC,WA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QACjD,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YACjC,IAAI,CAAC,kBAAkB,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;SAC1D;aAAM;YACH,IAAI,CAAC,kBAAkB,GAAG,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAA;SAClD;QAED,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAA;QAExD,OAAO,IAAI,CAAC,kBAAkB,CAAA;IAClC,CAAC;IAED;;OAEG;IACO,gBAAgB;QACtB,IAAI,6BAAa,CAAC,IAAI,KAAK,SAAS,EAAE;YAClC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,GAAG,CAAA;YAChD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;SACvB;aAAM;YACH,IAAI;gBACA,MAAM,MAAM,GACR,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,6BAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;gBACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;aACvB;YAAC,OAAO,CAAC,EAAE;gBACR,MAAM,IAAI,+DAA8B,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;aAC/D;SACJ;IACL,CAAC;CACJ;AAhSD,kCAgSC","file":"SqljsDriver.js","sourcesContent":["import { AbstractSqliteDriver } from \"../sqlite-abstract/AbstractSqliteDriver\"\nimport { SqljsConnectionOptions } from \"./SqljsConnectionOptions\"\nimport { SqljsQueryRunner } from \"./SqljsQueryRunner\"\nimport { QueryRunner } from \"../../query-runner/QueryRunner\"\nimport { DataSource } from \"../../data-source/DataSource\"\nimport { DriverPackageNotInstalledError } from \"../../error/DriverPackageNotInstalledError\"\nimport { DriverOptionNotSetError } from \"../../error/DriverOptionNotSetError\"\nimport { PlatformTools } from \"../../platform/PlatformTools\"\nimport { EntityMetadata } from \"../../metadata/EntityMetadata\"\nimport { OrmUtils } from \"../../util/OrmUtils\"\nimport { ObjectLiteral } from \"../../common/ObjectLiteral\"\nimport { ReplicationMode } from \"../types/ReplicationMode\"\nimport { TypeORMError } from \"../../error\"\n\n// This is needed to satisfy the typescript compiler.\ninterface Window {\n SQL: any\n localforage: any\n}\ndeclare let window: Window\n\nexport class SqljsDriver extends AbstractSqliteDriver {\n // The driver specific options.\n options: SqljsConnectionOptions\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(connection: DataSource) {\n super(connection)\n\n // If autoSave is enabled by user, location or autoSaveCallback have to be set\n // because either autoSave saves to location or calls autoSaveCallback.\n if (\n this.options.autoSave &&\n !this.options.location &&\n !this.options.autoSaveCallback\n ) {\n throw new DriverOptionNotSetError(`location or autoSaveCallback`)\n }\n\n // load sql.js package\n this.loadDependencies()\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Performs connection to the database.\n */\n async connect(): Promise<void> {\n this.databaseConnection = await this.createDatabaseConnection()\n }\n\n /**\n * Closes connection with database.\n */\n async disconnect(): Promise<void> {\n this.queryRunner = undefined\n this.databaseConnection.close()\n }\n\n /**\n * Creates a query runner used to execute database queries.\n */\n createQueryRunner(mode: ReplicationMode): QueryRunner {\n if (!this.queryRunner) this.queryRunner = new SqljsQueryRunner(this)\n\n return this.queryRunner\n }\n\n /**\n * Loads a database from a given file (Node.js), local storage key (browser) or array.\n * This will delete the current database!\n */\n async load(\n fileNameOrLocalStorageOrData: string | Uint8Array,\n checkIfFileOrLocalStorageExists: boolean = true,\n ): Promise<any> {\n if (typeof fileNameOrLocalStorageOrData === \"string\") {\n // content has to be loaded\n if (PlatformTools.type === \"node\") {\n // Node.js\n // fileNameOrLocalStorageOrData should be a path to the file\n if (PlatformTools.fileExist(fileNameOrLocalStorageOrData)) {\n const database = PlatformTools.readFileSync(\n fileNameOrLocalStorageOrData,\n )\n return this.createDatabaseConnectionWithImport(database)\n } else if (checkIfFileOrLocalStorageExists) {\n throw new TypeORMError(\n `File ${fileNameOrLocalStorageOrData} does not exist`,\n )\n } else {\n // File doesn't exist and checkIfFileOrLocalStorageExists is set to false.\n // Therefore open a database without importing an existing file.\n // File will be written on first write operation.\n return this.createDatabaseConnectionWithImport()\n }\n } else {\n // browser\n // fileNameOrLocalStorageOrData should be a local storage / indexedDB key\n let localStorageContent = null\n if (this.options.useLocalForage) {\n if (window.localforage) {\n localStorageContent = await window.localforage.getItem(\n fileNameOrLocalStorageOrData,\n )\n } else {\n throw new TypeORMError(\n `localforage is not defined - please import localforage.js into your site`,\n )\n }\n } else {\n localStorageContent =\n PlatformTools.getGlobalVariable().localStorage.getItem(\n fileNameOrLocalStorageOrData,\n )\n }\n\n if (localStorageContent != null) {\n // localStorage value exists.\n return this.createDatabaseConnectionWithImport(\n JSON.parse(localStorageContent),\n )\n } else if (checkIfFileOrLocalStorageExists) {\n throw new TypeORMError(\n `File ${fileNameOrLocalStorageOrData} does not exist`,\n )\n } else {\n // localStorage value doesn't exist and checkIfFileOrLocalStorageExists is set to false.\n // Therefore open a database without importing anything.\n // localStorage value will be written on first write operation.\n return this.createDatabaseConnectionWithImport()\n }\n }\n } else {\n return this.createDatabaseConnectionWithImport(\n fileNameOrLocalStorageOrData,\n )\n }\n }\n\n /**\n * Saved the current database to the given file (Node.js), local storage key (browser) or\n * indexedDB key (browser with enabled useLocalForage option).\n * If no location path is given, the location path in the options (if specified) will be used.\n */\n async save(location?: string) {\n if (!location && !this.options.location) {\n throw new TypeORMError(\n `No location is set, specify a location parameter or add the location option to your configuration`,\n )\n }\n\n let path = \"\"\n if (location) {\n path = location\n } else if (this.options.location) {\n path = this.options.location\n }\n\n if (PlatformTools.type === \"node\") {\n try {\n const content = Buffer.from(this.databaseConnection.export())\n await PlatformTools.writeFile(path, content)\n } catch (e) {\n throw new TypeORMError(`Could not save database, error: ${e}`)\n }\n } else {\n const database: Uint8Array = this.databaseConnection.export()\n // convert Uint8Array to number array to improve local-storage storage\n const databaseArray = [].slice.call(database)\n if (this.options.useLocalForage) {\n if (window.localforage) {\n await window.localforage.setItem(\n path,\n JSON.stringify(databaseArray),\n )\n } else {\n throw new TypeORMError(\n `localforage is not defined - please import localforage.js into your site`,\n )\n }\n } else {\n PlatformTools.getGlobalVariable().localStorage.setItem(\n path,\n JSON.stringify(databaseArray),\n )\n }\n }\n }\n\n /**\n * This gets called by the QueryRunner when a change to the database is made.\n * If a custom autoSaveCallback is specified, it get's called with the database as Uint8Array,\n * otherwise the save method is called which saves it to file (Node.js), local storage (browser)\n * or indexedDB (browser with enabled useLocalForage option).\n */\n async autoSave() {\n if (this.options.autoSave) {\n if (this.options.autoSaveCallback) {\n await this.options.autoSaveCallback(this.export())\n } else {\n await this.save()\n }\n }\n }\n\n /**\n * Returns the current database as Uint8Array.\n */\n export(): Uint8Array {\n return this.databaseConnection.export()\n }\n\n /**\n * Creates generated map of values generated or returned by database after INSERT query.\n */\n createGeneratedMap(metadata: EntityMetadata, insertResult: any) {\n const generatedMap = metadata.generatedColumns.reduce(\n (map, generatedColumn) => {\n // seems to be the only way to get the inserted id, see https://github.com/kripken/sql.js/issues/77\n if (\n generatedColumn.isPrimary &&\n generatedColumn.generationStrategy === \"increment\"\n ) {\n const query = \"SELECT last_insert_rowid()\"\n try {\n let result = this.databaseConnection.exec(query)\n this.connection.logger.logQuery(query)\n return OrmUtils.mergeDeep(\n map,\n generatedColumn.createValueMap(\n result[0].values[0][0],\n ),\n )\n } catch (e) {\n this.connection.logger.logQueryError(e, query, [])\n }\n }\n\n return map\n },\n {} as ObjectLiteral,\n )\n\n return Object.keys(generatedMap).length > 0 ? generatedMap : undefined\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates connection with the database.\n * If the location option is set, the database is loaded first.\n */\n protected createDatabaseConnection(): Promise<any> {\n if (this.options.location) {\n return this.load(this.options.location, false)\n }\n\n return this.createDatabaseConnectionWithImport(this.options.database)\n }\n\n /**\n * Creates connection with an optional database.\n * If database is specified it is loaded, otherwise a new empty database is created.\n */\n protected async createDatabaseConnectionWithImport(\n database?: Uint8Array,\n ): Promise<any> {\n // sql.js < 1.0 exposes an object with a `Database` method.\n const isLegacyVersion = typeof this.sqlite.Database === \"function\"\n const sqlite = isLegacyVersion\n ? this.sqlite\n : await this.sqlite(this.options.sqlJsConfig)\n if (database && database.length > 0) {\n this.databaseConnection = new sqlite.Database(database)\n } else {\n this.databaseConnection = new sqlite.Database()\n }\n\n this.databaseConnection.exec(`PRAGMA foreign_keys = ON`)\n\n return this.databaseConnection\n }\n\n /**\n * If driver dependency is not given explicitly, then try to load it via \"require\".\n */\n protected loadDependencies(): void {\n if (PlatformTools.type === \"browser\") {\n const sqlite = this.options.driver || window.SQL\n this.sqlite = sqlite\n } else {\n try {\n const sqlite =\n this.options.driver || PlatformTools.load(\"sql.js\")\n this.sqlite = sqlite\n } catch (e) {\n throw new DriverPackageNotInstalledError(\"sql.js\", \"sql.js\")\n }\n }\n }\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../../src/driver/sqljs/SqljsDriver.ts"],"names":[],"mappings":";;;AAAA,kFAA8E;AAE9E,yDAAqD;AAGrD,+FAA2F;AAC3F,iFAA6E;AAC7E,gEAA4D;AAE5D,kDAA8C;AAG9C,uCAA0C;AAS1C,MAAa,WAAY,SAAQ,2CAAoB;IAIjD,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,UAAsB;QAC9B,KAAK,CAAC,UAAU,CAAC,CAAA;QAEjB,8EAA8E;QAC9E,uEAAuE;QACvE,IACI,IAAI,CAAC,OAAO,CAAC,QAAQ;YACrB,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ;YACtB,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAChC;YACE,MAAM,IAAI,iDAAuB,CAAC,8BAA8B,CAAC,CAAA;SACpE;QAED,sBAAsB;QACtB,IAAI,C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,OAAO,CAAC,EAAE;gBACR,MAAM,IAAI,+DAA8B,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;aAC/D;SACJ;IACL,CAAC;CACJ;AAjSD,kCAiSC","file":"SqljsDriver.js","sourcesContent":["import { AbstractSqliteDriver } from \"../sqlite-abstract/AbstractSqliteDriver\"\nimport { SqljsConnectionOptions } from \"./SqljsConnectionOptions\"\nimport { SqljsQueryRunner } from \"./SqljsQueryRunner\"\nimport { QueryRunner } from \"../../query-runner/QueryRunner\"\nimport { DataSource } from \"../../data-source/DataSource\"\nimport { DriverPackageNotInstalledError } from \"../../error/DriverPackageNotInstalledError\"\nimport { DriverOptionNotSetError } from \"../../error/DriverOptionNotSetError\"\nimport { PlatformTools } from \"../../platform/PlatformTools\"\nimport { EntityMetadata } from \"../../metadata/EntityMetadata\"\nimport { OrmUtils } from \"../../util/OrmUtils\"\nimport { ObjectLiteral } from \"../../common/ObjectLiteral\"\nimport { ReplicationMode } from \"../types/ReplicationMode\"\nimport { TypeORMError } from \"../../error\"\n\n// This is needed to satisfy the typescript compiler.\ninterface Window {\n SQL: any\n localforage: any\n}\ndeclare let window: Window\n\nexport class SqljsDriver extends AbstractSqliteDriver {\n // The driver specific options.\n options: SqljsConnectionOptions\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(connection: DataSource) {\n super(connection)\n\n // If autoSave is enabled by user, location or autoSaveCallback have to be set\n // because either autoSave saves to location or calls autoSaveCallback.\n if (\n this.options.autoSave &&\n !this.options.location &&\n !this.options.autoSaveCallback\n ) {\n throw new DriverOptionNotSetError(`location or autoSaveCallback`)\n }\n\n // load sql.js package\n this.loadDependencies()\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Performs connection to the database.\n */\n async connect(): Promise<void> {\n this.databaseConnection = await this.createDatabaseConnection()\n }\n\n /**\n * Closes connection with database.\n */\n async disconnect(): Promise<void> {\n this.queryRunner = undefined\n this.databaseConnection.close()\n }\n\n /**\n * Creates a query runner used to execute database queries.\n */\n createQueryRunner(mode: ReplicationMode): QueryRunner {\n if (!this.queryRunner) this.queryRunner = new SqljsQueryRunner(this)\n\n return this.queryRunner\n }\n\n /**\n * Loads a database from a given file (Node.js), local storage key (browser) or array.\n * This will delete the current database!\n */\n async load(\n fileNameOrLocalStorageOrData: string | Uint8Array,\n checkIfFileOrLocalStorageExists: boolean = true,\n ): Promise<any> {\n if (typeof fileNameOrLocalStorageOrData === \"string\") {\n // content has to be loaded\n if (PlatformTools.type === \"node\") {\n // Node.js\n // fileNameOrLocalStorageOrData should be a path to the file\n if (PlatformTools.fileExist(fileNameOrLocalStorageOrData)) {\n const database = PlatformTools.readFileSync(\n fileNameOrLocalStorageOrData,\n )\n return this.createDatabaseConnectionWithImport(database)\n } else if (checkIfFileOrLocalStorageExists) {\n throw new TypeORMError(\n `File ${fileNameOrLocalStorageOrData} does not exist`,\n )\n } else {\n // File doesn't exist and checkIfFileOrLocalStorageExists is set to false.\n // Therefore open a database without importing an existing file.\n // File will be written on first write operation.\n return this.createDatabaseConnectionWithImport()\n }\n } else {\n // browser\n // fileNameOrLocalStorageOrData should be a local storage / indexedDB key\n let localStorageContent = null\n if (this.options.useLocalForage) {\n if (window.localforage) {\n localStorageContent = await window.localforage.getItem(\n fileNameOrLocalStorageOrData,\n )\n } else {\n throw new TypeORMError(\n `localforage is not defined - please import localforage.js into your site`,\n )\n }\n } else {\n localStorageContent =\n PlatformTools.getGlobalVariable().localStorage.getItem(\n fileNameOrLocalStorageOrData,\n )\n }\n\n if (localStorageContent != null) {\n // localStorage value exists.\n return this.createDatabaseConnectionWithImport(\n JSON.parse(localStorageContent),\n )\n } else if (checkIfFileOrLocalStorageExists) {\n throw new TypeORMError(\n `File ${fileNameOrLocalStorageOrData} does not exist`,\n )\n } else {\n // localStorage value doesn't exist and checkIfFileOrLocalStorageExists is set to false.\n // Therefore open a database without importing anything.\n // localStorage value will be written on first write operation.\n return this.createDatabaseConnectionWithImport()\n }\n }\n } else {\n return this.createDatabaseConnectionWithImport(\n fileNameOrLocalStorageOrData,\n )\n }\n }\n\n /**\n * Saved the current database to the given file (Node.js), local storage key (browser) or\n * indexedDB key (browser with enabled useLocalForage option).\n * If no location path is given, the location path in the options (if specified) will be used.\n */\n async save(location?: string) {\n if (!location && !this.options.location) {\n throw new TypeORMError(\n `No location is set, specify a location parameter or add the location option to your configuration`,\n )\n }\n\n let path = \"\"\n if (location) {\n path = location\n } else if (this.options.location) {\n path = this.options.location\n }\n\n if (PlatformTools.type === \"node\") {\n try {\n const content = Buffer.from(this.databaseConnection.export())\n await PlatformTools.writeFile(path, content)\n } catch (e) {\n throw new TypeORMError(`Could not save database, error: ${e}`)\n }\n } else {\n const database: Uint8Array = this.databaseConnection.export()\n // convert Uint8Array to number array to improve local-storage storage\n const databaseArray = [].slice.call(database)\n if (this.options.useLocalForage) {\n if (window.localforage) {\n await window.localforage.setItem(\n path,\n JSON.stringify(databaseArray),\n )\n } else {\n throw new TypeORMError(\n `localforage is not defined - please import localforage.js into your site`,\n )\n }\n } else {\n PlatformTools.getGlobalVariable().localStorage.setItem(\n path,\n JSON.stringify(databaseArray),\n )\n }\n }\n }\n\n /**\n * This gets called by the QueryRunner when a change to the database is made.\n * If a custom autoSaveCallback is specified, it get's called with the database as Uint8Array,\n * otherwise the save method is called which saves it to file (Node.js), local storage (browser)\n * or indexedDB (browser with enabled useLocalForage option).\n * Don't auto-save when in transaction as the call to export will end the current transaction\n */\n async autoSave() {\n if (this.options.autoSave && !this.queryRunner?.isTransactionActive) {\n if (this.options.autoSaveCallback) {\n await this.options.autoSaveCallback(this.export())\n } else {\n await this.save()\n }\n }\n }\n\n /**\n * Returns the current database as Uint8Array.\n */\n export(): Uint8Array {\n return this.databaseConnection.export()\n }\n\n /**\n * Creates generated map of values generated or returned by database after INSERT query.\n */\n createGeneratedMap(metadata: EntityMetadata, insertResult: any) {\n const generatedMap = metadata.generatedColumns.reduce(\n (map, generatedColumn) => {\n // seems to be the only way to get the inserted id, see https://github.com/kripken/sql.js/issues/77\n if (\n generatedColumn.isPrimary &&\n generatedColumn.generationStrategy === \"increment\"\n ) {\n const query = \"SELECT last_insert_rowid()\"\n try {\n let result = this.databaseConnection.exec(query)\n this.connection.logger.logQuery(query)\n return OrmUtils.mergeDeep(\n map,\n generatedColumn.createValueMap(\n result[0].values[0][0],\n ),\n )\n } catch (e) {\n this.connection.logger.logQueryError(e, query, [])\n }\n }\n\n return map\n },\n {} as ObjectLiteral,\n )\n\n return Object.keys(generatedMap).length > 0 ? generatedMap : undefined\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates connection with the database.\n * If the location option is set, the database is loaded first.\n */\n protected createDatabaseConnection(): Promise<any> {\n if (this.options.location) {\n return this.load(this.options.location, false)\n }\n\n return this.createDatabaseConnectionWithImport(this.options.database)\n }\n\n /**\n * Creates connection with an optional database.\n * If database is specified it is loaded, otherwise a new empty database is created.\n */\n protected async createDatabaseConnectionWithImport(\n database?: Uint8Array,\n ): Promise<any> {\n // sql.js < 1.0 exposes an object with a `Database` method.\n const isLegacyVersion = typeof this.sqlite.Database === \"function\"\n const sqlite = isLegacyVersion\n ? this.sqlite\n : await this.sqlite(this.options.sqlJsConfig)\n if (database && database.length > 0) {\n this.databaseConnection = new sqlite.Database(database)\n } else {\n this.databaseConnection = new sqlite.Database()\n }\n\n this.databaseConnection.exec(`PRAGMA foreign_keys = ON`)\n\n return this.databaseConnection\n }\n\n /**\n * If driver dependency is not given explicitly, then try to load it via \"require\".\n */\n protected loadDependencies(): void {\n if (PlatformTools.type === \"browser\") {\n const sqlite = this.options.driver || window.SQL\n this.sqlite = sqlite\n } else {\n try {\n const sqlite =\n this.options.driver || PlatformTools.load(\"sql.js\")\n this.sqlite = sqlite\n } catch (e) {\n throw new DriverPackageNotInstalledError(\"sql.js\", \"sql.js\")\n }\n }\n }\n}\n"],"sourceRoot":"../.."}
|
|
@@ -54,7 +54,9 @@ class SqljsQueryRunner extends AbstractSqliteQueryRunner_1.AbstractSqliteQueryRu
|
|
|
54
54
|
*/
|
|
55
55
|
async commitTransaction() {
|
|
56
56
|
await super.commitTransaction();
|
|
57
|
-
|
|
57
|
+
if (!this.isTransactionActive) {
|
|
58
|
+
await this.flush();
|
|
59
|
+
}
|
|
58
60
|
}
|
|
59
61
|
/**
|
|
60
62
|
* Executes a given SQL query.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/driver/sqljs/SqljsQueryRunner.ts"],"names":[],"mappings":";;;AAAA,iGAA6F;AAC7F,4FAAwF;AAExF,8DAA0D;AAC1D,mEAA+D;AAC/D,gEAA4D;AAE5D;;GAEG;AACH,MAAa,gBAAiB,SAAQ,qDAAyB;IAW3D,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,MAAmB;QAC3B,KAAK,EAAE,CAAA;QAfX;;WAEG;QACK,YAAO,GAAG,KAAK,CAAA;QAanB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;QACnC,IAAI,CAAC,WAAW,GAAG,IAAI,yBAAW,CAAC,IAAI,CAAC,CAAA;IAC5C,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,KAAK,CAAC,eAAe;QACjB,MAAM,IAAI,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAA;IACjD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,cAAc;QAChB,MAAM,IAAI,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAA;IAChD,CAAC;IAEO,KAAK,CAAC,KAAK;QACf,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAA;YAC5B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;SACvB;IACL,CAAC;IAED,KAA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A;YAChC,MAAM,kBAAkB,GAAG,YAAY,GAAG,cAAc,CAAA;YACxD,IACI,qBAAqB;gBACrB,kBAAkB,GAAG,qBAAqB;gBAE1C,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,YAAY,CACtC,kBAAkB,EAClB,KAAK,EACL,UAAU,EACV,IAAI,CACP,CAAA;YAEL,MAAM,OAAO,GAAU,EAAE,CAAA;YAEzB,OAAO,SAAS,CAAC,IAAI,EAAE,EAAE;gBACrB,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,CAAA;aACxC;YAED,MAAM,MAAM,GAAG,IAAI,yBAAW,EAAE,CAAA;YAEhC,MAAM,CAAC,QAAQ,GAAG,kBAAkB,CAAC,eAAe,EAAE,CAAA;YACtD,MAAM,CAAC,OAAO,GAAG,OAAO,CAAA;YACxB,MAAM,CAAC,GAAG,GAAG,OAAO,CAAA;YAEpB,SAAS,CAAC,IAAI,EAAE,CAAA;YAEhB,IAAI,OAAO,KAAK,QAAQ,EAAE;gBACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;aACtB;YAED,IAAI,mBAAmB,EAAE;gBACrB,OAAO,MAAM,CAAA;aAChB;iBAAM;gBACH,OAAO,MAAM,CAAC,GAAG,CAAA;aACpB;SACJ;QAAC,OAAO,CAAC,EAAE;YACR,IAAI,SAAS,EAAE;gBACX,SAAS,CAAC,IAAI,EAAE,CAAA;aACnB;YAED,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,aAAa,CACvC,CAAC,EACD,KAAK,EACL,UAAU,EACV,IAAI,CACP,CAAA;YACD,MAAM,IAAI,mCAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC,CAAA;SACnD;IACL,CAAC;CACJ;AA9ID,4CA8IC","file":"SqljsQueryRunner.js","sourcesContent":["import { QueryRunnerAlreadyReleasedError } from \"../../error/QueryRunnerAlreadyReleasedError\"\nimport { AbstractSqliteQueryRunner } from \"../sqlite-abstract/AbstractSqliteQueryRunner\"\nimport { SqljsDriver } from \"./SqljsDriver\"\nimport { Broadcaster } from \"../../subscriber/Broadcaster\"\nimport { QueryFailedError } from \"../../error/QueryFailedError\"\nimport { QueryResult } from \"../../query-runner/QueryResult\"\n\n/**\n * Runs queries on a single sqlite database connection.\n */\nexport class SqljsQueryRunner extends AbstractSqliteQueryRunner {\n /**\n * Flag to determine if a modification has happened since the last time this query runner has requested a save.\n */\n private isDirty = false\n\n /**\n * Database driver used by connection.\n */\n driver: SqljsDriver\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(driver: SqljsDriver) {\n super()\n this.driver = driver\n this.connection = driver.connection\n this.broadcaster = new Broadcaster(this)\n }\n\n // -------------------------------------------------------------------------\n // Public methods\n // -------------------------------------------------------------------------\n\n /**\n * Called before migrations are run.\n */\n async beforeMigration(): Promise<void> {\n await this.query(`PRAGMA foreign_keys = OFF`)\n }\n\n /**\n * Called after migrations are run.\n */\n async afterMigration(): Promise<void> {\n await this.query(`PRAGMA foreign_keys = ON`)\n }\n\n private async flush() {\n if (this.isDirty) {\n await this.driver.autoSave()\n this.isDirty = false\n }\n }\n\n async release(): Promise<void> {\n await this.flush()\n return super.release()\n }\n\n /**\n * Commits transaction.\n * Error will be thrown if transaction was not started.\n */\n async commitTransaction(): Promise<void> {\n await super.commitTransaction()\n if (!this.isTransactionActive) {\n await this.flush()\n }\n }\n\n /**\n * Executes a given SQL query.\n */\n async query(\n query: string,\n parameters: any[] = [],\n useStructuredResult = false,\n ): Promise<any> {\n if (this.isReleased) throw new QueryRunnerAlreadyReleasedError()\n\n const command = query.trim().split(\" \", 1)[0]\n\n const databaseConnection = this.driver.databaseConnection\n this.driver.connection.logger.logQuery(query, parameters, this)\n const queryStartTime = +new Date()\n let statement: any\n try {\n statement = databaseConnection.prepare(query)\n if (parameters) {\n parameters = parameters.map((p) =>\n typeof p !== \"undefined\" ? p : null,\n )\n\n statement.bind(parameters)\n }\n\n // log slow queries if maxQueryExecution time is set\n const maxQueryExecutionTime =\n this.driver.options.maxQueryExecutionTime\n const queryEndTime = +new Date()\n const queryExecutionTime = queryEndTime - queryStartTime\n if (\n maxQueryExecutionTime &&\n queryExecutionTime > maxQueryExecutionTime\n )\n this.driver.connection.logger.logQuerySlow(\n queryExecutionTime,\n query,\n parameters,\n this,\n )\n\n const records: any[] = []\n\n while (statement.step()) {\n records.push(statement.getAsObject())\n }\n\n const result = new QueryResult()\n\n result.affected = databaseConnection.getRowsModified()\n result.records = records\n result.raw = records\n\n statement.free()\n\n if (command !== \"SELECT\") {\n this.isDirty = true\n }\n\n if (useStructuredResult) {\n return result\n } else {\n return result.raw\n }\n } catch (e) {\n if (statement) {\n statement.free()\n }\n\n this.driver.connection.logger.logQueryError(\n e,\n query,\n parameters,\n this,\n )\n throw new QueryFailedError(query, parameters, e)\n }\n }\n}\n"],"sourceRoot":"../.."}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/driver/sqlserver/SqlServerConnectionOptions.ts"],"names":[],"mappings":"","file":"SqlServerConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { SqlServerConnectionCredentialsOptions } from \"./SqlServerConnectionCredentialsOptions\"\n\n/**\n * Microsoft Sql Server specific connection options.\n */\nexport interface SqlServerConnectionOptions\n extends BaseDataSourceOptions,\n SqlServerConnectionCredentialsOptions {\n /**\n * Database type.\n */\n readonly type: \"mssql\"\n\n /**\n * Connection timeout in ms (default: 15000).\n */\n readonly connectionTimeout?: number\n\n /**\n * Request timeout in ms (default: 15000). NOTE: msnodesqlv8 driver doesn't support timeouts < 1 second.\n */\n readonly requestTimeout?: number\n\n /**\n * Stream recordsets/rows instead of returning them all at once as an argument of callback (default: false).\n * You can also enable streaming for each request independently (request.stream = true).\n * Always set to true if you plan to work with large amount of rows.\n */\n readonly stream?: boolean\n\n /**\n * Database schema.\n */\n readonly schema?: string\n\n /**\n * The driver object\n * This defaults to `require(\"mssql\")`\n */\n readonly driver?: any\n\n /**\n * An optional object/dictionary with the any of the properties\n */\n readonly pool?: {\n /**\n * Maximum number of resources to create at any given time. (default=1)\n */\n readonly max?: number\n\n /**\n * Minimum number of resources to keep in pool at any given time. If this is set >= max, the pool will silently\n * set the min to equal max. (default=0)\n */\n readonly min?: number\n\n /**\n * Maximum number of queued requests allowed, additional acquire calls will be callback with an err in a future\n * cycle of the event loop.\n */\n readonly maxWaitingClients?: number\n\n /**\n * Should the pool validate resources before giving them to clients. Requires that either factory.validate or\n * factory.validateAsync to be specified\n */\n readonly testOnBorrow?: boolean\n\n /**\n * Max milliseconds an acquire call will wait for a resource before timing out. (default no limit), if supplied should non-zero positive integer.\n */\n readonly acquireTimeoutMillis?: number\n\n /**\n * If true the oldest resources will be first to be allocated. If false the most recently released resources will\n * be the first to be allocated. This in effect turns the pool's behaviour from a queue into a stack. boolean,\n * (default true)\n */\n readonly fifo?: boolean\n\n /**\n * Int between 1 and x - if set, borrowers can specify their relative priority in the queue if no resources\n * are available. see example. (default 1)\n */\n readonly priorityRange?: number\n\n /**\n * How often to run eviction checks. Default: 0 (does not run).\n */\n readonly evictionRunIntervalMillis?: number\n\n /**\n * Number of resources to check each eviction run. Default: 3.\n */\n readonly numTestsPerRun?: number\n\n /**\n * Amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object\n * evictor (if any), with the extra condition that at least \"min idle\" object instances remain in the pool.\n * Default -1 (nothing can get evicted)\n */\n readonly softIdleTimeoutMillis?: number\n\n /**\n * The minimum amount of time that an object may sit idle in the pool before it is eligible for eviction due\n * to idle time. Supercedes softIdleTimeoutMillis Default: 30000\n */\n readonly idleTimeoutMillis?: number\n\n /*\n * Function handling errors thrown by drivers pool.\n * Defaults to logging error with `warn` level.\n */\n readonly errorHandler?: (err: any) => any\n }\n\n /**\n * Extra options\n */\n readonly options?: {\n /**\n * By default, if the database requestion by options.database cannot be accessed, the connection will fail with\n * an error. However, if options.fallbackToDefaultDb is set to true, then the user's default database will\n * be used instead (Default: false).\n */\n readonly fallbackToDefaultDb?: boolean\n\n /**\n * If true, SET ANSI_NULL_DFLT_ON ON will be set in the initial sql. This means new columns will be nullable by\n * default. See the T-SQL documentation for more details. (Default: true).\n */\n readonly enableAnsiNullDefault?: boolean\n\n /**\n * The number of milliseconds before the attempt to connect is considered failed (default: 15000).\n */\n readonly connectTimeout?: number\n\n /**\n * The number of milliseconds before the cancel (abort) of a request is considered failed (default: 5000).\n */\n readonly cancelTimeout?: number\n\n /**\n * The size of TDS packets (subject to negotiation with the server). Should be a power of 2. (default: 4096).\n */\n readonly packetSize?: number\n\n /**\n * A boolean determining whether to pass time values in UTC or local time. (default: false).\n */\n readonly useUTC?: boolean\n\n /**\n * A boolean determining whether to rollback a transaction automatically if any error is encountered during\n * the given transaction's execution. This sets the value for SET XACT_ABORT during the initial SQL phase\n * of a connection (documentation).\n */\n readonly abortTransactionOnError?: boolean\n\n /**\n * A string indicating which network interface (ip address) to use when connecting to SQL Server.\n */\n readonly localAddress?: string\n\n /**\n * A boolean determining whether to return rows as arrays or key-value collections. (default: false).\n */\n readonly useColumnNames?: boolean\n\n /**\n * A boolean, controlling whether the column names returned will have the first letter converted to lower case\n * (true) or not. This value is ignored if you provide a columnNameReplacer. (default: false).\n */\n readonly camelCaseColumns?: boolean\n\n /**\n * A boolean, controlling whatever to disable RETURNING / OUTPUT statements.\n */\n readonly disableOutputReturning?: boolean\n\n /**\n * Debug options\n */\n readonly debug?: {\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet details\n * (default: false).\n */\n readonly packet?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet data details\n * (default: false).\n */\n readonly data?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet payload details\n * (default: false).\n */\n readonly payload?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing token stream tokens\n * (default: false).\n */\n readonly token?: boolean\n }\n\n /**\n * The default isolation level that transactions will be run with. The isolation levels are available\n * from require('tedious').ISOLATION_LEVEL. (default: READ_COMMITTED).\n */\n readonly isolation?:\n | \"READ_UNCOMMITTED\"\n | \"READ_COMMITTED\"\n | \"REPEATABLE_READ\"\n | \"SERIALIZABLE\"\n | \"SNAPSHOT\"\n\n /**\n * The default isolation level for new connections. All out-of-transaction queries are executed with this\n * setting. The isolation levels are available from require('tedious').ISOLATION_LEVEL .\n */\n readonly connectionIsolationLevel?:\n | \"READ_UNCOMMITTED\"\n | \"READ_COMMITTED\"\n | \"REPEATABLE_READ\"\n | \"SERIALIZABLE\"\n | \"SNAPSHOT\"\n\n /**\n * A boolean, determining whether the connection will request read only access from a SQL Server\n * Availability Group. For more information, see here. (default: false).\n */\n readonly readOnlyIntent?: boolean\n\n /**\n * A boolean determining whether or not the connection will be encrypted. Set to true if you're on\n * Windows Azure. (default: true).\n */\n readonly encrypt?: boolean\n\n /**\n * When encryption is used, an object may be supplied that will be used for the first argument when calling\n * tls.createSecurePair (default: {}).\n */\n readonly cryptoCredentialsDetails?: any\n\n /**\n * A boolean, that when true will expose received rows in Requests' done* events. See done, doneInProc and\n * doneProc. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnDone?: boolean\n\n /**\n * A boolean, that when true will expose received rows in Requests' completion callback. See new Request. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnRequestCompletion?: boolean\n\n /**\n * The version of TDS to use. If server doesn't support specified version, negotiated version is used instead.\n * The versions are available from require('tedious').TDS_VERSION. (default: 7_4).\n */\n readonly tdsVersion?: string\n\n /**\n * A boolean, that when true will abort a query when an overflow or divide-by-zero error occurs during query execution.\n */\n readonly enableArithAbort?: boolean\n\n /**\n * Application name used for identifying a specific application in profiling, logging or tracing tools of SQL Server.\n * (default: node-mssql)\n */\n readonly appName?: string\n }\n\n /**\n * Replication setup.\n */\n readonly replication?: {\n /**\n * Master server used by orm to perform writes.\n */\n readonly master: SqlServerConnectionCredentialsOptions\n\n /**\n * List of read-from severs (slaves).\n */\n readonly slaves: SqlServerConnectionCredentialsOptions[]\n }\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../../src/driver/sqlserver/SqlServerConnectionOptions.ts"],"names":[],"mappings":"","file":"SqlServerConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { SqlServerConnectionCredentialsOptions } from \"./SqlServerConnectionCredentialsOptions\"\n\n/**\n * Microsoft Sql Server specific connection options.\n */\nexport interface SqlServerConnectionOptions\n extends BaseDataSourceOptions,\n SqlServerConnectionCredentialsOptions {\n /**\n * Database type.\n */\n readonly type: \"mssql\"\n\n /**\n * Connection timeout in ms (default: 15000).\n */\n readonly connectionTimeout?: number\n\n /**\n * Request timeout in ms (default: 15000). NOTE: msnodesqlv8 driver doesn't support timeouts < 1 second.\n */\n readonly requestTimeout?: number\n\n /**\n * Stream recordsets/rows instead of returning them all at once as an argument of callback (default: false).\n * You can also enable streaming for each request independently (request.stream = true).\n * Always set to true if you plan to work with large amount of rows.\n */\n readonly stream?: boolean\n\n /**\n * Database schema.\n */\n readonly schema?: string\n\n /**\n * The driver object\n * This defaults to `require(\"mssql\")`\n */\n readonly driver?: any\n\n /**\n * An optional object/dictionary with the any of the properties\n */\n readonly pool?: {\n /**\n * Maximum number of resources to create at any given time. (default=1)\n */\n readonly max?: number\n\n /**\n * Minimum number of resources to keep in pool at any given time. If this is set >= max, the pool will silently\n * set the min to equal max. (default=0)\n */\n readonly min?: number\n\n /**\n * Maximum number of queued requests allowed, additional acquire calls will be callback with an err in a future\n * cycle of the event loop.\n */\n readonly maxWaitingClients?: number\n\n /**\n * Should the pool validate resources before giving them to clients. Requires that either factory.validate or\n * factory.validateAsync to be specified\n */\n readonly testOnBorrow?: boolean\n\n /**\n * Max milliseconds an acquire call will wait for a resource before timing out. (default no limit), if supplied should non-zero positive integer.\n */\n readonly acquireTimeoutMillis?: number\n\n /**\n * If true the oldest resources will be first to be allocated. If false the most recently released resources will\n * be the first to be allocated. This in effect turns the pool's behaviour from a queue into a stack. boolean,\n * (default true)\n */\n readonly fifo?: boolean\n\n /**\n * Int between 1 and x - if set, borrowers can specify their relative priority in the queue if no resources\n * are available. see example. (default 1)\n */\n readonly priorityRange?: number\n\n /**\n * How often to run eviction checks. Default: 0 (does not run).\n */\n readonly evictionRunIntervalMillis?: number\n\n /**\n * Number of resources to check each eviction run. Default: 3.\n */\n readonly numTestsPerRun?: number\n\n /**\n * Amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object\n * evictor (if any), with the extra condition that at least \"min idle\" object instances remain in the pool.\n * Default -1 (nothing can get evicted)\n */\n readonly softIdleTimeoutMillis?: number\n\n /**\n * The minimum amount of time that an object may sit idle in the pool before it is eligible for eviction due\n * to idle time. Supercedes softIdleTimeoutMillis Default: 30000\n */\n readonly idleTimeoutMillis?: number\n\n /*\n * Function handling errors thrown by drivers pool.\n * Defaults to logging error with `warn` level.\n */\n readonly errorHandler?: (err: any) => any\n }\n\n /**\n * Extra options\n */\n readonly options?: {\n /**\n * By default, if the database requestion by options.database cannot be accessed, the connection will fail with\n * an error. However, if options.fallbackToDefaultDb is set to true, then the user's default database will\n * be used instead (Default: false).\n */\n readonly fallbackToDefaultDb?: boolean\n\n /**\n * If true, SET ANSI_NULL_DFLT_ON ON will be set in the initial sql. This means new columns will be nullable by\n * default. See the T-SQL documentation for more details. (Default: true).\n */\n readonly enableAnsiNullDefault?: boolean\n\n /**\n * The number of milliseconds before the attempt to connect is considered failed (default: 15000).\n */\n readonly connectTimeout?: number\n\n /**\n * The number of milliseconds before the cancel (abort) of a request is considered failed (default: 5000).\n */\n readonly cancelTimeout?: number\n\n /**\n * The size of TDS packets (subject to negotiation with the server). Should be a power of 2. (default: 4096).\n */\n readonly packetSize?: number\n\n /**\n * A boolean determining whether to pass time values in UTC or local time. (default: false).\n */\n readonly useUTC?: boolean\n\n /**\n * A boolean determining whether to rollback a transaction automatically if any error is encountered during\n * the given transaction's execution. This sets the value for SET XACT_ABORT during the initial SQL phase\n * of a connection (documentation).\n */\n readonly abortTransactionOnError?: boolean\n\n /**\n * A string indicating which network interface (ip address) to use when connecting to SQL Server.\n */\n readonly localAddress?: string\n\n /**\n * A boolean determining whether to return rows as arrays or key-value collections. (default: false).\n */\n readonly useColumnNames?: boolean\n\n /**\n * A boolean, controlling whether the column names returned will have the first letter converted to lower case\n * (true) or not. This value is ignored if you provide a columnNameReplacer. (default: false).\n */\n readonly camelCaseColumns?: boolean\n\n /**\n * A boolean, controlling whatever to disable RETURNING / OUTPUT statements.\n */\n readonly disableOutputReturning?: boolean\n\n /**\n * Debug options\n */\n readonly debug?: {\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet details\n * (default: false).\n */\n readonly packet?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet data details\n * (default: false).\n */\n readonly data?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet payload details\n * (default: false).\n */\n readonly payload?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing token stream tokens\n * (default: false).\n */\n readonly token?: boolean\n }\n\n /**\n * The default isolation level that transactions will be run with. The isolation levels are available\n * from require('tedious').ISOLATION_LEVEL. (default: READ_COMMITTED).\n */\n readonly isolation?:\n | \"READ_UNCOMMITTED\"\n | \"READ_COMMITTED\"\n | \"REPEATABLE_READ\"\n | \"SERIALIZABLE\"\n | \"SNAPSHOT\"\n\n /**\n * The default isolation level for new connections. All out-of-transaction queries are executed with this\n * setting. The isolation levels are available from require('tedious').ISOLATION_LEVEL .\n */\n readonly connectionIsolationLevel?:\n | \"READ_UNCOMMITTED\"\n | \"READ_COMMITTED\"\n | \"REPEATABLE_READ\"\n | \"SERIALIZABLE\"\n | \"SNAPSHOT\"\n\n /**\n * A boolean, determining whether the connection will request read only access from a SQL Server\n * Availability Group. For more information, see here. (default: false).\n */\n readonly readOnlyIntent?: boolean\n\n /**\n * A boolean determining whether or not the connection will be encrypted. Set to true if you're on\n * Windows Azure. (default: true).\n */\n readonly encrypt?: boolean\n\n /**\n * When encryption is used, an object may be supplied that will be used for the first argument when calling\n * tls.createSecurePair (default: {}).\n */\n readonly cryptoCredentialsDetails?: any\n\n /**\n * A boolean, that when true will expose received rows in Requests' done* events. See done, doneInProc and\n * doneProc. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnDone?: boolean\n\n /**\n * A boolean, that when true will expose received rows in Requests' completion callback. See new Request. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnRequestCompletion?: boolean\n\n /**\n * The version of TDS to use. If server doesn't support specified version, negotiated version is used instead.\n * The versions are available from require('tedious').TDS_VERSION. (default: 7_4).\n */\n readonly tdsVersion?: string\n\n /**\n * A boolean, that when true will abort a query when an overflow or divide-by-zero error occurs during query execution.\n */\n readonly enableArithAbort?: boolean\n\n /**\n * Application name used for identifying a specific application in profiling, logging or tracing tools of SQL Server.\n * (default: node-mssql)\n */\n readonly appName?: string\n }\n\n /**\n * Replication setup.\n */\n readonly replication?: {\n /**\n * Master server used by orm to perform writes.\n */\n readonly master: SqlServerConnectionCredentialsOptions\n\n /**\n * List of read-from severs (slaves).\n */\n readonly slaves: SqlServerConnectionCredentialsOptions[]\n }\n\n readonly poolSize?: never\n}\n"],"sourceRoot":"../.."}
|
|
@@ -66,7 +66,7 @@ export declare class EntityManager {
|
|
|
66
66
|
/**
|
|
67
67
|
* Creates a new query builder that can be used to build a SQL query.
|
|
68
68
|
*/
|
|
69
|
-
createQueryBuilder<Entity>(entityClass: EntityTarget<Entity>, alias: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>;
|
|
69
|
+
createQueryBuilder<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, alias: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>;
|
|
70
70
|
/**
|
|
71
71
|
* Creates a new query builder that can be used to build a SQL query.
|
|
72
72
|
*/
|
|
@@ -197,8 +197,8 @@ export declare class EntityManager {
|
|
|
197
197
|
* Does not check if entity exist in the database, so query will fail if duplicate entity is being inserted.
|
|
198
198
|
* You can execute bulk inserts using this method.
|
|
199
199
|
*/
|
|
200
|
-
insert<Entity>(target: EntityTarget<Entity>, entity: QueryDeepPartialEntity<Entity> | QueryDeepPartialEntity<Entity>[]): Promise<InsertResult>;
|
|
201
|
-
upsert<Entity>(target: EntityTarget<Entity>, entityOrEntities: QueryDeepPartialEntity<Entity> | QueryDeepPartialEntity<Entity>[], conflictPathsOrOptions: string[] | UpsertOptions<Entity>): Promise<InsertResult>;
|
|
200
|
+
insert<Entity extends ObjectLiteral>(target: EntityTarget<Entity>, entity: QueryDeepPartialEntity<Entity> | QueryDeepPartialEntity<Entity>[]): Promise<InsertResult>;
|
|
201
|
+
upsert<Entity extends ObjectLiteral>(target: EntityTarget<Entity>, entityOrEntities: QueryDeepPartialEntity<Entity> | QueryDeepPartialEntity<Entity>[], conflictPathsOrOptions: string[] | UpsertOptions<Entity>): Promise<InsertResult>;
|
|
202
202
|
/**
|
|
203
203
|
* Updates entity partially. Entity can be found by a given condition(s).
|
|
204
204
|
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
|
|
@@ -206,7 +206,7 @@ export declare class EntityManager {
|
|
|
206
206
|
* Does not check if entity exist in the database.
|
|
207
207
|
* Condition(s) cannot be empty.
|
|
208
208
|
*/
|
|
209
|
-
update<Entity>(target: EntityTarget<Entity>, criteria: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[] | any, partialEntity: QueryDeepPartialEntity<Entity>): Promise<UpdateResult>;
|
|
209
|
+
update<Entity extends ObjectLiteral>(target: EntityTarget<Entity>, criteria: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[] | any, partialEntity: QueryDeepPartialEntity<Entity>): Promise<UpdateResult>;
|
|
210
210
|
/**
|
|
211
211
|
* Deletes entities by a given condition(s).
|
|
212
212
|
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
|
|
@@ -214,7 +214,7 @@ export declare class EntityManager {
|
|
|
214
214
|
* Does not check if entity exist in the database.
|
|
215
215
|
* Condition(s) cannot be empty.
|
|
216
216
|
*/
|
|
217
|
-
delete<Entity>(targetOrEntity: EntityTarget<Entity>, criteria: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[] | any): Promise<DeleteResult>;
|
|
217
|
+
delete<Entity extends ObjectLiteral>(targetOrEntity: EntityTarget<Entity>, criteria: string | string[] | number | number[] | Date | Date[] | ObjectID | ObjectID[] | any): Promise<DeleteResult>;
|
|
218
218
|
/**
|
|
219
219
|
* Records the delete date of entities by a given condition(s).
|
|
220
220
|
* Unlike save method executes a primitive operation without cascades, relations and other operations included.
|
|
@@ -235,32 +235,32 @@ export declare class EntityManager {
|
|
|
235
235
|
* Counts entities that match given options.
|
|
236
236
|
* Useful for pagination.
|
|
237
237
|
*/
|
|
238
|
-
count<Entity>(entityClass: EntityTarget<Entity>, options?: FindManyOptions<Entity>): Promise<number>;
|
|
238
|
+
count<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, options?: FindManyOptions<Entity>): Promise<number>;
|
|
239
239
|
/**
|
|
240
240
|
* Counts entities that match given conditions.
|
|
241
241
|
* Useful for pagination.
|
|
242
242
|
*/
|
|
243
|
-
countBy<Entity>(entityClass: EntityTarget<Entity>, where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<number>;
|
|
243
|
+
countBy<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<number>;
|
|
244
244
|
/**
|
|
245
245
|
* Finds entities that match given find options.
|
|
246
246
|
*/
|
|
247
|
-
find<Entity>(entityClass: EntityTarget<Entity>, options?: FindManyOptions<Entity>): Promise<Entity[]>;
|
|
247
|
+
find<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, options?: FindManyOptions<Entity>): Promise<Entity[]>;
|
|
248
248
|
/**
|
|
249
249
|
* Finds entities that match given find options.
|
|
250
250
|
*/
|
|
251
|
-
findBy<Entity>(entityClass: EntityTarget<Entity>, where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<Entity[]>;
|
|
251
|
+
findBy<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<Entity[]>;
|
|
252
252
|
/**
|
|
253
253
|
* Finds entities that match given find options.
|
|
254
254
|
* Also counts all entities that match given conditions,
|
|
255
255
|
* but ignores pagination settings (from and take options).
|
|
256
256
|
*/
|
|
257
|
-
findAndCount<Entity>(entityClass: EntityTarget<Entity>, options?: FindManyOptions<Entity>): Promise<[Entity[], number]>;
|
|
257
|
+
findAndCount<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, options?: FindManyOptions<Entity>): Promise<[Entity[], number]>;
|
|
258
258
|
/**
|
|
259
259
|
* Finds entities that match given WHERE conditions.
|
|
260
260
|
* Also counts all entities that match given conditions,
|
|
261
261
|
* but ignores pagination settings (from and take options).
|
|
262
262
|
*/
|
|
263
|
-
findAndCountBy<Entity>(entityClass: EntityTarget<Entity>, where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<[Entity[], number]>;
|
|
263
|
+
findAndCountBy<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<[Entity[], number]>;
|
|
264
264
|
/**
|
|
265
265
|
* Finds entities with ids.
|
|
266
266
|
* Optionally find options or conditions can be applied.
|
|
@@ -271,17 +271,17 @@ export declare class EntityManager {
|
|
|
271
271
|
* id: In([1, 2, 3])
|
|
272
272
|
* })
|
|
273
273
|
*/
|
|
274
|
-
findByIds<Entity>(entityClass: EntityTarget<Entity>, ids: any[]): Promise<Entity[]>;
|
|
274
|
+
findByIds<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, ids: any[]): Promise<Entity[]>;
|
|
275
275
|
/**
|
|
276
276
|
* Finds first entity by a given find options.
|
|
277
277
|
* If entity was not found in the database - returns null.
|
|
278
278
|
*/
|
|
279
|
-
findOne<Entity>(entityClass: EntityTarget<Entity>, options: FindOneOptions<Entity>): Promise<Entity | null>;
|
|
279
|
+
findOne<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, options: FindOneOptions<Entity>): Promise<Entity | null>;
|
|
280
280
|
/**
|
|
281
281
|
* Finds first entity that matches given where condition.
|
|
282
282
|
* If entity was not found in the database - returns null.
|
|
283
283
|
*/
|
|
284
|
-
findOneBy<Entity>(entityClass: EntityTarget<Entity>, where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<Entity | null>;
|
|
284
|
+
findOneBy<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<Entity | null>;
|
|
285
285
|
/**
|
|
286
286
|
* Finds first entity that matches given id.
|
|
287
287
|
* If entity was not found in the database - returns null.
|
|
@@ -292,17 +292,17 @@ export declare class EntityManager {
|
|
|
292
292
|
* id: 1 // where "id" is your primary column name
|
|
293
293
|
* })
|
|
294
294
|
*/
|
|
295
|
-
findOneById<Entity>(entityClass: EntityTarget<Entity>, id: number | string | Date | ObjectID): Promise<Entity | null>;
|
|
295
|
+
findOneById<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, id: number | string | Date | ObjectID): Promise<Entity | null>;
|
|
296
296
|
/**
|
|
297
297
|
* Finds first entity by a given find options.
|
|
298
298
|
* If entity was not found in the database - rejects with error.
|
|
299
299
|
*/
|
|
300
|
-
findOneOrFail<Entity>(entityClass: EntityTarget<Entity>, options: FindOneOptions<Entity>): Promise<Entity>;
|
|
300
|
+
findOneOrFail<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, options: FindOneOptions<Entity>): Promise<Entity>;
|
|
301
301
|
/**
|
|
302
302
|
* Finds first entity that matches given where condition.
|
|
303
303
|
* If entity was not found in the database - rejects with error.
|
|
304
304
|
*/
|
|
305
|
-
findOneByOrFail<Entity>(entityClass: EntityTarget<Entity>, where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<Entity>;
|
|
305
|
+
findOneByOrFail<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[]): Promise<Entity>;
|
|
306
306
|
/**
|
|
307
307
|
* Clears all the data from the given table (truncates/drops it).
|
|
308
308
|
*
|
|
@@ -313,11 +313,11 @@ export declare class EntityManager {
|
|
|
313
313
|
/**
|
|
314
314
|
* Increments some column by provided value of the entities matched given conditions.
|
|
315
315
|
*/
|
|
316
|
-
increment<Entity>(entityClass: EntityTarget<Entity>, conditions: any, propertyPath: string, value: number | string): Promise<UpdateResult>;
|
|
316
|
+
increment<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, conditions: any, propertyPath: string, value: number | string): Promise<UpdateResult>;
|
|
317
317
|
/**
|
|
318
318
|
* Decrements some column by provided value of the entities matched given conditions.
|
|
319
319
|
*/
|
|
320
|
-
decrement<Entity>(entityClass: EntityTarget<Entity>, conditions: any, propertyPath: string, value: number | string): Promise<UpdateResult>;
|
|
320
|
+
decrement<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, conditions: any, propertyPath: string, value: number | string): Promise<UpdateResult>;
|
|
321
321
|
/**
|
|
322
322
|
* Gets repository for the given entity class or name.
|
|
323
323
|
* If single database connection mode is used, then repository is obtained from the
|
|
@@ -341,7 +341,7 @@ export declare class EntityManager {
|
|
|
341
341
|
* sets current EntityManager instance to it. Used to work with custom repositories
|
|
342
342
|
* in transactions.
|
|
343
343
|
*/
|
|
344
|
-
withRepository<Entity extends ObjectLiteral, R extends Repository<
|
|
344
|
+
withRepository<Entity extends ObjectLiteral, R extends Repository<any>>(repository: R & Repository<Entity>): R;
|
|
345
345
|
/**
|
|
346
346
|
* Gets custom entity repository marked with @EntityRepository decorator.
|
|
347
347
|
*
|