typeorm 0.3.7-dev.ec05f1d → 0.3.8-dev.0b54222

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.
Files changed (33) hide show
  1. package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +4 -0
  2. package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
  3. package/browser/driver/better-sqlite3/BetterSqlite3Driver.d.ts +1 -1
  4. package/browser/driver/better-sqlite3/BetterSqlite3Driver.js +4 -3
  5. package/browser/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
  6. package/browser/driver/oracle/OracleConnectionOptions.d.ts +1 -1
  7. package/browser/driver/oracle/OracleConnectionOptions.js.map +1 -1
  8. package/browser/driver/postgres/PostgresConnectionOptions.d.ts +1 -1
  9. package/browser/driver/postgres/PostgresConnectionOptions.js.map +1 -1
  10. package/browser/driver/sap/SapQueryRunner.d.ts +7 -0
  11. package/browser/driver/sap/SapQueryRunner.js +24 -2
  12. package/browser/driver/sap/SapQueryRunner.js.map +1 -1
  13. package/browser/driver/sqlserver/SqlServerConnectionOptions.d.ts +1 -1
  14. package/browser/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
  15. package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js +2 -1
  16. package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
  17. package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +4 -0
  18. package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
  19. package/driver/better-sqlite3/BetterSqlite3Driver.d.ts +1 -1
  20. package/driver/better-sqlite3/BetterSqlite3Driver.js +6 -5
  21. package/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
  22. package/driver/oracle/OracleConnectionOptions.d.ts +1 -1
  23. package/driver/oracle/OracleConnectionOptions.js.map +1 -1
  24. package/driver/postgres/PostgresConnectionOptions.d.ts +1 -1
  25. package/driver/postgres/PostgresConnectionOptions.js.map +1 -1
  26. package/driver/sap/SapQueryRunner.d.ts +7 -0
  27. package/driver/sap/SapQueryRunner.js +24 -2
  28. package/driver/sap/SapQueryRunner.js.map +1 -1
  29. package/driver/sqlserver/SqlServerConnectionOptions.d.ts +1 -1
  30. package/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
  31. package/package.json +1 -1
  32. package/query-builder/transformer/RawSqlResultsToEntityTransformer.js +2 -1
  33. package/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
@@ -52,4 +52,8 @@ export interface BetterSqlite3ConnectionOptions extends BaseDataSourceOptions {
52
52
  * Provide a function that gets called with every SQL string executed by the database connection.
53
53
  */
54
54
  readonly verbose?: Function;
55
+ /**
56
+ * Relative or absolute path to the native addon (better_sqlite3.node).
57
+ */
58
+ readonly nativeBinding?: string;
55
59
  }
@@ -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"],"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"],"sourceRoot":"../.."}
@@ -1,4 +1,4 @@
1
- import { DataSource } from "../../data-source/DataSource";
1
+ import { DataSource } from "../../data-source";
2
2
  import { ColumnType } from "../types/ColumnTypes";
3
3
  import { QueryRunner } from "../../query-runner/QueryRunner";
4
4
  import { AbstractSqliteDriver } from "../sqlite-abstract/AbstractSqliteDriver";
@@ -1,7 +1,7 @@
1
1
  import mkdirp from "mkdirp";
2
2
  import path from "path";
3
- import { DriverPackageNotInstalledError } from "../../error/DriverPackageNotInstalledError";
4
- import { DriverOptionNotSetError } from "../../error/DriverOptionNotSetError";
3
+ import { DriverPackageNotInstalledError } from "../../error";
4
+ import { DriverOptionNotSetError } from "../../error";
5
5
  import { PlatformTools } from "../../platform/PlatformTools";
6
6
  import { AbstractSqliteDriver } from "../sqlite-abstract/AbstractSqliteDriver";
7
7
  import { BetterSqlite3QueryRunner } from "./BetterSqlite3QueryRunner";
@@ -84,12 +84,13 @@ export class BetterSqlite3Driver extends AbstractSqliteDriver {
84
84
  // not to create database directory if is in memory
85
85
  if (this.options.database !== ":memory:")
86
86
  await this.createDatabaseDirectory(path.dirname(this.options.database));
87
- const { database, readonly = false, fileMustExist = false, timeout = 5000, verbose = null, prepareDatabase, } = this.options;
87
+ const { database, readonly = false, fileMustExist = false, timeout = 5000, verbose = null, nativeBinding = null, prepareDatabase, } = this.options;
88
88
  const databaseConnection = this.sqlite(database, {
89
89
  readonly,
90
90
  fileMustExist,
91
91
  timeout,
92
92
  verbose,
93
+ nativeBinding,
93
94
  });
94
95
  // in the options, if encryption key for SQLCipher is setted.
95
96
  // Must invoke key pragma before trying to do any other interaction with the database.
@@ -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,4CAA4C,CAAA;AAC3F,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAA;AAC7E,OAAO,EAAE,aAAa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M,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/DriverPackageNotInstalledError\"\nimport { DriverOptionNotSetError } from \"../../error/DriverOptionNotSetError\"\nimport { PlatformTools } from \"../../platform/PlatformTools\"\nimport { DataSource } from \"../../data-source/DataSource\"\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 // 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: {\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 prepareDatabase,\n } = this.options\n const databaseConnection = this.sqlite(database, {\n readonly,\n fileMustExist,\n timeout,\n verbose,\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,uBAAuB,EAAE,MAAM,aAAa,CAAA;AACrD,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,kDAAkD;QAClD,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ;YACtB,MAAM,IAAI,uBAAuB,CAAC,UAAU,CAAC,CAAA;QAEjD,sBAAsB;QACtB,IAAI,CAAC,gBAAgB,EAAE,CAAA;IAC3B,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,KAAK,CAAC,UAAU;QACZ,IAAI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AI,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 { DriverOptionNotSetError } 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 // 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: {\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":"../.."}
@@ -18,7 +18,7 @@ export interface OracleConnectionOptions extends BaseDataSourceOptions, OracleCo
18
18
  */
19
19
  readonly driver?: any;
20
20
  /**
21
- * A boolean determining whether to pass time values in UTC or local time. (default: true).
21
+ * A boolean determining whether to pass time values in UTC or local time. (default: false).
22
22
  */
23
23
  readonly useUTC?: boolean;
24
24
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/driver/oracle/OracleConnectionOptions.ts"],"names":[],"mappings":"","file":"OracleConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { OracleConnectionCredentialsOptions } from \"./OracleConnectionCredentialsOptions\"\n\n/**\n * Oracle-specific connection options.\n */\nexport interface OracleConnectionOptions\n extends BaseDataSourceOptions,\n OracleConnectionCredentialsOptions {\n /**\n * Database type.\n */\n readonly type: \"oracle\"\n\n /**\n * Schema name. By default is \"public\".\n */\n readonly schema?: string\n\n /**\n * The driver object\n * This defaults to require(\"oracledb\")\n */\n readonly driver?: any\n\n /**\n * A boolean determining whether to pass time values in UTC or local time. (default: true).\n */\n readonly useUTC?: boolean\n\n /**\n * Replication setup.\n */\n readonly replication?: {\n /**\n * Master server used by orm to perform writes.\n */\n readonly master: OracleConnectionCredentialsOptions\n\n /**\n * List of read-from severs (slaves).\n */\n readonly slaves: OracleConnectionCredentialsOptions[]\n }\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../browser/src/driver/oracle/OracleConnectionOptions.ts"],"names":[],"mappings":"","file":"OracleConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { OracleConnectionCredentialsOptions } from \"./OracleConnectionCredentialsOptions\"\n\n/**\n * Oracle-specific connection options.\n */\nexport interface OracleConnectionOptions\n extends BaseDataSourceOptions,\n OracleConnectionCredentialsOptions {\n /**\n * Database type.\n */\n readonly type: \"oracle\"\n\n /**\n * Schema name. By default is \"public\".\n */\n readonly schema?: string\n\n /**\n * The driver object\n * This defaults to require(\"oracledb\")\n */\n readonly driver?: any\n\n /**\n * A boolean determining whether to pass time values in UTC or local time. (default: false).\n */\n readonly useUTC?: boolean\n\n /**\n * Replication setup.\n */\n readonly replication?: {\n /**\n * Master server used by orm to perform writes.\n */\n readonly master: OracleConnectionCredentialsOptions\n\n /**\n * List of read-from severs (slaves).\n */\n readonly slaves: OracleConnectionCredentialsOptions[]\n }\n}\n"],"sourceRoot":"../.."}
@@ -23,7 +23,7 @@ export interface PostgresConnectionOptions extends BaseDataSourceOptions, Postgr
23
23
  */
24
24
  readonly nativeDriver?: any;
25
25
  /**
26
- * A boolean determining whether to pass time values in UTC or local time. (default: true).
26
+ * A boolean determining whether to pass time values in UTC or local time. (default: false).
27
27
  */
28
28
  readonly useUTC?: boolean;
29
29
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/driver/postgres/PostgresConnectionOptions.ts"],"names":[],"mappings":"","file":"PostgresConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { PostgresConnectionCredentialsOptions } from \"./PostgresConnectionCredentialsOptions\"\n\n/**\n * Postgres-specific connection options.\n */\nexport interface PostgresConnectionOptions\n extends BaseDataSourceOptions,\n PostgresConnectionCredentialsOptions {\n /**\n * Database type.\n */\n readonly type: \"postgres\"\n\n /**\n * Schema name.\n */\n readonly schema?: string\n\n /**\n * The driver object\n * This defaults to `require(\"pg\")`.\n */\n readonly driver?: any\n\n /**\n * The driver object\n * This defaults to `require(\"pg-native\")`.\n */\n readonly nativeDriver?: any\n\n /**\n * A boolean determining whether to pass time values in UTC or local time. (default: true).\n */\n readonly useUTC?: boolean\n\n /**\n * Replication setup.\n */\n readonly replication?: {\n /**\n * Master server used by orm to perform writes.\n */\n readonly master: PostgresConnectionCredentialsOptions\n\n /**\n * List of read-from severs (slaves).\n */\n readonly slaves: PostgresConnectionCredentialsOptions[]\n }\n\n /**\n * The milliseconds before a timeout occurs during the initial connection to the postgres\n * server. If undefined, or set to 0, there is no timeout. Defaults to undefined.\n */\n readonly connectTimeoutMS?: number\n\n /**\n * The Postgres extension to use to generate UUID columns. Defaults to uuid-ossp.\n * If pgcrypto is selected, TypeORM will use the gen_random_uuid() function from this extension.\n * If uuid-ossp is selected, TypeORM will use the uuid_generate_v4() function from this extension.\n */\n readonly uuidExtension?: \"pgcrypto\" | \"uuid-ossp\"\n\n /*\n * Function handling errors thrown by drivers pool.\n * Defaults to logging error with `warn` level.\n */\n readonly poolErrorHandler?: (err: any) => any\n\n /**\n * Include notification messages from Postgres server in client logs\n */\n readonly logNotifications?: boolean\n\n /**\n * Automatically install postgres extensions\n */\n readonly installExtensions?: boolean\n\n /**\n * sets the application_name var to help db administrators identify\n * the service using this connection. Defaults to 'undefined'\n */\n readonly applicationName?: string\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../browser/src/driver/postgres/PostgresConnectionOptions.ts"],"names":[],"mappings":"","file":"PostgresConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { PostgresConnectionCredentialsOptions } from \"./PostgresConnectionCredentialsOptions\"\n\n/**\n * Postgres-specific connection options.\n */\nexport interface PostgresConnectionOptions\n extends BaseDataSourceOptions,\n PostgresConnectionCredentialsOptions {\n /**\n * Database type.\n */\n readonly type: \"postgres\"\n\n /**\n * Schema name.\n */\n readonly schema?: string\n\n /**\n * The driver object\n * This defaults to `require(\"pg\")`.\n */\n readonly driver?: any\n\n /**\n * The driver object\n * This defaults to `require(\"pg-native\")`.\n */\n readonly nativeDriver?: any\n\n /**\n * A boolean determining whether to pass time values in UTC or local time. (default: false).\n */\n readonly useUTC?: boolean\n\n /**\n * Replication setup.\n */\n readonly replication?: {\n /**\n * Master server used by orm to perform writes.\n */\n readonly master: PostgresConnectionCredentialsOptions\n\n /**\n * List of read-from severs (slaves).\n */\n readonly slaves: PostgresConnectionCredentialsOptions[]\n }\n\n /**\n * The milliseconds before a timeout occurs during the initial connection to the postgres\n * server. If undefined, or set to 0, there is no timeout. Defaults to undefined.\n */\n readonly connectTimeoutMS?: number\n\n /**\n * The Postgres extension to use to generate UUID columns. Defaults to uuid-ossp.\n * If pgcrypto is selected, TypeORM will use the gen_random_uuid() function from this extension.\n * If uuid-ossp is selected, TypeORM will use the uuid_generate_v4() function from this extension.\n */\n readonly uuidExtension?: \"pgcrypto\" | \"uuid-ossp\"\n\n /*\n * Function handling errors thrown by drivers pool.\n * Defaults to logging error with `warn` level.\n */\n readonly poolErrorHandler?: (err: any) => any\n\n /**\n * Include notification messages from Postgres server in client logs\n */\n readonly logNotifications?: boolean\n\n /**\n * Automatically install postgres extensions\n */\n readonly installExtensions?: boolean\n\n /**\n * sets the application_name var to help db administrators identify\n * the service using this connection. Defaults to 'undefined'\n */\n readonly applicationName?: string\n}\n"],"sourceRoot":"../.."}
@@ -52,6 +52,13 @@ export declare class SapQueryRunner extends BaseQueryRunner implements QueryRunn
52
52
  * Error will be thrown if transaction was not started.
53
53
  */
54
54
  rollbackTransaction(): Promise<void>;
55
+ /**
56
+ * @description Switches on/off AUTOCOMMIT mode
57
+ * @link https://help.sap.com/docs/HANA_SERVICE_CF/7c78579ce9b14a669c1f3295b0d8ca16/d538d11053bd4f3f847ec5ce817a3d4c.html?locale=en-US
58
+ */
59
+ setAutoCommit(options: {
60
+ status: "on" | "off";
61
+ }): Promise<void>;
55
62
  /**
56
63
  * Executes a given SQL query.
57
64
  */
@@ -17,6 +17,7 @@ import { QueryResult } from "../../query-runner/QueryResult";
17
17
  import { QueryLock } from "../../query-runner/QueryLock";
18
18
  import { MetadataTableType } from "../types/MetadataTableType";
19
19
  import { InstanceChecker } from "../../util/InstanceChecker";
20
+ import { promisify } from "util";
20
21
  /**
21
22
  * Runs queries on a single SQL Server database connection.
22
23
  */
@@ -67,6 +68,11 @@ export class SapQueryRunner extends BaseQueryRunner {
67
68
  throw new TransactionAlreadyStartedError();
68
69
  await this.broadcaster.broadcast("BeforeTransactionStart");
69
70
  this.isTransactionActive = true;
71
+ /**
72
+ * Disable AUTOCOMMIT while running transaction.
73
+ * Otherwise, COMMIT/ROLLBACK doesn't work in autocommit mode.
74
+ */
75
+ await this.setAutoCommit({ status: "off" });
70
76
  if (isolationLevel) {
71
77
  await this.query(`SET TRANSACTION ISOLATION LEVEL ${isolationLevel || ""}`);
72
78
  }
@@ -84,6 +90,7 @@ export class SapQueryRunner extends BaseQueryRunner {
84
90
  await this.broadcaster.broadcast("BeforeTransactionCommit");
85
91
  await this.query("COMMIT");
86
92
  this.isTransactionActive = false;
93
+ await this.setAutoCommit({ status: "on" });
87
94
  await this.broadcaster.broadcast("AfterTransactionCommit");
88
95
  }
89
96
  /**
@@ -98,8 +105,25 @@ export class SapQueryRunner extends BaseQueryRunner {
98
105
  await this.broadcaster.broadcast("BeforeTransactionRollback");
99
106
  await this.query("ROLLBACK");
100
107
  this.isTransactionActive = false;
108
+ await this.setAutoCommit({ status: "on" });
101
109
  await this.broadcaster.broadcast("AfterTransactionRollback");
102
110
  }
111
+ /**
112
+ * @description Switches on/off AUTOCOMMIT mode
113
+ * @link https://help.sap.com/docs/HANA_SERVICE_CF/7c78579ce9b14a669c1f3295b0d8ca16/d538d11053bd4f3f847ec5ce817a3d4c.html?locale=en-US
114
+ */
115
+ async setAutoCommit(options) {
116
+ const connection = await this.connect();
117
+ const execute = promisify(connection.exec.bind(connection));
118
+ connection.setAutoCommit(options.status === "on");
119
+ const query = `SET TRANSACTION AUTOCOMMIT DDL ${options.status.toUpperCase()};`;
120
+ try {
121
+ await execute(query);
122
+ }
123
+ catch (error) {
124
+ throw new QueryFailedError(query, [], error);
125
+ }
126
+ }
103
127
  /**
104
128
  * Executes a given SQL query.
105
129
  */
@@ -111,8 +135,6 @@ export class SapQueryRunner extends BaseQueryRunner {
111
135
  const result = new QueryResult();
112
136
  try {
113
137
  const databaseConnection = await this.connect();
114
- // we disable autocommit because ROLLBACK does not work in autocommit mode
115
- databaseConnection.setAutoCommit(!this.isTransactionActive);
116
138
  this.driver.connection.logger.logQuery(query, parameters, this);
117
139
  const queryStartTime = +new Date();
118
140
  const isInsertQuery = query.substr(0, 11) === "INSERT INTO";