typeorm 0.2.42-dev.93bf96e → 0.2.42-dev.9e844d9
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/connection/BaseConnectionOptions.js.map +1 -1
- package/browser/connection/Connection.js +33 -24
- package/browser/connection/Connection.js.map +1 -1
- package/browser/connection/ConnectionOptionsReader.js +3 -1
- package/browser/connection/ConnectionOptionsReader.js.map +1 -1
- package/browser/driver/better-sqlite3/BetterSqlite3Driver.d.ts +14 -1
- package/browser/driver/better-sqlite3/BetterSqlite3Driver.js +87 -4
- package/browser/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
- package/browser/driver/better-sqlite3/BetterSqlite3QueryRunner.d.ts +10 -0
- package/browser/driver/better-sqlite3/BetterSqlite3QueryRunner.js +64 -1
- package/browser/driver/better-sqlite3/BetterSqlite3QueryRunner.js.map +1 -1
- package/browser/driver/capacitor/CapacitorQueryRunner.d.ts +8 -0
- package/browser/driver/capacitor/CapacitorQueryRunner.js +30 -0
- package/browser/driver/capacitor/CapacitorQueryRunner.js.map +1 -1
- package/browser/driver/cordova/CordovaQueryRunner.d.ts +8 -0
- package/browser/driver/cordova/CordovaQueryRunner.js +30 -0
- package/browser/driver/cordova/CordovaQueryRunner.js.map +1 -1
- package/browser/driver/expo/ExpoQueryRunner.d.ts +8 -0
- package/browser/driver/expo/ExpoQueryRunner.js +30 -0
- package/browser/driver/expo/ExpoQueryRunner.js.map +1 -1
- package/browser/driver/mongodb/MongoQueryRunner.d.ts +8 -0
- package/browser/driver/mongodb/MongoQueryRunner.js +20 -0
- package/browser/driver/mongodb/MongoQueryRunner.js.map +1 -1
- package/browser/driver/nativescript/NativescriptQueryRunner.d.ts +8 -0
- package/browser/driver/nativescript/NativescriptQueryRunner.js +30 -0
- package/browser/driver/nativescript/NativescriptQueryRunner.js.map +1 -1
- package/browser/driver/react-native/ReactNativeQueryRunner.d.ts +8 -0
- package/browser/driver/react-native/ReactNativeQueryRunner.js +30 -0
- package/browser/driver/react-native/ReactNativeQueryRunner.js.map +1 -1
- package/browser/driver/sqlite/SqliteDriver.d.ts +13 -0
- package/browser/driver/sqlite/SqliteDriver.js +84 -1
- package/browser/driver/sqlite/SqliteDriver.js.map +1 -1
- package/browser/driver/sqlite/SqliteQueryRunner.d.ts +8 -0
- package/browser/driver/sqlite/SqliteQueryRunner.js +30 -0
- package/browser/driver/sqlite/SqliteQueryRunner.js.map +1 -1
- package/browser/driver/sqlite-abstract/AbstractSqliteDriver.d.ts +13 -0
- package/browser/driver/sqlite-abstract/AbstractSqliteDriver.js +25 -2
- package/browser/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
- package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.d.ts +11 -1
- package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +116 -55
- package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
- package/browser/driver/sqljs/SqljsQueryRunner.d.ts +8 -0
- package/browser/driver/sqljs/SqljsQueryRunner.js +30 -0
- package/browser/driver/sqljs/SqljsQueryRunner.js.map +1 -1
- package/browser/metadata-builder/EntityMetadataValidator.js +1 -1
- package/browser/metadata-builder/EntityMetadataValidator.js.map +1 -1
- package/browser/migration/MigrationExecutor.js +37 -25
- package/browser/migration/MigrationExecutor.js.map +1 -1
- package/browser/persistence/SubjectExecutor.d.ts +2 -0
- package/browser/persistence/SubjectExecutor.js +99 -7
- package/browser/persistence/SubjectExecutor.js.map +1 -1
- package/browser/persistence/tree/MaterializedPathSubjectExecutor.js +1 -1
- package/browser/persistence/tree/MaterializedPathSubjectExecutor.js.map +1 -1
- package/browser/query-builder/InsertQueryBuilder.js +9 -0
- package/browser/query-builder/InsertQueryBuilder.js.map +1 -1
- package/browser/query-builder/relation-id/RelationIdLoader.js +9 -9
- package/browser/query-builder/relation-id/RelationIdLoader.js.map +1 -1
- package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.d.ts +13 -0
- package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js +94 -50
- package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
- package/browser/query-runner/BaseQueryRunner.d.ts +8 -0
- package/browser/query-runner/BaseQueryRunner.js +20 -0
- package/browser/query-runner/BaseQueryRunner.js.map +1 -1
- package/browser/query-runner/QueryRunner.d.ts +8 -0
- package/browser/query-runner/QueryRunner.js.map +1 -1
- package/browser/schema-builder/RdbmsSchemaBuilder.js +36 -30
- package/browser/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
- package/browser/subscriber/Broadcaster.js +35 -31
- package/browser/subscriber/Broadcaster.js.map +1 -1
- package/browser/util/PathUtils.d.ts +10 -0
- package/browser/util/PathUtils.js +28 -0
- package/browser/util/PathUtils.js.map +1 -0
- package/connection/BaseConnectionOptions.js.map +1 -1
- package/connection/Connection.js +33 -24
- package/connection/Connection.js.map +1 -1
- package/connection/ConnectionOptionsReader.js +3 -1
- package/connection/ConnectionOptionsReader.js.map +1 -1
- package/driver/better-sqlite3/BetterSqlite3Driver.d.ts +14 -1
- package/driver/better-sqlite3/BetterSqlite3Driver.js +86 -3
- package/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
- package/driver/better-sqlite3/BetterSqlite3QueryRunner.d.ts +10 -0
- package/driver/better-sqlite3/BetterSqlite3QueryRunner.js +63 -0
- package/driver/better-sqlite3/BetterSqlite3QueryRunner.js.map +1 -1
- package/driver/capacitor/CapacitorQueryRunner.d.ts +8 -0
- package/driver/capacitor/CapacitorQueryRunner.js +30 -0
- package/driver/capacitor/CapacitorQueryRunner.js.map +1 -1
- package/driver/cordova/CordovaQueryRunner.d.ts +8 -0
- package/driver/cordova/CordovaQueryRunner.js +30 -0
- package/driver/cordova/CordovaQueryRunner.js.map +1 -1
- package/driver/expo/ExpoQueryRunner.d.ts +8 -0
- package/driver/expo/ExpoQueryRunner.js +30 -0
- package/driver/expo/ExpoQueryRunner.js.map +1 -1
- package/driver/mongodb/MongoQueryRunner.d.ts +8 -0
- package/driver/mongodb/MongoQueryRunner.js +20 -0
- package/driver/mongodb/MongoQueryRunner.js.map +1 -1
- package/driver/nativescript/NativescriptQueryRunner.d.ts +8 -0
- package/driver/nativescript/NativescriptQueryRunner.js +30 -0
- package/driver/nativescript/NativescriptQueryRunner.js.map +1 -1
- package/driver/react-native/ReactNativeQueryRunner.d.ts +8 -0
- package/driver/react-native/ReactNativeQueryRunner.js +30 -0
- package/driver/react-native/ReactNativeQueryRunner.js.map +1 -1
- package/driver/sqlite/SqliteDriver.d.ts +13 -0
- package/driver/sqlite/SqliteDriver.js +83 -0
- package/driver/sqlite/SqliteDriver.js.map +1 -1
- package/driver/sqlite/SqliteQueryRunner.d.ts +8 -0
- package/driver/sqlite/SqliteQueryRunner.js +30 -0
- package/driver/sqlite/SqliteQueryRunner.js.map +1 -1
- package/driver/sqlite-abstract/AbstractSqliteDriver.d.ts +13 -0
- package/driver/sqlite-abstract/AbstractSqliteDriver.js +25 -2
- package/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
- package/driver/sqlite-abstract/AbstractSqliteQueryRunner.d.ts +11 -1
- package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +116 -55
- package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
- package/driver/sqljs/SqljsQueryRunner.d.ts +8 -0
- package/driver/sqljs/SqljsQueryRunner.js +30 -0
- package/driver/sqljs/SqljsQueryRunner.js.map +1 -1
- package/metadata-builder/EntityMetadataValidator.js +1 -1
- package/metadata-builder/EntityMetadataValidator.js.map +1 -1
- package/migration/MigrationExecutor.js +37 -25
- package/migration/MigrationExecutor.js.map +1 -1
- package/package.json +1 -1
- package/persistence/SubjectExecutor.d.ts +2 -0
- package/persistence/SubjectExecutor.js +99 -7
- package/persistence/SubjectExecutor.js.map +1 -1
- package/persistence/tree/MaterializedPathSubjectExecutor.js +1 -1
- package/persistence/tree/MaterializedPathSubjectExecutor.js.map +1 -1
- package/query-builder/InsertQueryBuilder.js +9 -0
- package/query-builder/InsertQueryBuilder.js.map +1 -1
- package/query-builder/relation-id/RelationIdLoader.js +9 -9
- package/query-builder/relation-id/RelationIdLoader.js.map +1 -1
- package/query-builder/transformer/RawSqlResultsToEntityTransformer.d.ts +13 -0
- package/query-builder/transformer/RawSqlResultsToEntityTransformer.js +94 -50
- package/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
- package/query-runner/BaseQueryRunner.d.ts +8 -0
- package/query-runner/BaseQueryRunner.js +20 -0
- package/query-runner/BaseQueryRunner.js.map +1 -1
- package/query-runner/QueryRunner.d.ts +8 -0
- package/query-runner/QueryRunner.js.map +1 -1
- package/schema-builder/RdbmsSchemaBuilder.js +36 -30
- package/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
- package/subscriber/Broadcaster.js +35 -31
- package/subscriber/Broadcaster.js.map +1 -1
- package/util/PathUtils.d.ts +10 -0
- package/util/PathUtils.js +34 -0
- package/util/PathUtils.js.map +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/connection/BaseConnectionOptions.ts"],"names":[],"mappings":"","file":"BaseConnectionOptions.js","sourcesContent":["import {EntitySchema} from \"../entity-schema/EntitySchema\";\nimport {LoggerOptions} from \"../logger/LoggerOptions\";\nimport {NamingStrategyInterface} from \"../naming-strategy/NamingStrategyInterface\";\nimport {DatabaseType} from \"../driver/types/DatabaseType\";\nimport {Logger} from \"../logger/Logger\";\nimport {Connection} from \"./Connection\";\nimport {QueryResultCache} from \"../cache/QueryResultCache\";\n\n/**\n * BaseConnectionOptions is set of connection options shared by all database types.\n */\nexport interface BaseConnectionOptions {\n\n /**\n * Database type. This value is required.\n */\n readonly type: DatabaseType;\n\n /**\n * Connection name. If connection name is not given then it will be called \"default\".\n * Different connections must have different names.\n */\n readonly name?: string;\n\n /**\n * Entities to be loaded for this connection.\n * Accepts both entity classes and directories where from entities need to be loaded.\n * Directories support glob patterns.\n */\n readonly entities?: ((Function|string|EntitySchema<any>))[];\n\n /**\n * Subscribers to be loaded for this connection.\n * Accepts both subscriber classes and directories where from subscribers need to be loaded.\n * Directories support glob patterns.\n */\n readonly subscribers?: (Function|string)[];\n\n /**\n * Migrations to be loaded for this connection.\n * Accepts both migration classes and directories where from migrations need to be loaded.\n * Directories support glob patterns.\n */\n readonly migrations?: (Function|string)[];\n\n /**\n * Migrations table name, in case of different name from \"migrations\".\n * Accepts single string name.\n */\n readonly migrationsTableName?: string;\n\n /**\n * Transaction mode for migrations to run in\n */\n readonly migrationsTransactionMode?: \"all\" | \"none\" | \"each\";\n\n /**\n * Typeorm metadata table name, in case of different name from \"typeorm_metadata\".\n * Accepts single string name.\n */\n readonly metadataTableName?: string;\n\n /**\n * Naming strategy to be used to name tables and columns in the database.\n */\n readonly namingStrategy?: NamingStrategyInterface;\n\n /**\n * Logging options.\n */\n readonly logging?: LoggerOptions;\n\n /**\n * Logger instance used to log queries and events in the ORM.\n */\n readonly logger?: \"advanced-console\"|\"simple-console\"|\"file\"|\"debug\"|Logger;\n\n /**\n * Maximum number of milliseconds query should be executed before logger log a warning.\n */\n readonly maxQueryExecutionTime?: number;\n\n /**\n * Indicates if database schema should be auto created on every application launch.\n * Be careful with this option and don't use this in production - otherwise you can lose production data.\n * This option is useful during debug and development.\n * Alternative to it, you can use CLI and run schema:sync command.\n *\n * Note that for MongoDB database it does not create schema, because MongoDB is schemaless.\n * Instead, it syncs just by creating indices.\n */\n readonly synchronize?: boolean;\n\n /**\n * Indicates if migrations should be auto run on every application launch.\n * Alternative to it, you can use CLI and run migrations:run command.\n */\n readonly migrationsRun?: boolean;\n\n /**\n * Drops the schema each time connection is being established.\n * Be careful with this option and don't use this in production - otherwise you'll lose all production data.\n * This option is useful during debug and development.\n */\n readonly dropSchema?: boolean;\n\n /**\n * Prefix to use on all tables (collections) of this connection in the database.\n */\n readonly entityPrefix?: string;\n\n /**\n * When creating new Entity instances, skip all constructors when true.\n */\n readonly entitySkipConstructor?: boolean;\n\n /**\n * Extra connection options to be passed to the underlying driver.\n *\n * todo: deprecate this and move all database-specific types into hts own connection options object.\n */\n readonly extra?: any;\n\n /**\n * Allows to setup cache options.\n */\n readonly cache?: boolean|{\n\n /**\n * Type of caching.\n *\n * - \"database\" means cached values will be stored in the separate table in database. This is default value.\n * - \"redis\" means cached values will be stored inside redis. You must provide redis connection options.\n */\n readonly type?: \"database\" | \"redis\" | \"ioredis\" | \"ioredis/cluster\"; // todo: add mongodb and other cache providers as well in the future\n\n /**\n * Factory function for custom cache providers that implement QueryResultCache.\n */\n readonly provider?: (connection: Connection) => QueryResultCache;\n\n /**\n * Configurable table name for \"database\" type cache.\n * Default value is \"query-result-cache\"\n */\n readonly tableName?: string;\n\n /**\n * Used to provide redis connection options.\n */\n readonly options?: any;\n\n /**\n * If set to true then queries (using find methods and QueryBuilder's methods) will always be cached.\n */\n readonly alwaysEnabled?: boolean;\n\n /**\n * Time in milliseconds in which cache will expire.\n * This can be setup per-query.\n * Default value is 1000 which is equivalent to 1 second.\n */\n readonly duration?: number;\n\n /**\n * Used to specify if cache errors should be ignored, and pass through the call to the Database.\n */\n readonly ignoreErrors?: boolean;\n };\n\n /**\n * CLI settings.\n */\n readonly cli?: {\n\n /**\n * Directory where entities should be created by default.\n */\n readonly entitiesDir?: string;\n\n /**\n * Directory where migrations should be created by default.\n */\n readonly migrationsDir?: string;\n\n /**\n * Directory where subscribers should be created by default.\n */\n readonly subscribersDir?: string;\n\n };\n\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/connection/BaseConnectionOptions.ts"],"names":[],"mappings":"","file":"BaseConnectionOptions.js","sourcesContent":["import {EntitySchema} from \"../entity-schema/EntitySchema\";\nimport {LoggerOptions} from \"../logger/LoggerOptions\";\nimport {NamingStrategyInterface} from \"../naming-strategy/NamingStrategyInterface\";\nimport {DatabaseType} from \"../driver/types/DatabaseType\";\nimport {Logger} from \"../logger/Logger\";\nimport {Connection} from \"./Connection\";\nimport {QueryResultCache} from \"../cache/QueryResultCache\";\n\n/**\n * BaseConnectionOptions is set of connection options shared by all database types.\n */\nexport interface BaseConnectionOptions {\n\n /**\n * Database type. This value is required.\n */\n readonly type: DatabaseType;\n\n /**\n * Connection name. If connection name is not given then it will be called \"default\".\n * Different connections must have different names.\n */\n readonly name?: string;\n\n /**\n * Entities to be loaded for this connection.\n * Accepts both entity classes and directories where from entities need to be loaded.\n * Directories support glob patterns.\n */\n readonly entities?: ((Function|string|EntitySchema<any>))[];\n\n /**\n * Subscribers to be loaded for this connection.\n * Accepts both subscriber classes and directories where from subscribers need to be loaded.\n * Directories support glob patterns.\n */\n readonly subscribers?: (Function|string)[];\n\n /**\n * Migrations to be loaded for this connection.\n * Accepts both migration classes and directories where from migrations need to be loaded.\n * Directories support glob patterns.\n */\n readonly migrations?: (Function|string)[];\n\n /**\n * Migrations table name, in case of different name from \"migrations\".\n * Accepts single string name.\n */\n readonly migrationsTableName?: string;\n\n /**\n * Transaction mode for migrations to run in\n */\n readonly migrationsTransactionMode?: \"all\" | \"none\" | \"each\";\n\n /**\n * Typeorm metadata table name, in case of different name from \"typeorm_metadata\".\n * Accepts single string name.\n */\n readonly metadataTableName?: string;\n\n /**\n * Naming strategy to be used to name tables and columns in the database.\n */\n readonly namingStrategy?: NamingStrategyInterface;\n\n /**\n * Logging options.\n */\n readonly logging?: LoggerOptions;\n\n /**\n * Logger instance used to log queries and events in the ORM.\n */\n readonly logger?: \"advanced-console\"|\"simple-console\"|\"file\"|\"debug\"|Logger;\n\n /**\n * Maximum number of milliseconds query should be executed before logger log a warning.\n */\n readonly maxQueryExecutionTime?: number;\n\n /**\n * Indicates if database schema should be auto created on every application launch.\n * Be careful with this option and don't use this in production - otherwise you can lose production data.\n * This option is useful during debug and development.\n * Alternative to it, you can use CLI and run schema:sync command.\n *\n * Note that for MongoDB database it does not create schema, because MongoDB is schemaless.\n * Instead, it syncs just by creating indices.\n */\n readonly synchronize?: boolean;\n\n /**\n * Indicates if migrations should be auto run on every application launch.\n * Alternative to it, you can use CLI and run migrations:run command.\n */\n readonly migrationsRun?: boolean;\n\n /**\n * Drops the schema each time connection is being established.\n * Be careful with this option and don't use this in production - otherwise you'll lose all production data.\n * This option is useful during debug and development.\n */\n readonly dropSchema?: boolean;\n\n /**\n * Prefix to use on all tables (collections) of this connection in the database.\n */\n readonly entityPrefix?: string;\n\n /**\n * When creating new Entity instances, skip all constructors when true.\n */\n readonly entitySkipConstructor?: boolean;\n\n /**\n * Extra connection options to be passed to the underlying driver.\n *\n * todo: deprecate this and move all database-specific types into hts own connection options object.\n */\n readonly extra?: any;\n\n /**\n * Holds reference to the baseDirectory where configuration file are expected\n * @internal\n */\n baseDirectory?: string;\n\n /**\n * Allows to setup cache options.\n */\n readonly cache?: boolean|{\n\n /**\n * Type of caching.\n *\n * - \"database\" means cached values will be stored in the separate table in database. This is default value.\n * - \"redis\" means cached values will be stored inside redis. You must provide redis connection options.\n */\n readonly type?: \"database\" | \"redis\" | \"ioredis\" | \"ioredis/cluster\"; // todo: add mongodb and other cache providers as well in the future\n\n /**\n * Factory function for custom cache providers that implement QueryResultCache.\n */\n readonly provider?: (connection: Connection) => QueryResultCache;\n\n /**\n * Configurable table name for \"database\" type cache.\n * Default value is \"query-result-cache\"\n */\n readonly tableName?: string;\n\n /**\n * Used to provide redis connection options.\n */\n readonly options?: any;\n\n /**\n * If set to true then queries (using find methods and QueryBuilder's methods) will always be cached.\n */\n readonly alwaysEnabled?: boolean;\n\n /**\n * Time in milliseconds in which cache will expire.\n * This can be setup per-query.\n * Default value is 1000 which is equivalent to 1 second.\n */\n readonly duration?: number;\n\n /**\n * Used to specify if cache errors should be ignored, and pass through the call to the Database.\n */\n readonly ignoreErrors?: boolean;\n };\n\n /**\n * CLI settings.\n */\n readonly cli?: {\n\n /**\n * Directory where entities should be created by default.\n */\n readonly entitiesDir?: string;\n\n /**\n * Directory where migrations should be created by default.\n */\n readonly migrationsDir?: string;\n\n /**\n * Directory where subscribers should be created by default.\n */\n readonly subscribersDir?: string;\n\n };\n\n}\n"],"sourceRoot":".."}
|
|
@@ -18,6 +18,7 @@ import { SqljsEntityManager } from "../entity-manager/SqljsEntityManager";
|
|
|
18
18
|
import { RelationLoader } from "../query-builder/RelationLoader";
|
|
19
19
|
import { EntitySchema } from "../entity-schema/EntitySchema";
|
|
20
20
|
import { SqlServerDriver } from "../driver/sqlserver/SqlServerDriver";
|
|
21
|
+
import { AbstractSqliteDriver } from "../driver/sqlite-abstract/AbstractSqliteDriver";
|
|
21
22
|
import { MysqlDriver } from "../driver/mysql/MysqlDriver";
|
|
22
23
|
import { ObjectUtils } from "../util/ObjectUtils";
|
|
23
24
|
import { AuroraDataApiDriver } from "../driver/aurora-data-api/AuroraDataApiDriver";
|
|
@@ -233,50 +234,58 @@ var Connection = /** @class */ (function () {
|
|
|
233
234
|
queryRunner = this.createQueryRunner();
|
|
234
235
|
_b.label = 1;
|
|
235
236
|
case 1:
|
|
236
|
-
_b.trys.push([1, ,
|
|
237
|
-
if (!(this.driver instanceof SqlServerDriver || this.driver instanceof MysqlDriver || this.driver instanceof AuroraDataApiDriver)) return [3 /*break*/,
|
|
238
|
-
databases_2 =
|
|
237
|
+
_b.trys.push([1, , 14, 16]);
|
|
238
|
+
if (!(this.driver instanceof SqlServerDriver || this.driver instanceof MysqlDriver || this.driver instanceof AuroraDataApiDriver || this.driver instanceof AbstractSqliteDriver)) return [3 /*break*/, 11];
|
|
239
|
+
databases_2 = [];
|
|
239
240
|
this.entityMetadatas.forEach(function (metadata) {
|
|
240
241
|
if (metadata.database && databases_2.indexOf(metadata.database) === -1)
|
|
241
242
|
databases_2.push(metadata.database);
|
|
242
243
|
});
|
|
243
|
-
|
|
244
|
+
if (databases_2.length === 0 && this.driver.database) {
|
|
245
|
+
databases_2.push(this.driver.database);
|
|
246
|
+
}
|
|
247
|
+
;
|
|
248
|
+
if (!(databases_2.length === 0)) return [3 /*break*/, 3];
|
|
249
|
+
return [4 /*yield*/, queryRunner.clearDatabase()];
|
|
244
250
|
case 2:
|
|
245
|
-
_b.
|
|
246
|
-
|
|
247
|
-
_b.label = 3;
|
|
251
|
+
_b.sent();
|
|
252
|
+
return [3 /*break*/, 10];
|
|
248
253
|
case 3:
|
|
249
|
-
|
|
254
|
+
_b.trys.push([3, 8, 9, 10]);
|
|
255
|
+
databases_1 = __values(databases_2), databases_1_1 = databases_1.next();
|
|
256
|
+
_b.label = 4;
|
|
257
|
+
case 4:
|
|
258
|
+
if (!!databases_1_1.done) return [3 /*break*/, 7];
|
|
250
259
|
database = databases_1_1.value;
|
|
251
260
|
return [4 /*yield*/, queryRunner.clearDatabase(database)];
|
|
252
|
-
case 4:
|
|
253
|
-
_b.sent();
|
|
254
|
-
_b.label = 5;
|
|
255
261
|
case 5:
|
|
262
|
+
_b.sent();
|
|
263
|
+
_b.label = 6;
|
|
264
|
+
case 6:
|
|
256
265
|
databases_1_1 = databases_1.next();
|
|
257
|
-
return [3 /*break*/,
|
|
258
|
-
case
|
|
259
|
-
case
|
|
266
|
+
return [3 /*break*/, 4];
|
|
267
|
+
case 7: return [3 /*break*/, 10];
|
|
268
|
+
case 8:
|
|
260
269
|
e_1_1 = _b.sent();
|
|
261
270
|
e_1 = { error: e_1_1 };
|
|
262
|
-
return [3 /*break*/,
|
|
263
|
-
case
|
|
271
|
+
return [3 /*break*/, 10];
|
|
272
|
+
case 9:
|
|
264
273
|
try {
|
|
265
274
|
if (databases_1_1 && !databases_1_1.done && (_a = databases_1.return)) _a.call(databases_1);
|
|
266
275
|
}
|
|
267
276
|
finally { if (e_1) throw e_1.error; }
|
|
268
277
|
return [7 /*endfinally*/];
|
|
269
|
-
case
|
|
270
|
-
case
|
|
271
|
-
case
|
|
278
|
+
case 10: return [3 /*break*/, 13];
|
|
279
|
+
case 11: return [4 /*yield*/, queryRunner.clearDatabase()];
|
|
280
|
+
case 12:
|
|
272
281
|
_b.sent();
|
|
273
|
-
_b.label =
|
|
274
|
-
case
|
|
275
|
-
case
|
|
276
|
-
case
|
|
282
|
+
_b.label = 13;
|
|
283
|
+
case 13: return [3 /*break*/, 16];
|
|
284
|
+
case 14: return [4 /*yield*/, queryRunner.release()];
|
|
285
|
+
case 15:
|
|
277
286
|
_b.sent();
|
|
278
287
|
return [7 /*endfinally*/];
|
|
279
|
-
case
|
|
288
|
+
case 16: return [2 /*return*/];
|
|
280
289
|
}
|
|
281
290
|
});
|
|
282
291
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/connection/Connection.ts"],"names":[],"mappings":";AAMA,OAAO,EAAC,qBAAqB,EAAC,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EAAC,8BAA8B,EAAC,MAAM,yCAAyC,CAAC;AACvF,OAAO,EAAC,kCAAkC,EAAC,MAAM,6CAA6C,CAAC;AAK/F,OAAO,EAAC,2BAA2B,EAAC,MAAM,sCAAsC,CAAC;AAEjF,OAAO,EAAC,iBAAiB,EAAC,MAAM,gCAAgC,CAAC;AAGjE,OAAO,EAAC,WAAW,EAAC,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAC,kBAAkB,EAAC,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAC,uBAAuB,EAAC,MAAM,6CAA6C,CAAC;AAEpF,OAAO,EAAC,uCAAuC,EAAC,MAAM,kDAAkD,CAAC;AACzG,OAAO,EAAC,oBAAoB,EAAC,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAC,aAAa,EAAC,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAC,yBAAyB,EAAC,MAAM,6BAA6B,CAAC;AAEtE,OAAO,EAAC,kBAAkB,EAAC,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAC,aAAa,EAAC,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAC,uBAAuB,EAAC,MAAM,kCAAkC,CAAC;AAEzE,OAAO,EAAC,kBAAkB,EAAC,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAC,cAAc,EAAC,MAAM,iCAAiC,CAAC;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AC;QACjB,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACa,mCAAc,GAA9B;;;;;;wBAEU,yBAAyB,GAAG,IAAI,yBAAyB,CAAC,IAAI,CAAC,CAAC;wBAChE,uBAAuB,GAAG,IAAI,uBAAuB,EAAE,CAAC;wBAG1C,qBAAM,yBAAyB,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC,EAAA;;wBAA9F,WAAW,GAAG,SAAgF;wBACpG,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC;wBAG/B,qBAAM,yBAAyB,CAAC,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAA;;wBAAnG,eAAe,GAAG,SAAiF;wBACzG,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,eAAe,EAAE,eAAe,EAAE,CAAC,CAAC;wBAG5C,qBAAM,yBAAyB,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC,EAAA;;wBAA3F,UAAU,GAAG,SAA8E;wBACjG,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;wBAErD,iGAAiG;wBACjG,uBAAuB,CAAC,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,UAAA,QAAQ,IAAI,OAAA,QAAQ,CAAC,SAAS,KAAK,MAAM,EAA7B,CAA6B,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;;;;;KAC7H;IACL,iBAAC;AAAD,CA9dA,AA8dC,IAAA","file":"Connection.js","sourcesContent":["import {Driver} from \"../driver/Driver\";\nimport {Repository} from \"../repository/Repository\";\nimport {EntitySubscriberInterface} from \"../subscriber/EntitySubscriberInterface\";\nimport {EntityTarget} from \"../common/EntityTarget\";\nimport {ObjectType} from \"../common/ObjectType\";\nimport {EntityManager} from \"../entity-manager/EntityManager\";\nimport {DefaultNamingStrategy} from \"../naming-strategy/DefaultNamingStrategy\";\nimport {CannotExecuteNotConnectedError} from \"../error/CannotExecuteNotConnectedError\";\nimport {CannotConnectAlreadyConnectedError} from \"../error/CannotConnectAlreadyConnectedError\";\nimport {TreeRepository} from \"../repository/TreeRepository\";\nimport {NamingStrategyInterface} from \"../naming-strategy/NamingStrategyInterface\";\nimport {EntityMetadata} from \"../metadata/EntityMetadata\";\nimport {Logger} from \"../logger/Logger\";\nimport {EntityMetadataNotFoundError} from \"../error/EntityMetadataNotFoundError\";\nimport {MigrationInterface} from \"../migration/MigrationInterface\";\nimport {MigrationExecutor} from \"../migration/MigrationExecutor\";\nimport {Migration} from \"../migration/Migration\";\nimport {MongoRepository} from \"../repository/MongoRepository\";\nimport {MongoDriver} from \"../driver/mongodb/MongoDriver\";\nimport {MongoEntityManager} from \"../entity-manager/MongoEntityManager\";\nimport {EntityMetadataValidator} from \"../metadata-builder/EntityMetadataValidator\";\nimport {ConnectionOptions} from \"./ConnectionOptions\";\nimport {QueryRunnerProviderAlreadyReleasedError} from \"../error/QueryRunnerProviderAlreadyReleasedError\";\nimport {EntityManagerFactory} from \"../entity-manager/EntityManagerFactory\";\nimport {DriverFactory} from \"../driver/DriverFactory\";\nimport {ConnectionMetadataBuilder} from \"./ConnectionMetadataBuilder\";\nimport {QueryRunner} from \"../query-runner/QueryRunner\";\nimport {SelectQueryBuilder} from \"../query-builder/SelectQueryBuilder\";\nimport {LoggerFactory} from \"../logger/LoggerFactory\";\nimport {QueryResultCacheFactory} from \"../cache/QueryResultCacheFactory\";\nimport {QueryResultCache} from \"../cache/QueryResultCache\";\nimport {SqljsEntityManager} from \"../entity-manager/SqljsEntityManager\";\nimport {RelationLoader} from \"../query-builder/RelationLoader\";\nimport {EntitySchema} from \"../entity-schema/EntitySchema\";\nimport {SqlServerDriver} from \"../driver/sqlserver/SqlServerDriver\";\nimport {MysqlDriver} from \"../driver/mysql/MysqlDriver\";\nimport {ObjectUtils} from \"../util/ObjectUtils\";\nimport {IsolationLevel} from \"../driver/types/IsolationLevel\";\nimport {AuroraDataApiDriver} from \"../driver/aurora-data-api/AuroraDataApiDriver\";\nimport {ReplicationMode} from \"../driver/types/ReplicationMode\";\nimport { TypeORMError } from \"../error/TypeORMError\";\n\n/**\n * Connection is a single database ORM connection to a specific database.\n * Its not required to be a database connection, depend on database type it can create connection pool.\n * You can have multiple connections to multiple databases in your application.\n */\nexport class Connection {\n\n // -------------------------------------------------------------------------\n // Public Readonly Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection name.\n */\n readonly name: string;\n\n /**\n * Connection options.\n */\n readonly options: ConnectionOptions;\n\n /**\n * Indicates if connection is initialized or not.\n */\n readonly isConnected: boolean;\n\n /**\n * Database driver used by this connection.\n */\n readonly driver: Driver;\n\n /**\n * EntityManager of this connection.\n */\n readonly manager: EntityManager;\n\n /**\n * Naming strategy used in the connection.\n */\n readonly namingStrategy: NamingStrategyInterface;\n\n /**\n * Name for the metadata table\n */\n readonly metadataTableName: string;\n\n /**\n * Logger used to log orm events.\n */\n readonly logger: Logger;\n\n /**\n * Migration instances that are registered for this connection.\n */\n readonly migrations: MigrationInterface[] = [];\n\n /**\n * Entity subscriber instances that are registered for this connection.\n */\n readonly subscribers: EntitySubscriberInterface<any>[] = [];\n\n /**\n * All entity metadatas that are registered for this connection.\n */\n readonly entityMetadatas: EntityMetadata[] = [];\n\n /**\n * Used to work with query result cache.\n */\n readonly queryResultCache?: QueryResultCache;\n\n /**\n * Used to load relations and work with lazy relations.\n */\n readonly relationLoader: RelationLoader;\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(options: ConnectionOptions) {\n this.name = options.name || \"default\";\n this.options = options;\n this.logger = new LoggerFactory().create(this.options.logger, this.options.logging);\n this.driver = new DriverFactory().create(this);\n this.manager = this.createEntityManager();\n this.namingStrategy = options.namingStrategy || new DefaultNamingStrategy();\n this.metadataTableName = options.metadataTableName || \"typeorm_metadata\";\n this.queryResultCache = options.cache ? new QueryResultCacheFactory(this).create() : undefined;\n this.relationLoader = new RelationLoader(this);\n this.isConnected = false;\n }\n\n // -------------------------------------------------------------------------\n // Public Accessors\n // -------------------------------------------------------------------------\n\n /**\n * Gets the mongodb entity manager that allows to perform mongodb-specific repository operations\n * with any entity in this connection.\n *\n * Available only in mongodb connections.\n */\n get mongoManager(): MongoEntityManager {\n if (!(this.manager instanceof MongoEntityManager))\n throw new TypeORMError(`MongoEntityManager is only available for MongoDB databases.`);\n\n return this.manager as MongoEntityManager;\n }\n\n /**\n * Gets a sql.js specific Entity Manager that allows to perform special load and save operations\n *\n * Available only in connection with the sqljs driver.\n */\n get sqljsManager(): SqljsEntityManager {\n if (!(this.manager instanceof SqljsEntityManager))\n throw new TypeORMError(`SqljsEntityManager is only available for Sqljs databases.`);\n\n return this.manager as SqljsEntityManager;\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Performs connection to the database.\n * This method should be called once on application bootstrap.\n * This method not necessarily creates database connection (depend on database type),\n * but it also can setup a connection pool with database to use.\n */\n async connect(): Promise<this> {\n if (this.isConnected)\n throw new CannotConnectAlreadyConnectedError(this.name);\n\n // connect to the database via its driver\n await this.driver.connect();\n\n // connect to the cache-specific database if cache is enabled\n if (this.queryResultCache)\n await this.queryResultCache.connect();\n\n // set connected status for the current connection\n ObjectUtils.assign(this, { isConnected: true });\n\n try {\n\n // build all metadatas registered in the current connection\n await this.buildMetadatas();\n\n await this.driver.afterConnect();\n\n // if option is set - drop schema once connection is done\n if (this.options.dropSchema)\n await this.dropDatabase();\n\n // if option is set - automatically synchronize a schema\n if (this.options.synchronize)\n await this.synchronize();\n\n // if option is set - automatically synchronize a schema\n if (this.options.migrationsRun)\n await this.runMigrations({ transaction: this.options.migrationsTransactionMode });\n\n } catch (error) {\n\n // if for some reason build metadata fail (for example validation error during entity metadata check)\n // connection needs to be closed\n await this.close();\n throw error;\n }\n\n return this;\n }\n\n /**\n * Closes connection with the database.\n * Once connection is closed, you cannot use repositories or perform any operations except opening connection again.\n */\n async close(): Promise<void> {\n if (!this.isConnected)\n throw new CannotExecuteNotConnectedError(this.name);\n\n await this.driver.disconnect();\n\n // disconnect from the cache-specific database if cache was enabled\n if (this.queryResultCache)\n await this.queryResultCache.disconnect();\n\n ObjectUtils.assign(this, { isConnected: false });\n }\n\n /**\n * Creates database schema for all entities registered in this connection.\n * Can be used only after connection to the database is established.\n *\n * @param dropBeforeSync If set to true then it drops the database with all its tables and data\n */\n async synchronize(dropBeforeSync: boolean = false): Promise<void> {\n\n if (!this.isConnected)\n throw new CannotExecuteNotConnectedError(this.name);\n\n if (dropBeforeSync)\n await this.dropDatabase();\n\n const schemaBuilder = this.driver.createSchemaBuilder();\n await schemaBuilder.build();\n }\n\n /**\n * Drops the database and all its data.\n * Be careful with this method on production since this method will erase all your database tables and their data.\n * Can be used only after connection to the database is established.\n */\n // TODO rename\n async dropDatabase(): Promise<void> {\n const queryRunner = this.createQueryRunner();\n try {\n if (this.driver instanceof SqlServerDriver || this.driver instanceof MysqlDriver || this.driver instanceof AuroraDataApiDriver) {\n const databases: string[] = this.driver.database ? [this.driver.database] : [];\n this.entityMetadatas.forEach(metadata => {\n if (metadata.database && databases.indexOf(metadata.database) === -1)\n databases.push(metadata.database);\n });\n\n for (const database of databases) {\n await queryRunner.clearDatabase(database);\n }\n } else {\n await queryRunner.clearDatabase();\n }\n } finally {\n await queryRunner.release();\n }\n }\n\n /**\n * Runs all pending migrations.\n * Can be used only after connection to the database is established.\n */\n async runMigrations(options?: { transaction?: \"all\" | \"none\" | \"each\" }): Promise<Migration[]> {\n if (!this.isConnected)\n throw new CannotExecuteNotConnectedError(this.name);\n\n const migrationExecutor = new MigrationExecutor(this);\n migrationExecutor.transaction = (options && options.transaction) || \"all\";\n\n const successMigrations = await migrationExecutor.executePendingMigrations();\n return successMigrations;\n }\n\n /**\n * Reverts last executed migration.\n * Can be used only after connection to the database is established.\n */\n async undoLastMigration(options?: { transaction?: \"all\" | \"none\" | \"each\" }): Promise<void> {\n\n if (!this.isConnected)\n throw new CannotExecuteNotConnectedError(this.name);\n\n const migrationExecutor = new MigrationExecutor(this);\n migrationExecutor.transaction = (options && options.transaction) || \"all\";\n\n await migrationExecutor.undoLastMigration();\n }\n\n /**\n * Lists all migrations and whether they have been run.\n * Returns true if there are pending migrations\n */\n async showMigrations(): Promise<boolean> {\n if (!this.isConnected) {\n throw new CannotExecuteNotConnectedError(this.name);\n }\n const migrationExecutor = new MigrationExecutor(this);\n return await migrationExecutor.showMigrations();\n }\n\n /**\n * Checks if entity metadata exist for the given entity class, target name or table name.\n */\n hasMetadata(target: EntityTarget<any>): boolean {\n return !!this.findMetadata(target);\n }\n\n /**\n * Gets entity metadata for the given entity class or schema name.\n */\n getMetadata(target: EntityTarget<any>): EntityMetadata {\n const metadata = this.findMetadata(target);\n if (!metadata)\n throw new EntityMetadataNotFoundError(target);\n\n return metadata;\n }\n\n /**\n * Gets repository for the given entity.\n */\n getRepository<Entity>(target: EntityTarget<Entity>): Repository<Entity> {\n return this.manager.getRepository(target);\n }\n\n /**\n * Gets tree repository for the given entity class or name.\n * Only tree-type entities can have a TreeRepository, like ones decorated with @Tree decorator.\n */\n getTreeRepository<Entity>(target: EntityTarget<Entity>): TreeRepository<Entity> {\n return this.manager.getTreeRepository(target);\n }\n\n /**\n * Gets mongodb-specific repository for the given entity class or name.\n * Works only if connection is mongodb-specific.\n */\n getMongoRepository<Entity>(target: EntityTarget<Entity>): MongoRepository<Entity> {\n if (!(this.driver instanceof MongoDriver))\n throw new TypeORMError(`You can use getMongoRepository only for MongoDB connections.`);\n\n return this.manager.getRepository(target) as any;\n }\n\n /**\n * Gets custom entity repository marked with @EntityRepository decorator.\n */\n getCustomRepository<T>(customRepository: ObjectType<T>): T {\n return this.manager.getCustomRepository(customRepository);\n }\n\n /**\n * Wraps given function execution (and all operations made there) into a transaction.\n * All database operations must be executed using provided entity manager.\n */\n async transaction<T>(runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T>;\n async transaction<T>(isolationLevel: IsolationLevel, runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T>;\n async transaction<T>(\n isolationOrRunInTransaction: IsolationLevel | ((entityManager: EntityManager) => Promise<T>),\n runInTransactionParam?: (entityManager: EntityManager) => Promise<T>\n ): Promise<any> {\n return this.manager.transaction(\n isolationOrRunInTransaction as any,\n runInTransactionParam as any\n );\n }\n\n /**\n * Executes raw SQL query and returns raw database results.\n */\n async query(query: string, parameters?: any[], queryRunner?: QueryRunner): Promise<any> {\n if (this instanceof MongoEntityManager)\n throw new TypeORMError(`Queries aren't supported by MongoDB.`);\n\n if (queryRunner && queryRunner.isReleased)\n throw new QueryRunnerProviderAlreadyReleasedError();\n\n const usedQueryRunner = queryRunner || this.createQueryRunner();\n\n try {\n return await usedQueryRunner.query(query, parameters); // await is needed here because we are using finally\n\n } finally {\n if (!queryRunner)\n await usedQueryRunner.release();\n }\n }\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder<Entity>(entityClass: EntityTarget<Entity>, alias: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>;\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder(queryRunner?: QueryRunner): SelectQueryBuilder<any>;\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder<Entity>(entityOrRunner?: EntityTarget<Entity>|QueryRunner, alias?: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity> {\n if (this instanceof MongoEntityManager)\n throw new TypeORMError(`Query Builder is not supported by MongoDB.`);\n\n if (alias) {\n const metadata = this.getMetadata(entityOrRunner as EntityTarget<Entity>);\n return new SelectQueryBuilder(this, queryRunner)\n .select(alias)\n .from(metadata.target, alias);\n\n } else {\n return new SelectQueryBuilder(this, entityOrRunner as QueryRunner|undefined);\n }\n }\n\n /**\n * Creates a query runner used for perform queries on a single database connection.\n * Using query runners you can control your queries to execute using single database connection and\n * manually control your database transaction.\n *\n * Mode is used in replication mode and indicates whatever you want to connect\n * to master database or any of slave databases.\n * If you perform writes you must use master database,\n * if you perform reads you can use slave databases.\n */\n createQueryRunner(mode: ReplicationMode = \"master\"): QueryRunner {\n const queryRunner = this.driver.createQueryRunner(mode);\n const manager = this.createEntityManager(queryRunner);\n Object.assign(queryRunner, { manager: manager });\n return queryRunner;\n }\n\n /**\n * Gets entity metadata of the junction table (many-to-many table).\n */\n getManyToManyMetadata(entityTarget: EntityTarget<any>, relationPropertyPath: string) {\n const relationMetadata = this.getMetadata(entityTarget).findRelationWithPropertyPath(relationPropertyPath);\n if (!relationMetadata)\n throw new TypeORMError(`Relation \"${relationPropertyPath}\" was not found in ${entityTarget} entity.`);\n if (!relationMetadata.isManyToMany)\n throw new TypeORMError(`Relation \"${entityTarget}#${relationPropertyPath}\" does not have a many-to-many relationship.` +\n `You can use this method only on many-to-many relations.`);\n\n return relationMetadata.junctionEntityMetadata;\n }\n\n /**\n * Creates an Entity Manager for the current connection with the help of the EntityManagerFactory.\n */\n createEntityManager(queryRunner?: QueryRunner): EntityManager {\n return new EntityManagerFactory().create(this, queryRunner);\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Finds exist entity metadata by the given entity class, target name or table name.\n */\n protected findMetadata(target: EntityTarget<any>): EntityMetadata|undefined {\n return this.entityMetadatas.find(metadata => {\n if (metadata.target === target)\n return true;\n if (target instanceof EntitySchema) {\n return metadata.name === target.options.name;\n }\n if (typeof target === \"string\") {\n if (target.indexOf(\".\") !== -1) {\n return metadata.tablePath === target;\n } else {\n return metadata.name === target || metadata.tableName === target;\n }\n }\n\n return false;\n });\n }\n\n /**\n * Builds metadatas for all registered classes inside this connection.\n */\n protected async buildMetadatas(): Promise<void> {\n\n const connectionMetadataBuilder = new ConnectionMetadataBuilder(this);\n const entityMetadataValidator = new EntityMetadataValidator();\n\n // create subscribers instances if they are not disallowed from high-level (for example they can disallowed from migrations run process)\n const subscribers = await connectionMetadataBuilder.buildSubscribers(this.options.subscribers || []);\n ObjectUtils.assign(this, { subscribers: subscribers });\n\n // build entity metadatas\n const entityMetadatas = await connectionMetadataBuilder.buildEntityMetadatas(this.options.entities || []);\n ObjectUtils.assign(this, { entityMetadatas: entityMetadatas });\n\n // create migration instances\n const migrations = await connectionMetadataBuilder.buildMigrations(this.options.migrations || []);\n ObjectUtils.assign(this, { migrations: migrations });\n\n // validate all created entity metadatas to make sure user created entities are valid and correct\n entityMetadataValidator.validateMany(this.entityMetadatas.filter(metadata => metadata.tableType !== \"view\"), this.driver);\n }\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/connection/Connection.ts"],"names":[],"mappings":";AAMA,OAAO,EAAC,qBAAqB,EAAC,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EAAC,8BAA8B,EAAC,MAAM,yCAAyC,CAAC;AACvF,OAAO,EAAC,kCAAkC,EAAC,MAAM,6CAA6C,CAAC;AAK/F,OAAO,EAAC,2BAA2B,EAAC,MAAM,sCAAsC,CAAC;AAEjF,OAAO,EAAC,iBAAiB,EAAC,MAAM,gCAAgC,CAAC;AAGjE,OAAO,EAAC,WAAW,EAAC,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAC,kBAAkB,EAAC,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAC,uBAAuB,EAAC,MAAM,6CAA6C,CAAC;AAEpF,OAAO,EAAC,uCAAuC,EAAC,MAAM,kDAAkD,CAAC;AACzG,OAAO,EAAC,oBAAoB,EAAC,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAC,aAAa,EAAC,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAC,yBAAyB,EAAC,MAAM,6BAA6B,CAAC;AAEtE,OAAO,EAAC,kBAAkB,EAAC,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAC,aAAa,EA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AM,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;wBAErD,iGAAiG;wBACjG,uBAAuB,CAAC,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,UAAA,QAAQ,IAAI,OAAA,QAAQ,CAAC,SAAS,KAAK,MAAM,EAA7B,CAA6B,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;;;;;KAC7H;IACL,iBAAC;AAAD,CAteA,AAseC,IAAA","file":"Connection.js","sourcesContent":["import {Driver} from \"../driver/Driver\";\nimport {Repository} from \"../repository/Repository\";\nimport {EntitySubscriberInterface} from \"../subscriber/EntitySubscriberInterface\";\nimport {EntityTarget} from \"../common/EntityTarget\";\nimport {ObjectType} from \"../common/ObjectType\";\nimport {EntityManager} from \"../entity-manager/EntityManager\";\nimport {DefaultNamingStrategy} from \"../naming-strategy/DefaultNamingStrategy\";\nimport {CannotExecuteNotConnectedError} from \"../error/CannotExecuteNotConnectedError\";\nimport {CannotConnectAlreadyConnectedError} from \"../error/CannotConnectAlreadyConnectedError\";\nimport {TreeRepository} from \"../repository/TreeRepository\";\nimport {NamingStrategyInterface} from \"../naming-strategy/NamingStrategyInterface\";\nimport {EntityMetadata} from \"../metadata/EntityMetadata\";\nimport {Logger} from \"../logger/Logger\";\nimport {EntityMetadataNotFoundError} from \"../error/EntityMetadataNotFoundError\";\nimport {MigrationInterface} from \"../migration/MigrationInterface\";\nimport {MigrationExecutor} from \"../migration/MigrationExecutor\";\nimport {Migration} from \"../migration/Migration\";\nimport {MongoRepository} from \"../repository/MongoRepository\";\nimport {MongoDriver} from \"../driver/mongodb/MongoDriver\";\nimport {MongoEntityManager} from \"../entity-manager/MongoEntityManager\";\nimport {EntityMetadataValidator} from \"../metadata-builder/EntityMetadataValidator\";\nimport {ConnectionOptions} from \"./ConnectionOptions\";\nimport {QueryRunnerProviderAlreadyReleasedError} from \"../error/QueryRunnerProviderAlreadyReleasedError\";\nimport {EntityManagerFactory} from \"../entity-manager/EntityManagerFactory\";\nimport {DriverFactory} from \"../driver/DriverFactory\";\nimport {ConnectionMetadataBuilder} from \"./ConnectionMetadataBuilder\";\nimport {QueryRunner} from \"../query-runner/QueryRunner\";\nimport {SelectQueryBuilder} from \"../query-builder/SelectQueryBuilder\";\nimport {LoggerFactory} from \"../logger/LoggerFactory\";\nimport {QueryResultCacheFactory} from \"../cache/QueryResultCacheFactory\";\nimport {QueryResultCache} from \"../cache/QueryResultCache\";\nimport {SqljsEntityManager} from \"../entity-manager/SqljsEntityManager\";\nimport {RelationLoader} from \"../query-builder/RelationLoader\";\nimport {EntitySchema} from \"../entity-schema/EntitySchema\";\nimport {SqlServerDriver} from \"../driver/sqlserver/SqlServerDriver\";\nimport {AbstractSqliteDriver} from \"../driver/sqlite-abstract/AbstractSqliteDriver\";\nimport {MysqlDriver} from \"../driver/mysql/MysqlDriver\";\nimport {ObjectUtils} from \"../util/ObjectUtils\";\nimport {IsolationLevel} from \"../driver/types/IsolationLevel\";\nimport {AuroraDataApiDriver} from \"../driver/aurora-data-api/AuroraDataApiDriver\";\nimport {ReplicationMode} from \"../driver/types/ReplicationMode\";\nimport { TypeORMError } from \"../error/TypeORMError\";\n\n/**\n * Connection is a single database ORM connection to a specific database.\n * Its not required to be a database connection, depend on database type it can create connection pool.\n * You can have multiple connections to multiple databases in your application.\n */\nexport class Connection {\n\n // -------------------------------------------------------------------------\n // Public Readonly Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection name.\n */\n readonly name: string;\n\n /**\n * Connection options.\n */\n readonly options: ConnectionOptions;\n\n /**\n * Indicates if connection is initialized or not.\n */\n readonly isConnected: boolean;\n\n /**\n * Database driver used by this connection.\n */\n readonly driver: Driver;\n\n /**\n * EntityManager of this connection.\n */\n readonly manager: EntityManager;\n\n /**\n * Naming strategy used in the connection.\n */\n readonly namingStrategy: NamingStrategyInterface;\n\n /**\n * Name for the metadata table\n */\n readonly metadataTableName: string;\n\n /**\n * Logger used to log orm events.\n */\n readonly logger: Logger;\n\n /**\n * Migration instances that are registered for this connection.\n */\n readonly migrations: MigrationInterface[] = [];\n\n /**\n * Entity subscriber instances that are registered for this connection.\n */\n readonly subscribers: EntitySubscriberInterface<any>[] = [];\n\n /**\n * All entity metadatas that are registered for this connection.\n */\n readonly entityMetadatas: EntityMetadata[] = [];\n\n /**\n * Used to work with query result cache.\n */\n readonly queryResultCache?: QueryResultCache;\n\n /**\n * Used to load relations and work with lazy relations.\n */\n readonly relationLoader: RelationLoader;\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(options: ConnectionOptions) {\n this.name = options.name || \"default\";\n this.options = options;\n this.logger = new LoggerFactory().create(this.options.logger, this.options.logging);\n this.driver = new DriverFactory().create(this);\n this.manager = this.createEntityManager();\n this.namingStrategy = options.namingStrategy || new DefaultNamingStrategy();\n this.metadataTableName = options.metadataTableName || \"typeorm_metadata\";\n this.queryResultCache = options.cache ? new QueryResultCacheFactory(this).create() : undefined;\n this.relationLoader = new RelationLoader(this);\n this.isConnected = false;\n }\n\n // -------------------------------------------------------------------------\n // Public Accessors\n // -------------------------------------------------------------------------\n\n /**\n * Gets the mongodb entity manager that allows to perform mongodb-specific repository operations\n * with any entity in this connection.\n *\n * Available only in mongodb connections.\n */\n get mongoManager(): MongoEntityManager {\n if (!(this.manager instanceof MongoEntityManager))\n throw new TypeORMError(`MongoEntityManager is only available for MongoDB databases.`);\n\n return this.manager as MongoEntityManager;\n }\n\n /**\n * Gets a sql.js specific Entity Manager that allows to perform special load and save operations\n *\n * Available only in connection with the sqljs driver.\n */\n get sqljsManager(): SqljsEntityManager {\n if (!(this.manager instanceof SqljsEntityManager))\n throw new TypeORMError(`SqljsEntityManager is only available for Sqljs databases.`);\n\n return this.manager as SqljsEntityManager;\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Performs connection to the database.\n * This method should be called once on application bootstrap.\n * This method not necessarily creates database connection (depend on database type),\n * but it also can setup a connection pool with database to use.\n */\n async connect(): Promise<this> {\n if (this.isConnected)\n throw new CannotConnectAlreadyConnectedError(this.name);\n\n // connect to the database via its driver\n await this.driver.connect();\n\n // connect to the cache-specific database if cache is enabled\n if (this.queryResultCache)\n await this.queryResultCache.connect();\n\n // set connected status for the current connection\n ObjectUtils.assign(this, { isConnected: true });\n\n try {\n\n // build all metadatas registered in the current connection\n await this.buildMetadatas();\n\n await this.driver.afterConnect();\n\n // if option is set - drop schema once connection is done\n if (this.options.dropSchema)\n await this.dropDatabase();\n\n // if option is set - automatically synchronize a schema\n if (this.options.synchronize)\n await this.synchronize();\n\n // if option is set - automatically synchronize a schema\n if (this.options.migrationsRun)\n await this.runMigrations({ transaction: this.options.migrationsTransactionMode });\n\n } catch (error) {\n\n // if for some reason build metadata fail (for example validation error during entity metadata check)\n // connection needs to be closed\n await this.close();\n throw error;\n }\n\n return this;\n }\n\n /**\n * Closes connection with the database.\n * Once connection is closed, you cannot use repositories or perform any operations except opening connection again.\n */\n async close(): Promise<void> {\n if (!this.isConnected)\n throw new CannotExecuteNotConnectedError(this.name);\n\n await this.driver.disconnect();\n\n // disconnect from the cache-specific database if cache was enabled\n if (this.queryResultCache)\n await this.queryResultCache.disconnect();\n\n ObjectUtils.assign(this, { isConnected: false });\n }\n\n /**\n * Creates database schema for all entities registered in this connection.\n * Can be used only after connection to the database is established.\n *\n * @param dropBeforeSync If set to true then it drops the database with all its tables and data\n */\n async synchronize(dropBeforeSync: boolean = false): Promise<void> {\n\n if (!this.isConnected)\n throw new CannotExecuteNotConnectedError(this.name);\n\n if (dropBeforeSync)\n await this.dropDatabase();\n\n const schemaBuilder = this.driver.createSchemaBuilder();\n await schemaBuilder.build();\n }\n\n /**\n * Drops the database and all its data.\n * Be careful with this method on production since this method will erase all your database tables and their data.\n * Can be used only after connection to the database is established.\n */\n // TODO rename\n async dropDatabase(): Promise<void> {\n const queryRunner = this.createQueryRunner();\n try {\n if (this.driver instanceof SqlServerDriver || this.driver instanceof MysqlDriver || this.driver instanceof AuroraDataApiDriver || this.driver instanceof AbstractSqliteDriver) {\n const databases: string[] = [];\n this.entityMetadatas.forEach(metadata => {\n if (metadata.database && databases.indexOf(metadata.database) === -1)\n databases.push(metadata.database);\n });\n if (databases.length === 0 && this.driver.database) {\n databases.push(this.driver.database);\n };\n\n if (databases.length === 0) {\n await queryRunner.clearDatabase();\n }\n else {\n for (const database of databases) {\n await queryRunner.clearDatabase(database);\n }\n }\n } else {\n await queryRunner.clearDatabase();\n }\n } finally {\n await queryRunner.release();\n }\n }\n\n /**\n * Runs all pending migrations.\n * Can be used only after connection to the database is established.\n */\n async runMigrations(options?: { transaction?: \"all\" | \"none\" | \"each\" }): Promise<Migration[]> {\n if (!this.isConnected)\n throw new CannotExecuteNotConnectedError(this.name);\n\n const migrationExecutor = new MigrationExecutor(this);\n migrationExecutor.transaction = (options && options.transaction) || \"all\";\n\n const successMigrations = await migrationExecutor.executePendingMigrations();\n return successMigrations;\n }\n\n /**\n * Reverts last executed migration.\n * Can be used only after connection to the database is established.\n */\n async undoLastMigration(options?: { transaction?: \"all\" | \"none\" | \"each\" }): Promise<void> {\n\n if (!this.isConnected)\n throw new CannotExecuteNotConnectedError(this.name);\n\n const migrationExecutor = new MigrationExecutor(this);\n migrationExecutor.transaction = (options && options.transaction) || \"all\";\n\n await migrationExecutor.undoLastMigration();\n }\n\n /**\n * Lists all migrations and whether they have been run.\n * Returns true if there are pending migrations\n */\n async showMigrations(): Promise<boolean> {\n if (!this.isConnected) {\n throw new CannotExecuteNotConnectedError(this.name);\n }\n const migrationExecutor = new MigrationExecutor(this);\n return await migrationExecutor.showMigrations();\n }\n\n /**\n * Checks if entity metadata exist for the given entity class, target name or table name.\n */\n hasMetadata(target: EntityTarget<any>): boolean {\n return !!this.findMetadata(target);\n }\n\n /**\n * Gets entity metadata for the given entity class or schema name.\n */\n getMetadata(target: EntityTarget<any>): EntityMetadata {\n const metadata = this.findMetadata(target);\n if (!metadata)\n throw new EntityMetadataNotFoundError(target);\n\n return metadata;\n }\n\n /**\n * Gets repository for the given entity.\n */\n getRepository<Entity>(target: EntityTarget<Entity>): Repository<Entity> {\n return this.manager.getRepository(target);\n }\n\n /**\n * Gets tree repository for the given entity class or name.\n * Only tree-type entities can have a TreeRepository, like ones decorated with @Tree decorator.\n */\n getTreeRepository<Entity>(target: EntityTarget<Entity>): TreeRepository<Entity> {\n return this.manager.getTreeRepository(target);\n }\n\n /**\n * Gets mongodb-specific repository for the given entity class or name.\n * Works only if connection is mongodb-specific.\n */\n getMongoRepository<Entity>(target: EntityTarget<Entity>): MongoRepository<Entity> {\n if (!(this.driver instanceof MongoDriver))\n throw new TypeORMError(`You can use getMongoRepository only for MongoDB connections.`);\n\n return this.manager.getRepository(target) as any;\n }\n\n /**\n * Gets custom entity repository marked with @EntityRepository decorator.\n */\n getCustomRepository<T>(customRepository: ObjectType<T>): T {\n return this.manager.getCustomRepository(customRepository);\n }\n\n /**\n * Wraps given function execution (and all operations made there) into a transaction.\n * All database operations must be executed using provided entity manager.\n */\n async transaction<T>(runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T>;\n async transaction<T>(isolationLevel: IsolationLevel, runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T>;\n async transaction<T>(\n isolationOrRunInTransaction: IsolationLevel | ((entityManager: EntityManager) => Promise<T>),\n runInTransactionParam?: (entityManager: EntityManager) => Promise<T>\n ): Promise<any> {\n return this.manager.transaction(\n isolationOrRunInTransaction as any,\n runInTransactionParam as any\n );\n }\n\n /**\n * Executes raw SQL query and returns raw database results.\n */\n async query(query: string, parameters?: any[], queryRunner?: QueryRunner): Promise<any> {\n if (this instanceof MongoEntityManager)\n throw new TypeORMError(`Queries aren't supported by MongoDB.`);\n\n if (queryRunner && queryRunner.isReleased)\n throw new QueryRunnerProviderAlreadyReleasedError();\n\n const usedQueryRunner = queryRunner || this.createQueryRunner();\n\n try {\n return await usedQueryRunner.query(query, parameters); // await is needed here because we are using finally\n\n } finally {\n if (!queryRunner)\n await usedQueryRunner.release();\n }\n }\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder<Entity>(entityClass: EntityTarget<Entity>, alias: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>;\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder(queryRunner?: QueryRunner): SelectQueryBuilder<any>;\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder<Entity>(entityOrRunner?: EntityTarget<Entity>|QueryRunner, alias?: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity> {\n if (this instanceof MongoEntityManager)\n throw new TypeORMError(`Query Builder is not supported by MongoDB.`);\n\n if (alias) {\n const metadata = this.getMetadata(entityOrRunner as EntityTarget<Entity>);\n return new SelectQueryBuilder(this, queryRunner)\n .select(alias)\n .from(metadata.target, alias);\n\n } else {\n return new SelectQueryBuilder(this, entityOrRunner as QueryRunner|undefined);\n }\n }\n\n /**\n * Creates a query runner used for perform queries on a single database connection.\n * Using query runners you can control your queries to execute using single database connection and\n * manually control your database transaction.\n *\n * Mode is used in replication mode and indicates whatever you want to connect\n * to master database or any of slave databases.\n * If you perform writes you must use master database,\n * if you perform reads you can use slave databases.\n */\n createQueryRunner(mode: ReplicationMode = \"master\"): QueryRunner {\n const queryRunner = this.driver.createQueryRunner(mode);\n const manager = this.createEntityManager(queryRunner);\n Object.assign(queryRunner, { manager: manager });\n return queryRunner;\n }\n\n /**\n * Gets entity metadata of the junction table (many-to-many table).\n */\n getManyToManyMetadata(entityTarget: EntityTarget<any>, relationPropertyPath: string) {\n const relationMetadata = this.getMetadata(entityTarget).findRelationWithPropertyPath(relationPropertyPath);\n if (!relationMetadata)\n throw new TypeORMError(`Relation \"${relationPropertyPath}\" was not found in ${entityTarget} entity.`);\n if (!relationMetadata.isManyToMany)\n throw new TypeORMError(`Relation \"${entityTarget}#${relationPropertyPath}\" does not have a many-to-many relationship.` +\n `You can use this method only on many-to-many relations.`);\n\n return relationMetadata.junctionEntityMetadata;\n }\n\n /**\n * Creates an Entity Manager for the current connection with the help of the EntityManagerFactory.\n */\n createEntityManager(queryRunner?: QueryRunner): EntityManager {\n return new EntityManagerFactory().create(this, queryRunner);\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Finds exist entity metadata by the given entity class, target name or table name.\n */\n protected findMetadata(target: EntityTarget<any>): EntityMetadata|undefined {\n return this.entityMetadatas.find(metadata => {\n if (metadata.target === target)\n return true;\n if (target instanceof EntitySchema) {\n return metadata.name === target.options.name;\n }\n if (typeof target === \"string\") {\n if (target.indexOf(\".\") !== -1) {\n return metadata.tablePath === target;\n } else {\n return metadata.name === target || metadata.tableName === target;\n }\n }\n\n return false;\n });\n }\n\n /**\n * Builds metadatas for all registered classes inside this connection.\n */\n protected async buildMetadatas(): Promise<void> {\n\n const connectionMetadataBuilder = new ConnectionMetadataBuilder(this);\n const entityMetadataValidator = new EntityMetadataValidator();\n\n // create subscribers instances if they are not disallowed from high-level (for example they can disallowed from migrations run process)\n const subscribers = await connectionMetadataBuilder.buildSubscribers(this.options.subscribers || []);\n ObjectUtils.assign(this, { subscribers: subscribers });\n\n // build entity metadatas\n const entityMetadatas = await connectionMetadataBuilder.buildEntityMetadatas(this.options.entities || []);\n ObjectUtils.assign(this, { entityMetadatas: entityMetadatas });\n\n // create migration instances\n const migrations = await connectionMetadataBuilder.buildMigrations(this.options.migrations || []);\n ObjectUtils.assign(this, { migrations: migrations });\n\n // validate all created entity metadatas to make sure user created entities are valid and correct\n entityMetadataValidator.validateMany(this.entityMetadatas.filter(metadata => metadata.tableType !== \"view\"), this.driver);\n }\n}\n"],"sourceRoot":".."}
|
|
@@ -6,6 +6,7 @@ import { ConnectionOptionsEnvReader } from "./options-reader/ConnectionOptionsEn
|
|
|
6
6
|
import { ConnectionOptionsYmlReader } from "./options-reader/ConnectionOptionsYmlReader";
|
|
7
7
|
import { ConnectionOptionsXmlReader } from "./options-reader/ConnectionOptionsXmlReader";
|
|
8
8
|
import { TypeORMError } from "../error";
|
|
9
|
+
import { isAbsolute } from "../util/PathUtils";
|
|
9
10
|
import { importOrRequireFile } from "../util/ImportUtils";
|
|
10
11
|
/**
|
|
11
12
|
* Reads connection options from the ormconfig.
|
|
@@ -169,6 +170,7 @@ var ConnectionOptionsReader = /** @class */ (function () {
|
|
|
169
170
|
if (!(Array.isArray(connectionOptions)))
|
|
170
171
|
connectionOptions = [connectionOptions];
|
|
171
172
|
connectionOptions.forEach(function (options) {
|
|
173
|
+
options.baseDirectory = _this.baseDirectory;
|
|
172
174
|
if (options.entities) {
|
|
173
175
|
var entities = options.entities.map(function (entity) {
|
|
174
176
|
if (typeof entity === "string" && entity.substr(0, 1) !== "/")
|
|
@@ -195,7 +197,7 @@ var ConnectionOptionsReader = /** @class */ (function () {
|
|
|
195
197
|
}
|
|
196
198
|
// make database path file in sqlite relative to package.json
|
|
197
199
|
if (options.type === "sqlite" || options.type === "better-sqlite3") {
|
|
198
|
-
if (typeof options.database === "string" &&
|
|
200
|
+
if (typeof options.database === "string" && !isAbsolute(options.database) &&
|
|
199
201
|
options.database.substr(0, 1) !== "/" && // unix absolute
|
|
200
202
|
options.database.substr(1, 2) !== ":\\" && // windows absolute
|
|
201
203
|
options.database !== ":memory:") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/connection/ConnectionOptionsReader.ts"],"names":[],"mappings":";AAAA,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAC,0BAA0B,EAAC,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAC,0BAA0B,EAAC,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAC,0BAA0B,EAAC,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAE,YAAY,EAAE,MAA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AC,cAAc,CAAC,CAAC;QACjE,CAAC;;;OAAA;IAKD,sBAAc,kDAAa;QAH3B;;WAEG;aACH;YACI,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI;gBACjC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAE7B,OAAO,WAAW,CAAC,IAAI,CAAC;QAC5B,CAAC;;;OAAA;IAKD,sBAAc,mDAAc;QAH5B;;WAEG;aACH;YACI,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU;gBACvC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;YAEnC,OAAO,WAAW,CAAC;QACvB,CAAC;;;OAAA;IAEL,8BAAC;AAAD,CAlNA,AAkNC,IAAA","file":"ConnectionOptionsReader.js","sourcesContent":["import appRootPath from \"app-root-path\";\nimport path from \"path\";\nimport {ConnectionOptions} from \"./ConnectionOptions\";\nimport {PlatformTools} from \"../platform/PlatformTools\";\nimport {ConnectionOptionsEnvReader} from \"./options-reader/ConnectionOptionsEnvReader\";\nimport {ConnectionOptionsYmlReader} from \"./options-reader/ConnectionOptionsYmlReader\";\nimport {ConnectionOptionsXmlReader} from \"./options-reader/ConnectionOptionsXmlReader\";\nimport { TypeORMError } from \"../error\";\nimport {importOrRequireFile} from \"../util/ImportUtils\";\n\n/**\n * Reads connection options from the ormconfig.\n * Can read from multiple file extensions including env, json, js, xml and yml.\n */\nexport class ConnectionOptionsReader {\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected options?: {\n /**\n * Directory where ormconfig should be read from.\n * By default its your application root (where your app package.json is located).\n */\n root?: string,\n\n /**\n * Filename of the ormconfig configuration. By default its equal to \"ormconfig\".\n */\n configName?: string\n }) {\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Returns all connection options read from the ormconfig.\n */\n async all(): Promise<ConnectionOptions[]> {\n const options = await this.load();\n if (!options)\n throw new TypeORMError(`No connection options were found in any orm configuration files.`);\n\n return options;\n }\n\n /**\n * Gets a connection with a given name read from ormconfig.\n * If connection with such name would not be found then it throw error.\n */\n async get(name: string): Promise<ConnectionOptions> {\n const allOptions = await this.all();\n const targetOptions = allOptions.find(options => options.name === name || (name === \"default\" && !options.name));\n if (!targetOptions)\n throw new TypeORMError(`Cannot find connection ${name} because its not defined in any orm configuration files.`);\n\n return targetOptions;\n }\n\n /**\n * Checks if there is a TypeORM configuration file.\n */\n async has(name: string): Promise<boolean> {\n const allOptions = await this.load();\n if (!allOptions)\n return false;\n\n const targetOptions = allOptions.find(options => options.name === name || (name === \"default\" && !options.name));\n return !!targetOptions;\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Loads all connection options from a configuration file.\n *\n * todo: get in count NODE_ENV somehow\n */\n protected async load(): Promise<ConnectionOptions[]|undefined> {\n let connectionOptions: ConnectionOptions|ConnectionOptions[]|undefined = undefined;\n\n const fileFormats = [\"env\", \"js\", \"mjs\", \"cjs\", \"ts\", \"mts\", \"cts\", \"json\", \"yml\", \"yaml\", \"xml\"];\n\n // Detect if baseFilePath contains file extension\n const possibleExtension = this.baseFilePath.substr(this.baseFilePath.lastIndexOf(\".\"));\n const fileExtension = fileFormats.find(extension => `.${extension}` === possibleExtension);\n\n // try to find any of following configuration formats\n const foundFileFormat = fileExtension || fileFormats.find(format => {\n return PlatformTools.fileExist(this.baseFilePath + \".\" + format);\n });\n\n // Determine config file name\n const configFile = fileExtension ? this.baseFilePath : this.baseFilePath + \".\" + foundFileFormat;\n\n // if .env file found then load all its variables into process.env using dotenv package\n if (foundFileFormat === \"env\") {\n PlatformTools.dotenv(configFile);\n } else if (PlatformTools.fileExist(this.baseDirectory + \"/.env\")) {\n PlatformTools.dotenv(this.baseDirectory + \"/.env\");\n }\n\n // try to find connection options from any of available sources of configuration\n if (PlatformTools.getEnvVariable(\"TYPEORM_CONNECTION\") || PlatformTools.getEnvVariable(\"TYPEORM_URL\")) {\n connectionOptions = await new ConnectionOptionsEnvReader().read();\n\n } else if (\n foundFileFormat === \"js\" || foundFileFormat === \"mjs\" || foundFileFormat === \"cjs\" ||\n foundFileFormat === \"ts\" || foundFileFormat === \"mts\" || foundFileFormat === \"cts\"\n ) {\n const [importOrRequireResult, moduleSystem] = await importOrRequireFile(configFile);\n const configModule = await importOrRequireResult;\n\n if (moduleSystem === \"esm\" || (configModule && \"__esModule\" in configModule && \"default\" in configModule)) {\n connectionOptions = configModule.default;\n } else {\n connectionOptions = configModule;\n }\n\n } else if (foundFileFormat === \"json\") {\n connectionOptions = require(configFile);\n\n } else if (foundFileFormat === \"yml\") {\n connectionOptions = await new ConnectionOptionsYmlReader().read(configFile);\n\n } else if (foundFileFormat === \"yaml\") {\n connectionOptions = await new ConnectionOptionsYmlReader().read(configFile);\n\n } else if (foundFileFormat === \"xml\") {\n connectionOptions = await new ConnectionOptionsXmlReader().read(configFile);\n }\n\n // normalize and return connection options\n if (connectionOptions) {\n return this.normalizeConnectionOptions(connectionOptions);\n }\n\n return undefined;\n }\n\n /**\n * Normalize connection options.\n */\n protected normalizeConnectionOptions(connectionOptions: ConnectionOptions|ConnectionOptions[]): ConnectionOptions[] {\n if (!(Array.isArray(connectionOptions)))\n connectionOptions = [connectionOptions];\n\n connectionOptions.forEach(options => {\n if (options.entities) {\n const entities = (options.entities as any[]).map(entity => {\n if (typeof entity === \"string\" && entity.substr(0, 1) !== \"/\")\n return this.baseDirectory + \"/\" + entity;\n\n return entity;\n });\n Object.assign(connectionOptions, { entities: entities });\n }\n if (options.subscribers) {\n const subscribers = (options.subscribers as any[]).map(subscriber => {\n if (typeof subscriber === \"string\" && subscriber.substr(0, 1) !== \"/\")\n return this.baseDirectory + \"/\" + subscriber;\n\n return subscriber;\n });\n Object.assign(connectionOptions, { subscribers: subscribers });\n }\n if (options.migrations) {\n const migrations = (options.migrations as any[]).map(migration => {\n if (typeof migration === \"string\" && migration.substr(0, 1) !== \"/\")\n return this.baseDirectory + \"/\" + migration;\n\n return migration;\n });\n Object.assign(connectionOptions, { migrations: migrations });\n }\n\n // make database path file in sqlite relative to package.json\n if (options.type === \"sqlite\" || options.type === \"better-sqlite3\") {\n if (typeof options.database === \"string\" &&\n options.database.substr(0, 1) !== \"/\" && // unix absolute\n options.database.substr(1, 2) !== \":\\\\\" && // windows absolute\n options.database !== \":memory:\") {\n Object.assign(options, {\n database: this.baseDirectory + \"/\" + options.database\n });\n }\n }\n });\n\n return connectionOptions;\n }\n\n /**\n * Gets directory where configuration file should be located and configuration file name.\n */\n protected get baseFilePath(): string {\n return path.resolve(this.baseDirectory, this.baseConfigName);\n }\n\n /**\n * Gets directory where configuration file should be located.\n */\n protected get baseDirectory(): string {\n if (this.options && this.options.root)\n return this.options.root;\n\n return appRootPath.path;\n }\n\n /**\n * Gets configuration file name.\n */\n protected get baseConfigName(): string {\n if (this.options && this.options.configName)\n return this.options.configName;\n\n return \"ormconfig\";\n }\n\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/connection/ConnectionOptionsReader.ts"],"names":[],"mappings":";AAAA,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAC,0BAA0B,EAAC,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAC,0BAA0B,EAAC,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAC,0BAA0B,EAAC,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAC,mBAAmB,EAAC,MAAM,qBAAqB,CAAC;AAExD;;;GAGG;AACH;IAEI,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,iCAAsB,O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A;IAKD,sBAAc,kDAAa;QAH3B;;WAEG;aACH;YACI,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI;gBACjC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAE7B,OAAO,WAAW,CAAC,IAAI,CAAC;QAC5B,CAAC;;;OAAA;IAKD,sBAAc,mDAAc;QAH5B;;WAEG;aACH;YACI,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU;gBACvC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;YAEnC,OAAO,WAAW,CAAC;QACvB,CAAC;;;OAAA;IAEL,8BAAC;AAAD,CAnNA,AAmNC,IAAA","file":"ConnectionOptionsReader.js","sourcesContent":["import appRootPath from \"app-root-path\";\nimport path from \"path\";\nimport {ConnectionOptions} from \"./ConnectionOptions\";\nimport {PlatformTools} from \"../platform/PlatformTools\";\nimport {ConnectionOptionsEnvReader} from \"./options-reader/ConnectionOptionsEnvReader\";\nimport {ConnectionOptionsYmlReader} from \"./options-reader/ConnectionOptionsYmlReader\";\nimport {ConnectionOptionsXmlReader} from \"./options-reader/ConnectionOptionsXmlReader\";\nimport { TypeORMError } from \"../error\";\nimport { isAbsolute } from \"../util/PathUtils\";\nimport {importOrRequireFile} from \"../util/ImportUtils\";\n\n/**\n * Reads connection options from the ormconfig.\n * Can read from multiple file extensions including env, json, js, xml and yml.\n */\nexport class ConnectionOptionsReader {\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected options?: {\n /**\n * Directory where ormconfig should be read from.\n * By default its your application root (where your app package.json is located).\n */\n root?: string,\n\n /**\n * Filename of the ormconfig configuration. By default its equal to \"ormconfig\".\n */\n configName?: string\n }) {\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Returns all connection options read from the ormconfig.\n */\n async all(): Promise<ConnectionOptions[]> {\n const options = await this.load();\n if (!options)\n throw new TypeORMError(`No connection options were found in any orm configuration files.`);\n\n return options;\n }\n\n /**\n * Gets a connection with a given name read from ormconfig.\n * If connection with such name would not be found then it throw error.\n */\n async get(name: string): Promise<ConnectionOptions> {\n const allOptions = await this.all();\n const targetOptions = allOptions.find(options => options.name === name || (name === \"default\" && !options.name));\n if (!targetOptions)\n throw new TypeORMError(`Cannot find connection ${name} because its not defined in any orm configuration files.`);\n\n return targetOptions;\n }\n\n /**\n * Checks if there is a TypeORM configuration file.\n */\n async has(name: string): Promise<boolean> {\n const allOptions = await this.load();\n if (!allOptions)\n return false;\n\n const targetOptions = allOptions.find(options => options.name === name || (name === \"default\" && !options.name));\n return !!targetOptions;\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Loads all connection options from a configuration file.\n *\n * todo: get in count NODE_ENV somehow\n */\n protected async load(): Promise<ConnectionOptions[]|undefined> {\n let connectionOptions: ConnectionOptions|ConnectionOptions[]|undefined = undefined;\n\n const fileFormats = [\"env\", \"js\", \"mjs\", \"cjs\", \"ts\", \"mts\", \"cts\", \"json\", \"yml\", \"yaml\", \"xml\"];\n\n // Detect if baseFilePath contains file extension\n const possibleExtension = this.baseFilePath.substr(this.baseFilePath.lastIndexOf(\".\"));\n const fileExtension = fileFormats.find(extension => `.${extension}` === possibleExtension);\n\n // try to find any of following configuration formats\n const foundFileFormat = fileExtension || fileFormats.find(format => {\n return PlatformTools.fileExist(this.baseFilePath + \".\" + format);\n });\n\n // Determine config file name\n const configFile = fileExtension ? this.baseFilePath : this.baseFilePath + \".\" + foundFileFormat;\n\n // if .env file found then load all its variables into process.env using dotenv package\n if (foundFileFormat === \"env\") {\n PlatformTools.dotenv(configFile);\n } else if (PlatformTools.fileExist(this.baseDirectory + \"/.env\")) {\n PlatformTools.dotenv(this.baseDirectory + \"/.env\");\n }\n\n // try to find connection options from any of available sources of configuration\n if (PlatformTools.getEnvVariable(\"TYPEORM_CONNECTION\") || PlatformTools.getEnvVariable(\"TYPEORM_URL\")) {\n connectionOptions = await new ConnectionOptionsEnvReader().read();\n\n } else if (\n foundFileFormat === \"js\" || foundFileFormat === \"mjs\" || foundFileFormat === \"cjs\" ||\n foundFileFormat === \"ts\" || foundFileFormat === \"mts\" || foundFileFormat === \"cts\"\n ) {\n const [importOrRequireResult, moduleSystem] = await importOrRequireFile(configFile);\n const configModule = await importOrRequireResult;\n\n if (moduleSystem === \"esm\" || (configModule && \"__esModule\" in configModule && \"default\" in configModule)) {\n connectionOptions = configModule.default;\n } else {\n connectionOptions = configModule;\n }\n\n } else if (foundFileFormat === \"json\") {\n connectionOptions = require(configFile);\n\n } else if (foundFileFormat === \"yml\") {\n connectionOptions = await new ConnectionOptionsYmlReader().read(configFile);\n\n } else if (foundFileFormat === \"yaml\") {\n connectionOptions = await new ConnectionOptionsYmlReader().read(configFile);\n\n } else if (foundFileFormat === \"xml\") {\n connectionOptions = await new ConnectionOptionsXmlReader().read(configFile);\n }\n\n // normalize and return connection options\n if (connectionOptions) {\n return this.normalizeConnectionOptions(connectionOptions);\n }\n\n return undefined;\n }\n\n /**\n * Normalize connection options.\n */\n protected normalizeConnectionOptions(connectionOptions: ConnectionOptions|ConnectionOptions[]): ConnectionOptions[] {\n if (!(Array.isArray(connectionOptions)))\n connectionOptions = [connectionOptions];\n\n connectionOptions.forEach(options => {\n options.baseDirectory = this.baseDirectory;\n if (options.entities) {\n const entities = (options.entities as any[]).map(entity => {\n if (typeof entity === \"string\" && entity.substr(0, 1) !== \"/\")\n return this.baseDirectory + \"/\" + entity;\n\n return entity;\n });\n Object.assign(connectionOptions, { entities: entities });\n }\n if (options.subscribers) {\n const subscribers = (options.subscribers as any[]).map(subscriber => {\n if (typeof subscriber === \"string\" && subscriber.substr(0, 1) !== \"/\")\n return this.baseDirectory + \"/\" + subscriber;\n\n return subscriber;\n });\n Object.assign(connectionOptions, { subscribers: subscribers });\n }\n if (options.migrations) {\n const migrations = (options.migrations as any[]).map(migration => {\n if (typeof migration === \"string\" && migration.substr(0, 1) !== \"/\")\n return this.baseDirectory + \"/\" + migration;\n\n return migration;\n });\n Object.assign(connectionOptions, { migrations: migrations });\n }\n\n // make database path file in sqlite relative to package.json\n if (options.type === \"sqlite\" || options.type === \"better-sqlite3\") {\n if (typeof options.database === \"string\" && !isAbsolute(options.database) &&\n options.database.substr(0, 1) !== \"/\" && // unix absolute\n options.database.substr(1, 2) !== \":\\\\\" && // windows absolute\n options.database !== \":memory:\") {\n Object.assign(options, {\n database: this.baseDirectory + \"/\" + options.database\n });\n }\n }\n });\n\n return connectionOptions;\n }\n\n /**\n * Gets directory where configuration file should be located and configuration file name.\n */\n protected get baseFilePath(): string {\n return path.resolve(this.baseDirectory, this.baseConfigName);\n }\n\n /**\n * Gets directory where configuration file should be located.\n */\n protected get baseDirectory(): string {\n if (this.options && this.options.root)\n return this.options.root;\n\n return appRootPath.path;\n }\n\n /**\n * Gets configuration file name.\n */\n protected get baseConfigName(): string {\n if (this.options && this.options.configName)\n return this.options.configName;\n\n return \"ormconfig\";\n }\n\n}\n"],"sourceRoot":".."}
|
|
@@ -31,6 +31,11 @@ export declare class BetterSqlite3Driver extends AbstractSqliteDriver {
|
|
|
31
31
|
precision?: number | null;
|
|
32
32
|
scale?: number;
|
|
33
33
|
}): string;
|
|
34
|
+
afterConnect(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* For SQLite, the database may be added in the decorator metadata. It will be a filepath to a database file.
|
|
37
|
+
*/
|
|
38
|
+
buildTableName(tableName: string, _schema?: string, database?: string): string;
|
|
34
39
|
/**
|
|
35
40
|
* Creates connection with the database.
|
|
36
41
|
*/
|
|
@@ -42,5 +47,13 @@ export declare class BetterSqlite3Driver extends AbstractSqliteDriver {
|
|
|
42
47
|
/**
|
|
43
48
|
* Auto creates database directory if it does not exist.
|
|
44
49
|
*/
|
|
45
|
-
protected createDatabaseDirectory(
|
|
50
|
+
protected createDatabaseDirectory(dbPath: string): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Performs the attaching of the database files. The attachedDatabase should have been populated during calls to #buildTableName
|
|
53
|
+
* during EntityMetadata production (see EntityMetadata#buildTablePath)
|
|
54
|
+
*
|
|
55
|
+
* https://sqlite.org/lang_attach.html
|
|
56
|
+
*/
|
|
57
|
+
protected attachDatabases(): Promise<void>;
|
|
58
|
+
protected getMainDatabasePath(): string;
|
|
46
59
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __awaiter, __extends, __generator } from "tslib";
|
|
1
|
+
import { __asyncValues, __awaiter, __extends, __generator } from "tslib";
|
|
2
2
|
import mkdirp from "mkdirp";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { DriverPackageNotInstalledError } from "../../error/DriverPackageNotInstalledError";
|
|
@@ -6,6 +6,7 @@ import { DriverOptionNotSetError } from "../../error/DriverOptionNotSetError";
|
|
|
6
6
|
import { PlatformTools } from "../../platform/PlatformTools";
|
|
7
7
|
import { AbstractSqliteDriver } from "../sqlite-abstract/AbstractSqliteDriver";
|
|
8
8
|
import { BetterSqlite3QueryRunner } from "./BetterSqlite3QueryRunner";
|
|
9
|
+
import { filepathToName, isAbsolute } from "../../util/PathUtils";
|
|
9
10
|
/**
|
|
10
11
|
* Organizes communication with sqlite DBMS.
|
|
11
12
|
*/
|
|
@@ -55,6 +56,34 @@ var BetterSqlite3Driver = /** @class */ (function (_super) {
|
|
|
55
56
|
}
|
|
56
57
|
return _super.prototype.normalizeType.call(this, column);
|
|
57
58
|
};
|
|
59
|
+
BetterSqlite3Driver.prototype.afterConnect = function () {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
+
return __generator(this, function (_a) {
|
|
62
|
+
return [2 /*return*/, this.attachDatabases()];
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* For SQLite, the database may be added in the decorator metadata. It will be a filepath to a database file.
|
|
68
|
+
*/
|
|
69
|
+
BetterSqlite3Driver.prototype.buildTableName = function (tableName, _schema, database) {
|
|
70
|
+
if (!database)
|
|
71
|
+
return tableName;
|
|
72
|
+
if (this.getAttachedDatabaseHandleByRelativePath(database))
|
|
73
|
+
return this.getAttachedDatabaseHandleByRelativePath(database) + "." + tableName;
|
|
74
|
+
if (database === this.options.database)
|
|
75
|
+
return tableName;
|
|
76
|
+
// we use the decorated name as supplied when deriving attach handle (ideally without non-portable absolute path)
|
|
77
|
+
var identifierHash = filepathToName(database);
|
|
78
|
+
// decorated name will be assumed relative to main database file when non absolute. Paths supplied as absolute won't be portable
|
|
79
|
+
var absFilepath = isAbsolute(database) ? database : path.join(this.getMainDatabasePath(), database);
|
|
80
|
+
this.attachedDatabases[database] = {
|
|
81
|
+
attachFilepathAbsolute: absFilepath,
|
|
82
|
+
attachFilepathRelative: database,
|
|
83
|
+
attachHandle: identifierHash,
|
|
84
|
+
};
|
|
85
|
+
return identifierHash + "." + tableName;
|
|
86
|
+
};
|
|
58
87
|
// -------------------------------------------------------------------------
|
|
59
88
|
// Protected Methods
|
|
60
89
|
// -------------------------------------------------------------------------
|
|
@@ -68,7 +97,7 @@ var BetterSqlite3Driver = /** @class */ (function (_super) {
|
|
|
68
97
|
switch (_f.label) {
|
|
69
98
|
case 0:
|
|
70
99
|
if (!(this.options.database !== ":memory:")) return [3 /*break*/, 2];
|
|
71
|
-
return [4 /*yield*/, this.createDatabaseDirectory(this.options.database)];
|
|
100
|
+
return [4 /*yield*/, this.createDatabaseDirectory(path.dirname(this.options.database))];
|
|
72
101
|
case 1:
|
|
73
102
|
_f.sent();
|
|
74
103
|
_f.label = 2;
|
|
@@ -109,11 +138,11 @@ var BetterSqlite3Driver = /** @class */ (function (_super) {
|
|
|
109
138
|
/**
|
|
110
139
|
* Auto creates database directory if it does not exist.
|
|
111
140
|
*/
|
|
112
|
-
BetterSqlite3Driver.prototype.createDatabaseDirectory = function (
|
|
141
|
+
BetterSqlite3Driver.prototype.createDatabaseDirectory = function (dbPath) {
|
|
113
142
|
return __awaiter(this, void 0, void 0, function () {
|
|
114
143
|
return __generator(this, function (_a) {
|
|
115
144
|
switch (_a.label) {
|
|
116
|
-
case 0: return [4 /*yield*/, mkdirp(
|
|
145
|
+
case 0: return [4 /*yield*/, mkdirp(dbPath)];
|
|
117
146
|
case 1:
|
|
118
147
|
_a.sent();
|
|
119
148
|
return [2 /*return*/];
|
|
@@ -121,6 +150,60 @@ var BetterSqlite3Driver = /** @class */ (function (_super) {
|
|
|
121
150
|
});
|
|
122
151
|
});
|
|
123
152
|
};
|
|
153
|
+
/**
|
|
154
|
+
* Performs the attaching of the database files. The attachedDatabase should have been populated during calls to #buildTableName
|
|
155
|
+
* during EntityMetadata production (see EntityMetadata#buildTablePath)
|
|
156
|
+
*
|
|
157
|
+
* https://sqlite.org/lang_attach.html
|
|
158
|
+
*/
|
|
159
|
+
BetterSqlite3Driver.prototype.attachDatabases = function () {
|
|
160
|
+
var e_1, _a;
|
|
161
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
162
|
+
var _b, _c, _d, attachHandle, attachFilepathAbsolute, e_1_1;
|
|
163
|
+
return __generator(this, function (_e) {
|
|
164
|
+
switch (_e.label) {
|
|
165
|
+
case 0:
|
|
166
|
+
_e.trys.push([0, 7, 8, 13]);
|
|
167
|
+
_b = __asyncValues(Object.values(this.attachedDatabases));
|
|
168
|
+
_e.label = 1;
|
|
169
|
+
case 1: return [4 /*yield*/, _b.next()];
|
|
170
|
+
case 2:
|
|
171
|
+
if (!(_c = _e.sent(), !_c.done)) return [3 /*break*/, 6];
|
|
172
|
+
_d = _c.value, attachHandle = _d.attachHandle, attachFilepathAbsolute = _d.attachFilepathAbsolute;
|
|
173
|
+
return [4 /*yield*/, this.createDatabaseDirectory(path.dirname(attachFilepathAbsolute))];
|
|
174
|
+
case 3:
|
|
175
|
+
_e.sent();
|
|
176
|
+
return [4 /*yield*/, this.connection.query("ATTACH \"" + attachFilepathAbsolute + "\" AS \"" + attachHandle + "\"")];
|
|
177
|
+
case 4:
|
|
178
|
+
_e.sent();
|
|
179
|
+
_e.label = 5;
|
|
180
|
+
case 5: return [3 /*break*/, 1];
|
|
181
|
+
case 6: return [3 /*break*/, 13];
|
|
182
|
+
case 7:
|
|
183
|
+
e_1_1 = _e.sent();
|
|
184
|
+
e_1 = { error: e_1_1 };
|
|
185
|
+
return [3 /*break*/, 13];
|
|
186
|
+
case 8:
|
|
187
|
+
_e.trys.push([8, , 11, 12]);
|
|
188
|
+
if (!(_c && !_c.done && (_a = _b.return))) return [3 /*break*/, 10];
|
|
189
|
+
return [4 /*yield*/, _a.call(_b)];
|
|
190
|
+
case 9:
|
|
191
|
+
_e.sent();
|
|
192
|
+
_e.label = 10;
|
|
193
|
+
case 10: return [3 /*break*/, 12];
|
|
194
|
+
case 11:
|
|
195
|
+
if (e_1) throw e_1.error;
|
|
196
|
+
return [7 /*endfinally*/];
|
|
197
|
+
case 12: return [7 /*endfinally*/];
|
|
198
|
+
case 13: return [2 /*return*/];
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
BetterSqlite3Driver.prototype.getMainDatabasePath = function () {
|
|
204
|
+
var optionsDb = this.options.database;
|
|
205
|
+
return path.dirname(isAbsolute(optionsDb) ? optionsDb : path.join(this.options.baseDirectory, optionsDb));
|
|
206
|
+
};
|
|
124
207
|
return BetterSqlite3Driver;
|
|
125
208
|
}(AbstractSqliteDriver));
|
|
126
209
|
export { BetterSqlite3Driver };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/driver/better-sqlite3/BetterSqlite3Driver.ts"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAC5F,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,8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,CAAC,gBAAgB,CAAC,CAAC;YAC3E,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;SAExB;QAAC,OAAO,CAAC,EAAE;YACR,MAAM,IAAI,8BAA8B,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;SACxE;IACL,CAAC;IAED;;OAEG;IACa,qDAAuB,GAAvC,UAAwC,QAAgB;;;;4BACpD,qBAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAA;;wBAApC,SAAoC,CAAC;;;;;KACxC;IAEL,0BAAC;AAAD,CA/HA,AA+HC,CA/HwC,oBAAoB,GA+H5D","file":"BetterSqlite3Driver.js","sourcesContent":["import mkdirp from \"mkdirp\";\nimport path from \"path\";\nimport { DriverPackageNotInstalledError } from \"../../error/DriverPackageNotInstalledError\";\nimport { DriverOptionNotSetError } from \"../../error/DriverOptionNotSetError\";\nimport { PlatformTools } from \"../../platform/PlatformTools\";\nimport { Connection } from \"../../connection/Connection\";\nimport { ColumnType } from \"../types/ColumnTypes\";\nimport { QueryRunner } from \"../../query-runner/QueryRunner\";\nimport { AbstractSqliteDriver } from \"../sqlite-abstract/AbstractSqliteDriver\";\nimport { BetterSqlite3ConnectionOptions } from \"./BetterSqlite3ConnectionOptions\";\nimport { BetterSqlite3QueryRunner } from \"./BetterSqlite3QueryRunner\";\nimport {ReplicationMode} from \"../types/ReplicationMode\";\n\n/**\n * Organizes communication with sqlite DBMS.\n */\nexport class BetterSqlite3Driver extends AbstractSqliteDriver {\n\n // -------------------------------------------------------------------------\n // Public Implemented Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection options.\n */\n options: BetterSqlite3ConnectionOptions;\n\n /**\n * SQLite underlying library.\n */\n sqlite: any;\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(connection: Connection) {\n super(connection);\n\n this.connection = connection;\n this.options = connection.options as BetterSqlite3ConnectionOptions;\n this.database = this.options.database;\n\n // validate options to make sure everything is set\n if (!this.options.database)\n throw new DriverOptionNotSetError(\"database\");\n\n // load sqlite package\n this.loadDependencies();\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\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)\n this.queryRunner = new BetterSqlite3QueryRunner(this);\n\n return this.queryRunner;\n }\n\n normalizeType(column: { type?: ColumnType, length?: number | string, precision?: number | null, scale?: number }): string {\n if ((column.type as any) === Buffer) {\n return \"blob\";\n }\n\n return super.normalizeType(column);\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates connection with the database.\n */\n protected async createDatabaseConnection() {\n // not to create database directory if is in memory\n if (this.options.database !== \":memory:\")\n await this.createDatabaseDirectory(this.options.database);\n\n const {\n database,\n readonly = false,\n fileMustExist = false,\n timeout = 5000,\n verbose = null,\n prepareDatabase\n } = this.options;\n const databaseConnection = this.sqlite(database, { readonly, fileMustExist, timeout, verbose });\n // in the options, if encryption key for SQLCipher is setted.\n // Must invoke key pragma before trying to do any other interaction with the database.\n if (this.options.key) {\n databaseConnection.exec(`PRAGMA key = ${JSON.stringify(this.options.key)}`);\n }\n\n // function to run before a database is used in typeorm.\n if (typeof prepareDatabase === \"function\") {\n prepareDatabase(databaseConnection);\n }\n\n // we need to enable foreign keys in sqlite to make sure all foreign key related features\n // working properly. this also makes onDelete to work with sqlite.\n databaseConnection.exec(`PRAGMA foreign_keys = ON`);\n\n // turn on WAL mode to enhance performance\n databaseConnection.exec(`PRAGMA journal_mode = WAL`);\n\n return 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 try {\n const sqlite = this.options.driver || PlatformTools.load(\"better-sqlite3\");\n this.sqlite = sqlite;\n\n } catch (e) {\n throw new DriverPackageNotInstalledError(\"SQLite\", \"better-sqlite3\");\n }\n }\n\n /**\n * Auto creates database directory if it does not exist.\n */\n protected async createDatabaseDirectory(fullPath: string): Promise<void> {\n await mkdirp(path.dirname(fullPath));\n }\n\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/driver/better-sqlite3/BetterSqlite3Driver.ts"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAC5F,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAI7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAE/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElE;;GAEG;AACH;IAAyC,uCAAoB;IAgBzD,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,6BAAY,UAAsB;QAAlC,YACI,kBAAM,UAAU,CAAC,SAYpB;QAVG,KAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,KAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAyC,CAAC;QACpE,KAAI,CAAC,QAAQ,GAAG,KAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;QAEtC,kDAAkD;QAClD,IAAI,CAAC,KAAI,CAAC,OAAO,CAAC,QAAQ;YACtB,MAAM,IAAI,uBAAuB,CAAC,UAAU,CAAC,CAAC;QAElD,sBAAsB;QACtB,KAAI,CAAC,gBAAgB,EAAE,CAAC;;IAC5B,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACG,wCA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C;IAC/G,CAAC;IAEL,0BAAC;AAAD,CA/KA,AA+KC,CA/KwC,oBAAoB,GA+K5D","file":"BetterSqlite3Driver.js","sourcesContent":["import mkdirp from \"mkdirp\";\nimport path from \"path\";\nimport { DriverPackageNotInstalledError } from \"../../error/DriverPackageNotInstalledError\";\nimport { DriverOptionNotSetError } from \"../../error/DriverOptionNotSetError\";\nimport { PlatformTools } from \"../../platform/PlatformTools\";\nimport { Connection } from \"../../connection/Connection\";\nimport { ColumnType } from \"../types/ColumnTypes\";\nimport { QueryRunner } from \"../../query-runner/QueryRunner\";\nimport { AbstractSqliteDriver } from \"../sqlite-abstract/AbstractSqliteDriver\";\nimport { BetterSqlite3ConnectionOptions } from \"./BetterSqlite3ConnectionOptions\";\nimport { BetterSqlite3QueryRunner } from \"./BetterSqlite3QueryRunner\";\nimport {ReplicationMode} from \"../types/ReplicationMode\";\nimport { filepathToName, isAbsolute } from \"../../util/PathUtils\";\n\n/**\n * Organizes communication with sqlite DBMS.\n */\nexport class BetterSqlite3Driver extends AbstractSqliteDriver {\n\n // -------------------------------------------------------------------------\n // Public Implemented Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection options.\n */\n options: BetterSqlite3ConnectionOptions;\n\n /**\n * SQLite underlying library.\n */\n sqlite: any;\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(connection: Connection) {\n super(connection);\n\n this.connection = connection;\n this.options = connection.options as BetterSqlite3ConnectionOptions;\n this.database = this.options.database;\n\n // validate options to make sure everything is set\n if (!this.options.database)\n throw new DriverOptionNotSetError(\"database\");\n\n // load sqlite package\n this.loadDependencies();\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\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)\n this.queryRunner = new BetterSqlite3QueryRunner(this);\n\n return this.queryRunner;\n }\n\n normalizeType(column: { type?: ColumnType, length?: number | string, precision?: number | null, scale?: number }): string {\n if ((column.type as any) === Buffer) {\n return \"blob\";\n }\n\n return super.normalizeType(column);\n }\n\n async afterConnect(): Promise<void> {\n return this.attachDatabases();\n }\n\n /**\n * For SQLite, the database may be added in the decorator metadata. It will be a filepath to a database file.\n */\n buildTableName(tableName: string, _schema?: string, database?: string): string {\n\n if (!database) return tableName;\n if (this.getAttachedDatabaseHandleByRelativePath(database)) return `${this.getAttachedDatabaseHandleByRelativePath(database)}.${tableName}`;\n\n if (database === this.options.database) return tableName;\n\n // we use the decorated name as supplied when deriving attach handle (ideally without non-portable absolute path)\n const identifierHash = filepathToName(database);\n // decorated name will be assumed relative to main database file when non absolute. Paths supplied as absolute won't be portable\n const absFilepath = isAbsolute(database) ? database : path.join(this.getMainDatabasePath(), database);\n\n this.attachedDatabases[database] = {\n attachFilepathAbsolute: absFilepath,\n attachFilepathRelative: database,\n attachHandle: identifierHash,\n };\n\n return `${identifierHash}.${tableName}`;\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates connection with the database.\n */\n protected async createDatabaseConnection() {\n // not to create database directory if is in memory\n if (this.options.database !== \":memory:\")\n await this.createDatabaseDirectory(path.dirname(this.options.database));\n\n const {\n database,\n readonly = false,\n fileMustExist = false,\n timeout = 5000,\n verbose = null,\n prepareDatabase\n } = this.options;\n const databaseConnection = this.sqlite(database, { readonly, fileMustExist, timeout, verbose });\n // in the options, if encryption key for SQLCipher is setted.\n // Must invoke key pragma before trying to do any other interaction with the database.\n if (this.options.key) {\n databaseConnection.exec(`PRAGMA key = ${JSON.stringify(this.options.key)}`);\n }\n\n // function to run before a database is used in typeorm.\n if (typeof prepareDatabase === \"function\") {\n prepareDatabase(databaseConnection);\n }\n\n // we need to enable foreign keys in sqlite to make sure all foreign key related features\n // working properly. this also makes onDelete to work with sqlite.\n databaseConnection.exec(`PRAGMA foreign_keys = ON`);\n\n // turn on WAL mode to enhance performance\n databaseConnection.exec(`PRAGMA journal_mode = WAL`);\n\n return 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 try {\n const sqlite = this.options.driver || PlatformTools.load(\"better-sqlite3\");\n this.sqlite = sqlite;\n\n } catch (e) {\n throw new DriverPackageNotInstalledError(\"SQLite\", \"better-sqlite3\");\n }\n }\n\n /**\n * Auto creates database directory if it does not exist.\n */\n protected async createDatabaseDirectory(dbPath: string): Promise<void> {\n await mkdirp(dbPath);\n }\n\n /**\n * Performs the attaching of the database files. The attachedDatabase should have been populated during calls to #buildTableName\n * during EntityMetadata production (see EntityMetadata#buildTablePath)\n *\n * https://sqlite.org/lang_attach.html\n */\n protected async attachDatabases() {\n\n // @todo - possibly check number of databases (but unqueriable at runtime sadly) - https://www.sqlite.org/limits.html#max_attached\n for await (const {attachHandle, attachFilepathAbsolute} of Object.values(this.attachedDatabases)) {\n await this.createDatabaseDirectory(path.dirname(attachFilepathAbsolute));\n await this.connection.query(`ATTACH \"${attachFilepathAbsolute}\" AS \"${attachHandle}\"`);\n }\n }\n\n protected getMainDatabasePath(): string {\n const optionsDb = this.options.database;\n return path.dirname(isAbsolute(optionsDb) ? optionsDb : path.join(this.options.baseDirectory!, optionsDb));\n }\n\n}\n"],"sourceRoot":"../.."}
|