typeorm 0.3.12-dev.4df969e → 0.3.12-dev.54ca9dd
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/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +6 -0
- package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
- package/browser/driver/better-sqlite3/BetterSqlite3Driver.js +3 -1
- package/browser/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
- package/browser/driver/postgres/PostgresQueryRunner.js +1 -1
- package/browser/driver/postgres/PostgresQueryRunner.js.map +1 -1
- package/browser/driver/sqlite-abstract/AbstractSqliteDriver.js +12 -0
- package/browser/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
- package/browser/find-options/FindOperatorType.d.ts +1 -1
- package/browser/find-options/FindOperatorType.js.map +1 -1
- package/browser/find-options/FindOptionsWhere.d.ts +5 -1
- package/browser/find-options/FindOptionsWhere.js.map +1 -1
- package/browser/find-options/operator/JsonContains.d.ts +6 -0
- package/browser/find-options/operator/JsonContains.js +10 -0
- package/browser/find-options/operator/JsonContains.js.map +1 -0
- package/browser/index.d.ts +2 -0
- package/browser/index.js +2 -0
- package/browser/index.js.map +1 -1
- package/browser/metadata-builder/RelationJoinColumnBuilder.js +2 -1
- package/browser/metadata-builder/RelationJoinColumnBuilder.js.map +1 -1
- package/browser/migration/MigrationExecutor.js +1 -1
- package/browser/migration/MigrationExecutor.js.map +1 -1
- package/browser/naming-strategy/LegacyOracleNamingStrategy.d.ts +21 -0
- package/browser/naming-strategy/LegacyOracleNamingStrategy.js +46 -0
- package/browser/naming-strategy/LegacyOracleNamingStrategy.js.map +1 -0
- package/browser/persistence/SubjectTopoligicalSorter.js +2 -6
- package/browser/persistence/SubjectTopoligicalSorter.js.map +1 -1
- package/browser/platform/BrowserPlatformTools.js +2 -2
- package/browser/platform/BrowserPlatformTools.js.map +1 -1
- package/browser/query-builder/QueryBuilder.js +2 -0
- package/browser/query-builder/QueryBuilder.js.map +1 -1
- package/browser/query-builder/SelectQueryBuilder.d.ts +1 -1
- package/browser/query-builder/SelectQueryBuilder.js +1 -1
- package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
- package/browser/query-builder/WhereClause.d.ts +1 -1
- package/browser/query-builder/WhereClause.js.map +1 -1
- package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +6 -0
- package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
- package/driver/better-sqlite3/BetterSqlite3Driver.js +3 -1
- package/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
- package/driver/postgres/PostgresQueryRunner.js +1 -1
- package/driver/postgres/PostgresQueryRunner.js.map +1 -1
- package/driver/sqlite-abstract/AbstractSqliteDriver.js +12 -0
- package/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
- package/find-options/FindOperatorType.d.ts +1 -1
- package/find-options/FindOperatorType.js.map +1 -1
- package/find-options/FindOptionsWhere.d.ts +5 -1
- package/find-options/FindOptionsWhere.js.map +1 -1
- package/find-options/operator/JsonContains.d.ts +6 -0
- package/find-options/operator/JsonContains.js +14 -0
- package/find-options/operator/JsonContains.js.map +1 -0
- package/index.d.ts +2 -0
- package/index.js +4 -1
- package/index.js.map +1 -1
- package/index.mjs +4 -0
- package/metadata-builder/RelationJoinColumnBuilder.js +2 -1
- package/metadata-builder/RelationJoinColumnBuilder.js.map +1 -1
- package/migration/MigrationExecutor.js +1 -1
- package/migration/MigrationExecutor.js.map +1 -1
- package/naming-strategy/LegacyOracleNamingStrategy.d.ts +21 -0
- package/naming-strategy/LegacyOracleNamingStrategy.js +50 -0
- package/naming-strategy/LegacyOracleNamingStrategy.js.map +1 -0
- package/package.json +1 -1
- package/persistence/SubjectTopoligicalSorter.js +2 -6
- package/persistence/SubjectTopoligicalSorter.js.map +1 -1
- package/query-builder/QueryBuilder.js +2 -0
- package/query-builder/QueryBuilder.js.map +1 -1
- package/query-builder/SelectQueryBuilder.d.ts +1 -1
- package/query-builder/SelectQueryBuilder.js +1 -1
- package/query-builder/SelectQueryBuilder.js.map +1 -1
- package/query-builder/WhereClause.d.ts +1 -1
- package/query-builder/WhereClause.js.map +1 -1
|
@@ -57,4 +57,10 @@ export interface BetterSqlite3ConnectionOptions extends BaseDataSourceOptions {
|
|
|
57
57
|
*/
|
|
58
58
|
readonly nativeBinding?: string;
|
|
59
59
|
readonly poolSize?: never;
|
|
60
|
+
/**
|
|
61
|
+
* Enables WAL mode. By default its disabled.
|
|
62
|
+
*
|
|
63
|
+
* @see https://www.sqlite.org/wal.html
|
|
64
|
+
*/
|
|
65
|
+
readonly enableWAL?: boolean;
|
|
60
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/driver/better-sqlite3/BetterSqlite3ConnectionOptions.ts"],"names":[],"mappings":"","file":"BetterSqlite3ConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\n\n/**\n * Sqlite-specific connection options.\n */\nexport interface BetterSqlite3ConnectionOptions extends BaseDataSourceOptions {\n /**\n * Database type.\n */\n readonly type: \"better-sqlite3\"\n\n /**\n * Storage type or path to the storage.\n */\n readonly database: string\n\n /**\n * The driver object\n * This defaults to require(\"better-sqlite3\")\n */\n readonly driver?: any\n\n /**\n * Encryption key for for SQLCipher.\n */\n readonly key?: string\n\n /**\n * Cache size of sqlite statement to speed up queries.\n * Default: 100.\n */\n readonly statementCacheSize?: number\n\n /**\n * Function to run before a database is used in typeorm.\n * You can set pragmas, register plugins or register\n * functions or aggregates in this function.\n */\n readonly prepareDatabase?: (db: any) => void | Promise<void>\n\n /**\n * Open the database connection in readonly mode.\n * Default: false.\n */\n readonly readonly?: boolean\n\n /**\n * If the database does not exist, an Error will be thrown instead of creating a new file.\n * This option does not affect in-memory or readonly database connections.\n * Default: false.\n */\n readonly fileMustExist?: boolean\n\n /**\n * The number of milliseconds to wait when executing queries\n * on a locked database, before throwing a SQLITE_BUSY error.\n * Default: 5000.\n */\n readonly timeout?: number\n\n /**\n * Provide a function that gets called with every SQL string executed by the database connection.\n */\n readonly verbose?: Function\n\n /**\n * Relative or absolute path to the native addon (better_sqlite3.node).\n */\n readonly nativeBinding?: string\n\n readonly poolSize?: never\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/driver/better-sqlite3/BetterSqlite3ConnectionOptions.ts"],"names":[],"mappings":"","file":"BetterSqlite3ConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\n\n/**\n * Sqlite-specific connection options.\n */\nexport interface BetterSqlite3ConnectionOptions extends BaseDataSourceOptions {\n /**\n * Database type.\n */\n readonly type: \"better-sqlite3\"\n\n /**\n * Storage type or path to the storage.\n */\n readonly database: string\n\n /**\n * The driver object\n * This defaults to require(\"better-sqlite3\")\n */\n readonly driver?: any\n\n /**\n * Encryption key for for SQLCipher.\n */\n readonly key?: string\n\n /**\n * Cache size of sqlite statement to speed up queries.\n * Default: 100.\n */\n readonly statementCacheSize?: number\n\n /**\n * Function to run before a database is used in typeorm.\n * You can set pragmas, register plugins or register\n * functions or aggregates in this function.\n */\n readonly prepareDatabase?: (db: any) => void | Promise<void>\n\n /**\n * Open the database connection in readonly mode.\n * Default: false.\n */\n readonly readonly?: boolean\n\n /**\n * If the database does not exist, an Error will be thrown instead of creating a new file.\n * This option does not affect in-memory or readonly database connections.\n * Default: false.\n */\n readonly fileMustExist?: boolean\n\n /**\n * The number of milliseconds to wait when executing queries\n * on a locked database, before throwing a SQLITE_BUSY error.\n * Default: 5000.\n */\n readonly timeout?: number\n\n /**\n * Provide a function that gets called with every SQL string executed by the database connection.\n */\n readonly verbose?: Function\n\n /**\n * Relative or absolute path to the native addon (better_sqlite3.node).\n */\n readonly nativeBinding?: string\n\n readonly poolSize?: never\n\n /**\n * Enables WAL mode. By default its disabled.\n *\n * @see https://www.sqlite.org/wal.html\n */\n readonly enableWAL?: boolean\n}\n"],"sourceRoot":"../.."}
|
|
@@ -101,7 +101,9 @@ export class BetterSqlite3Driver extends AbstractSqliteDriver {
|
|
|
101
101
|
// working properly. this also makes onDelete to work with sqlite.
|
|
102
102
|
databaseConnection.exec(`PRAGMA foreign_keys = ON`);
|
|
103
103
|
// turn on WAL mode to enhance performance
|
|
104
|
-
|
|
104
|
+
if (this.options.enableWAL) {
|
|
105
|
+
databaseConnection.exec(`PRAGMA journal_mode = WAL`);
|
|
106
|
+
}
|
|
105
107
|
return databaseConnection;
|
|
106
108
|
}
|
|
107
109
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/driver/better-sqlite3/BetterSqlite3Driver.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAI5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAA;AAE9E,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAErE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjE;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,oBAAoB;IAezD,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,UAAsB;QAC9B,KAAK,CAAC,UAAU,CAAC,CAAA;QAEjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAyC,CAAA;QACnE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAA;QAErC,sBAAsB;QACtB,IAAI,CAAC,gBAAgB,EAAE,CAAA;IAC3B,CAAC;IAED,4EAA4E;IAC5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AC7B,CAAC;IAED;;OAEG;IACO,gBAAgB;QACtB,IAAI;YACA,MAAM,MAAM,GACR,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;YAC/D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;SACvB;QAAC,OAAO,CAAC,EAAE;YACR,MAAM,IAAI,8BAA8B,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAA;SACvE;IACL,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,uBAAuB,CAAC,MAAc;QAClD,MAAM,MAAM,CAAC,MAAM,CAAC,CAAA;IACxB,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,eAAe;QAC3B,kIAAkI;QAClI,IAAI,KAAK,EAAE,MAAM,EACb,YAAY,EACZ,sBAAsB,GACzB,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE;YACxC,MAAM,IAAI,CAAC,uBAAuB,CAC9B,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,CACvC,CAAA;YACD,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CACvB,WAAW,sBAAsB,SAAS,YAAY,GAAG,CAC5D,CAAA;SACJ;IACL,CAAC;IAES,mBAAmB;QACzB,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAA;QACvC,OAAO,IAAI,CAAC,OAAO,CACf,UAAU,CAAC,SAAS,CAAC;YACjB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAc,EAAE,SAAS,CAAC,CAC1D,CAAA;IACL,CAAC;CACJ","file":"BetterSqlite3Driver.js","sourcesContent":["import mkdirp from \"mkdirp\"\nimport path from \"path\"\nimport { DriverPackageNotInstalledError } from \"../../error\"\nimport { PlatformTools } from \"../../platform/PlatformTools\"\nimport { DataSource } from \"../../data-source\"\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 // 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: DataSource) {\n super(connection)\n\n this.connection = connection\n this.options = connection.options as BetterSqlite3ConnectionOptions\n this.database = this.options.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: {\n type?: ColumnType\n length?: number | string\n precision?: number | null\n scale?: number\n }): 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(\n tableName: string,\n _schema?: string,\n database?: string,\n ): string {\n if (!database) return tableName\n if (this.getAttachedDatabaseHandleByRelativePath(database))\n return `${this.getAttachedDatabaseHandleByRelativePath(\n database,\n )}.${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)\n ? database\n : 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(\n path.dirname(this.options.database),\n )\n\n const {\n database,\n readonly = false,\n fileMustExist = false,\n timeout = 5000,\n verbose = null,\n nativeBinding = null,\n prepareDatabase,\n } = this.options\n const databaseConnection = this.sqlite(database, {\n readonly,\n fileMustExist,\n timeout,\n verbose,\n nativeBinding,\n })\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(\n `PRAGMA key = ${JSON.stringify(this.options.key)}`,\n )\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 =\n this.options.driver || PlatformTools.load(\"better-sqlite3\")\n this.sqlite = sqlite\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 // @todo - possibly check number of databases (but unqueriable at runtime sadly) - https://www.sqlite.org/limits.html#max_attached\n for await (const {\n attachHandle,\n attachFilepathAbsolute,\n } of Object.values(this.attachedDatabases)) {\n await this.createDatabaseDirectory(\n path.dirname(attachFilepathAbsolute),\n )\n await this.connection.query(\n `ATTACH \"${attachFilepathAbsolute}\" AS \"${attachHandle}\"`,\n )\n }\n }\n\n protected getMainDatabasePath(): string {\n const optionsDb = this.options.database\n return path.dirname(\n isAbsolute(optionsDb)\n ? optionsDb\n : path.join(this.options.baseDirectory!, optionsDb),\n )\n }\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/driver/better-sqlite3/BetterSqlite3Driver.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAI5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAA;AAE9E,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAErE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjE;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,oBAAoB;IAezD,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,UAAsB;QAC9B,KAAK,CAAC,UAAU,CAAC,CAAA;QAEjB,IAAI,CAAC,UAAU,GAAG,UAAU,CA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,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAc,EAAE,SAAS,CAAC,CAC1D,CAAA;IACL,CAAC;CACJ","file":"BetterSqlite3Driver.js","sourcesContent":["import mkdirp from \"mkdirp\"\nimport path from \"path\"\nimport { DriverPackageNotInstalledError } from \"../../error\"\nimport { PlatformTools } from \"../../platform/PlatformTools\"\nimport { DataSource } from \"../../data-source\"\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 // 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: DataSource) {\n super(connection)\n\n this.connection = connection\n this.options = connection.options as BetterSqlite3ConnectionOptions\n this.database = this.options.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: {\n type?: ColumnType\n length?: number | string\n precision?: number | null\n scale?: number\n }): 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(\n tableName: string,\n _schema?: string,\n database?: string,\n ): string {\n if (!database) return tableName\n if (this.getAttachedDatabaseHandleByRelativePath(database))\n return `${this.getAttachedDatabaseHandleByRelativePath(\n database,\n )}.${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)\n ? database\n : 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(\n path.dirname(this.options.database),\n )\n\n const {\n database,\n readonly = false,\n fileMustExist = false,\n timeout = 5000,\n verbose = null,\n nativeBinding = null,\n prepareDatabase,\n } = this.options\n const databaseConnection = this.sqlite(database, {\n readonly,\n fileMustExist,\n timeout,\n verbose,\n nativeBinding,\n })\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(\n `PRAGMA key = ${JSON.stringify(this.options.key)}`,\n )\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 if (this.options.enableWAL) {\n databaseConnection.exec(`PRAGMA journal_mode = WAL`)\n }\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 =\n this.options.driver || PlatformTools.load(\"better-sqlite3\")\n this.sqlite = sqlite\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 // @todo - possibly check number of databases (but unqueriable at runtime sadly) - https://www.sqlite.org/limits.html#max_attached\n for await (const {\n attachHandle,\n attachFilepathAbsolute,\n } of Object.values(this.attachedDatabases)) {\n await this.createDatabaseDirectory(\n path.dirname(attachFilepathAbsolute),\n )\n await this.connection.query(\n `ATTACH \"${attachFilepathAbsolute}\" AS \"${attachHandle}\"`,\n )\n }\n }\n\n protected getMainDatabasePath(): string {\n const optionsDb = this.options.database\n return path.dirname(\n isAbsolute(optionsDb)\n ? optionsDb\n : path.join(this.options.baseDirectory!, optionsDb),\n )\n }\n}\n"],"sourceRoot":"../.."}
|
|
@@ -2028,7 +2028,7 @@ export class PostgresQueryRunner extends BaseQueryRunner {
|
|
|
2028
2028
|
dbColumn["column_default"];
|
|
2029
2029
|
}
|
|
2030
2030
|
else {
|
|
2031
|
-
tableColumn.default = dbColumn["column_default"].replace(
|
|
2031
|
+
tableColumn.default = dbColumn["column_default"].replace(/::.+/g, "");
|
|
2032
2032
|
tableColumn.default =
|
|
2033
2033
|
tableColumn.default.replace(/^(-?\d+)$/, "'$1'");
|
|
2034
2034
|
}
|