typeorm 0.2.39-dev.dd94c9d → 0.2.39

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 (220) hide show
  1. package/README.md +60 -59
  2. package/browser/connection/ConnectionOptionsReader.js +2 -1
  3. package/browser/connection/ConnectionOptionsReader.js.map +1 -1
  4. package/browser/decorator/entity-view/ViewEntity.js +1 -0
  5. package/browser/decorator/entity-view/ViewEntity.js.map +1 -1
  6. package/browser/decorator/options/ViewEntityOptions.d.ts +5 -0
  7. package/browser/decorator/options/ViewEntityOptions.js.map +1 -1
  8. package/browser/driver/aurora-data-api/AuroraDataApiConnectionOptions.d.ts +5 -0
  9. package/browser/driver/aurora-data-api/AuroraDataApiConnectionOptions.js.map +1 -1
  10. package/browser/driver/aurora-data-api/AuroraDataApiDriver.js +6 -5
  11. package/browser/driver/aurora-data-api/AuroraDataApiDriver.js.map +1 -1
  12. package/browser/driver/aurora-data-api-pg/AuroraDataApiPostgresConnectionOptions.d.ts +5 -0
  13. package/browser/driver/aurora-data-api-pg/AuroraDataApiPostgresConnectionOptions.js.map +1 -1
  14. package/browser/driver/aurora-data-api-pg/AuroraDataApiPostgresDriver.js +2 -1
  15. package/browser/driver/aurora-data-api-pg/AuroraDataApiPostgresDriver.js.map +1 -1
  16. package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +5 -0
  17. package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
  18. package/browser/driver/better-sqlite3/BetterSqlite3Driver.js +4 -3
  19. package/browser/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
  20. package/browser/driver/cockroachdb/CockroachConnectionOptions.d.ts +10 -0
  21. package/browser/driver/cockroachdb/CockroachConnectionOptions.js.map +1 -1
  22. package/browser/driver/cockroachdb/CockroachDriver.js +27 -17
  23. package/browser/driver/cockroachdb/CockroachDriver.js.map +1 -1
  24. package/browser/driver/cockroachdb/CockroachQueryRunner.js +63 -69
  25. package/browser/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
  26. package/browser/driver/cordova/CordovaConnectionOptions.d.ts +5 -0
  27. package/browser/driver/cordova/CordovaConnectionOptions.js.map +1 -1
  28. package/browser/driver/cordova/CordovaDriver.d.ts +1 -1
  29. package/browser/driver/cordova/CordovaDriver.js +27 -19
  30. package/browser/driver/cordova/CordovaDriver.js.map +1 -1
  31. package/browser/driver/cordova/CordovaQueryRunner.js +50 -43
  32. package/browser/driver/cordova/CordovaQueryRunner.js.map +1 -1
  33. package/browser/driver/mongodb/MongoConnectionOptions.d.ts +5 -0
  34. package/browser/driver/mongodb/MongoConnectionOptions.js.map +1 -1
  35. package/browser/driver/mongodb/MongoDriver.js +2 -1
  36. package/browser/driver/mongodb/MongoDriver.js.map +1 -1
  37. package/browser/driver/mysql/MysqlConnectionOptions.d.ts +6 -0
  38. package/browser/driver/mysql/MysqlConnectionOptions.js.map +1 -1
  39. package/browser/driver/mysql/MysqlDriver.js +4 -2
  40. package/browser/driver/mysql/MysqlDriver.js.map +1 -1
  41. package/browser/driver/nativescript/NativescriptQueryRunner.js +45 -37
  42. package/browser/driver/nativescript/NativescriptQueryRunner.js.map +1 -1
  43. package/browser/driver/oracle/OracleConnectionOptions.d.ts +5 -0
  44. package/browser/driver/oracle/OracleConnectionOptions.js.map +1 -1
  45. package/browser/driver/oracle/OracleDriver.js +5 -4
  46. package/browser/driver/oracle/OracleDriver.js.map +1 -1
  47. package/browser/driver/postgres/PostgresConnectionOptions.d.ts +10 -0
  48. package/browser/driver/postgres/PostgresConnectionOptions.js.map +1 -1
  49. package/browser/driver/postgres/PostgresDriver.d.ts +2 -2
  50. package/browser/driver/postgres/PostgresDriver.js +36 -44
  51. package/browser/driver/postgres/PostgresDriver.js.map +1 -1
  52. package/browser/driver/postgres/PostgresQueryRunner.js +7 -15
  53. package/browser/driver/postgres/PostgresQueryRunner.js.map +1 -1
  54. package/browser/driver/react-native/ReactNativeConnectionOptions.d.ts +5 -0
  55. package/browser/driver/react-native/ReactNativeConnectionOptions.js.map +1 -1
  56. package/browser/driver/react-native/ReactNativeDriver.js +2 -1
  57. package/browser/driver/react-native/ReactNativeDriver.js.map +1 -1
  58. package/browser/driver/sap/SapConnectionOptions.d.ts +16 -6
  59. package/browser/driver/sap/SapConnectionOptions.js.map +1 -1
  60. package/browser/driver/sap/SapDriver.js +6 -3
  61. package/browser/driver/sap/SapDriver.js.map +1 -1
  62. package/browser/driver/sap/SapQueryRunner.js +10 -28
  63. package/browser/driver/sap/SapQueryRunner.js.map +1 -1
  64. package/browser/driver/sqlite/SqliteConnectionOptions.d.ts +5 -0
  65. package/browser/driver/sqlite/SqliteConnectionOptions.js.map +1 -1
  66. package/browser/driver/sqlite/SqliteDriver.js +4 -3
  67. package/browser/driver/sqlite/SqliteDriver.js.map +1 -1
  68. package/browser/driver/sqljs/SqljsConnectionOptions.d.ts +5 -0
  69. package/browser/driver/sqljs/SqljsConnectionOptions.js.map +1 -1
  70. package/browser/driver/sqljs/SqljsDriver.js +9 -24
  71. package/browser/driver/sqljs/SqljsDriver.js.map +1 -1
  72. package/browser/driver/sqljs/SqljsQueryRunner.js +9 -10
  73. package/browser/driver/sqljs/SqljsQueryRunner.js.map +1 -1
  74. package/browser/driver/sqlserver/SqlServerConnectionOptions.d.ts +5 -0
  75. package/browser/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
  76. package/browser/driver/sqlserver/SqlServerDriver.js +7 -6
  77. package/browser/driver/sqlserver/SqlServerDriver.js.map +1 -1
  78. package/browser/find-options/FindOptionsUtils.d.ts +2 -0
  79. package/browser/find-options/FindOptionsUtils.js +19 -1
  80. package/browser/find-options/FindOptionsUtils.js.map +1 -1
  81. package/browser/metadata/EntityMetadata.d.ts +5 -0
  82. package/browser/metadata/EntityMetadata.js +1 -0
  83. package/browser/metadata/EntityMetadata.js.map +1 -1
  84. package/browser/metadata-args/TableMetadataArgs.d.ts +4 -0
  85. package/browser/metadata-args/TableMetadataArgs.js.map +1 -1
  86. package/browser/migration/MigrationExecutor.d.ts +1 -1
  87. package/browser/migration/MigrationExecutor.js +6 -14
  88. package/browser/migration/MigrationExecutor.js.map +1 -1
  89. package/browser/persistence/SubjectExecutor.js +3 -3
  90. package/browser/persistence/SubjectExecutor.js.map +1 -1
  91. package/browser/persistence/subject-builder/OneToManySubjectBuilder.js +10 -4
  92. package/browser/persistence/subject-builder/OneToManySubjectBuilder.js.map +1 -1
  93. package/browser/query-builder/QueryExpressionMap.d.ts +6 -0
  94. package/browser/query-builder/QueryExpressionMap.js.map +1 -1
  95. package/browser/query-builder/SelectQueryBuilder.d.ts +7 -1
  96. package/browser/query-builder/SelectQueryBuilder.js +42 -6
  97. package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
  98. package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js +2 -8
  99. package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
  100. package/browser/query-runner/BaseQueryRunner.js +3 -2
  101. package/browser/query-runner/BaseQueryRunner.js.map +1 -1
  102. package/browser/repository/TreeRepository.d.ts +3 -3
  103. package/browser/repository/TreeRepository.js +28 -39
  104. package/browser/repository/TreeRepository.js.map +1 -1
  105. package/browser/schema-builder/RdbmsSchemaBuilder.js +223 -148
  106. package/browser/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
  107. package/browser/schema-builder/util/ViewUtils.d.ts +7 -0
  108. package/browser/schema-builder/util/ViewUtils.js +25 -0
  109. package/browser/schema-builder/util/ViewUtils.js.map +1 -0
  110. package/commands/InitCommand.js +2 -1
  111. package/commands/InitCommand.js.map +1 -1
  112. package/connection/ConnectionOptionsReader.js +2 -1
  113. package/connection/ConnectionOptionsReader.js.map +1 -1
  114. package/decorator/entity-view/ViewEntity.js +1 -0
  115. package/decorator/entity-view/ViewEntity.js.map +1 -1
  116. package/decorator/options/ViewEntityOptions.d.ts +5 -0
  117. package/decorator/options/ViewEntityOptions.js.map +1 -1
  118. package/driver/aurora-data-api/AuroraDataApiConnectionOptions.d.ts +5 -0
  119. package/driver/aurora-data-api/AuroraDataApiConnectionOptions.js.map +1 -1
  120. package/driver/aurora-data-api/AuroraDataApiDriver.js +6 -5
  121. package/driver/aurora-data-api/AuroraDataApiDriver.js.map +1 -1
  122. package/driver/aurora-data-api-pg/AuroraDataApiPostgresConnectionOptions.d.ts +5 -0
  123. package/driver/aurora-data-api-pg/AuroraDataApiPostgresConnectionOptions.js.map +1 -1
  124. package/driver/aurora-data-api-pg/AuroraDataApiPostgresDriver.js +2 -1
  125. package/driver/aurora-data-api-pg/AuroraDataApiPostgresDriver.js.map +1 -1
  126. package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +5 -0
  127. package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
  128. package/driver/better-sqlite3/BetterSqlite3Driver.js +2 -1
  129. package/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
  130. package/driver/cockroachdb/CockroachConnectionOptions.d.ts +10 -0
  131. package/driver/cockroachdb/CockroachConnectionOptions.js.map +1 -1
  132. package/driver/cockroachdb/CockroachDriver.js +27 -17
  133. package/driver/cockroachdb/CockroachDriver.js.map +1 -1
  134. package/driver/cockroachdb/CockroachQueryRunner.js +63 -69
  135. package/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
  136. package/driver/cordova/CordovaConnectionOptions.d.ts +5 -0
  137. package/driver/cordova/CordovaConnectionOptions.js.map +1 -1
  138. package/driver/cordova/CordovaDriver.d.ts +1 -1
  139. package/driver/cordova/CordovaDriver.js +27 -19
  140. package/driver/cordova/CordovaDriver.js.map +1 -1
  141. package/driver/cordova/CordovaQueryRunner.js +50 -43
  142. package/driver/cordova/CordovaQueryRunner.js.map +1 -1
  143. package/driver/mongodb/MongoConnectionOptions.d.ts +5 -0
  144. package/driver/mongodb/MongoConnectionOptions.js.map +1 -1
  145. package/driver/mongodb/MongoDriver.js +2 -1
  146. package/driver/mongodb/MongoDriver.js.map +1 -1
  147. package/driver/mysql/MysqlConnectionOptions.d.ts +6 -0
  148. package/driver/mysql/MysqlConnectionOptions.js.map +1 -1
  149. package/driver/mysql/MysqlDriver.js +4 -2
  150. package/driver/mysql/MysqlDriver.js.map +1 -1
  151. package/driver/nativescript/NativescriptQueryRunner.js +45 -37
  152. package/driver/nativescript/NativescriptQueryRunner.js.map +1 -1
  153. package/driver/oracle/OracleConnectionOptions.d.ts +5 -0
  154. package/driver/oracle/OracleConnectionOptions.js.map +1 -1
  155. package/driver/oracle/OracleDriver.js +5 -4
  156. package/driver/oracle/OracleDriver.js.map +1 -1
  157. package/driver/postgres/PostgresConnectionOptions.d.ts +10 -0
  158. package/driver/postgres/PostgresConnectionOptions.js.map +1 -1
  159. package/driver/postgres/PostgresDriver.d.ts +2 -2
  160. package/driver/postgres/PostgresDriver.js +36 -44
  161. package/driver/postgres/PostgresDriver.js.map +1 -1
  162. package/driver/postgres/PostgresQueryRunner.js +7 -15
  163. package/driver/postgres/PostgresQueryRunner.js.map +1 -1
  164. package/driver/react-native/ReactNativeConnectionOptions.d.ts +5 -0
  165. package/driver/react-native/ReactNativeConnectionOptions.js.map +1 -1
  166. package/driver/react-native/ReactNativeDriver.js +2 -1
  167. package/driver/react-native/ReactNativeDriver.js.map +1 -1
  168. package/driver/sap/SapConnectionOptions.d.ts +16 -6
  169. package/driver/sap/SapConnectionOptions.js.map +1 -1
  170. package/driver/sap/SapDriver.js +6 -3
  171. package/driver/sap/SapDriver.js.map +1 -1
  172. package/driver/sap/SapQueryRunner.js +10 -28
  173. package/driver/sap/SapQueryRunner.js.map +1 -1
  174. package/driver/sqlite/SqliteConnectionOptions.d.ts +5 -0
  175. package/driver/sqlite/SqliteConnectionOptions.js.map +1 -1
  176. package/driver/sqlite/SqliteDriver.js +2 -1
  177. package/driver/sqlite/SqliteDriver.js.map +1 -1
  178. package/driver/sqljs/SqljsConnectionOptions.d.ts +5 -0
  179. package/driver/sqljs/SqljsConnectionOptions.js.map +1 -1
  180. package/driver/sqljs/SqljsDriver.js +9 -24
  181. package/driver/sqljs/SqljsDriver.js.map +1 -1
  182. package/driver/sqljs/SqljsQueryRunner.js +9 -10
  183. package/driver/sqljs/SqljsQueryRunner.js.map +1 -1
  184. package/driver/sqlserver/SqlServerConnectionOptions.d.ts +5 -0
  185. package/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
  186. package/driver/sqlserver/SqlServerDriver.js +7 -6
  187. package/driver/sqlserver/SqlServerDriver.js.map +1 -1
  188. package/find-options/FindOptionsUtils.d.ts +2 -0
  189. package/find-options/FindOptionsUtils.js +19 -1
  190. package/find-options/FindOptionsUtils.js.map +1 -1
  191. package/metadata/EntityMetadata.d.ts +5 -0
  192. package/metadata/EntityMetadata.js +1 -0
  193. package/metadata/EntityMetadata.js.map +1 -1
  194. package/metadata-args/TableMetadataArgs.d.ts +4 -0
  195. package/metadata-args/TableMetadataArgs.js.map +1 -1
  196. package/migration/MigrationExecutor.d.ts +1 -1
  197. package/migration/MigrationExecutor.js +6 -14
  198. package/migration/MigrationExecutor.js.map +1 -1
  199. package/package.json +239 -1
  200. package/persistence/SubjectExecutor.js +3 -3
  201. package/persistence/SubjectExecutor.js.map +1 -1
  202. package/persistence/subject-builder/OneToManySubjectBuilder.js +10 -4
  203. package/persistence/subject-builder/OneToManySubjectBuilder.js.map +1 -1
  204. package/query-builder/QueryExpressionMap.d.ts +6 -0
  205. package/query-builder/QueryExpressionMap.js.map +1 -1
  206. package/query-builder/SelectQueryBuilder.d.ts +7 -1
  207. package/query-builder/SelectQueryBuilder.js +42 -6
  208. package/query-builder/SelectQueryBuilder.js.map +1 -1
  209. package/query-builder/transformer/RawSqlResultsToEntityTransformer.js +2 -8
  210. package/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
  211. package/query-runner/BaseQueryRunner.js +3 -2
  212. package/query-runner/BaseQueryRunner.js.map +1 -1
  213. package/repository/TreeRepository.d.ts +3 -3
  214. package/repository/TreeRepository.js +27 -38
  215. package/repository/TreeRepository.js.map +1 -1
  216. package/schema-builder/RdbmsSchemaBuilder.js +222 -147
  217. package/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
  218. package/schema-builder/util/ViewUtils.d.ts +7 -0
  219. package/schema-builder/util/ViewUtils.js +28 -0
  220. package/schema-builder/util/ViewUtils.js.map +1 -0
@@ -11,6 +11,11 @@ export interface SqliteConnectionOptions extends BaseConnectionOptions {
11
11
  * Storage type or path to the storage.
12
12
  */
13
13
  readonly database: string;
14
+ /**
15
+ * The driver object
16
+ * This defaults to require("sqlite3")
17
+ */
18
+ readonly driver?: any;
14
19
  /**
15
20
  * Encryption key for for SQLCipher.
16
21
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/driver/sqlite/SqliteConnectionOptions.ts"],"names":[],"mappings":"","file":"SqliteConnectionOptions.js","sourcesContent":["import {BaseConnectionOptions} from \"../../connection/BaseConnectionOptions\";\n\n/**\n * Sqlite-specific connection options.\n */\nexport interface SqliteConnectionOptions extends BaseConnectionOptions {\n\n /**\n * Database type.\n */\n readonly type: \"sqlite\";\n\n /**\n * Storage type or path to the storage.\n */\n readonly database: string;\n\n /**\n * Encryption key for for SQLCipher.\n */\n readonly key?: string;\n\n /**\n * In your SQLite application when you perform parallel writes its common to face SQLITE_BUSY error.\n * This error indicates that SQLite failed to write to the database file since someone else already writes into it.\n * Since SQLite cannot handle parallel saves this error cannot be avoided.\n *\n * To simplify life's of those who have this error this particular option sets a timeout within which ORM will try\n * to perform requested write operation again and again until it receives SQLITE_BUSY error.\n *\n * Enabling WAL can improve your app performance and face less SQLITE_BUSY issues.\n * Time in milliseconds.\n */\n readonly busyErrorRetry?: number;\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}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../browser/src/driver/sqlite/SqliteConnectionOptions.ts"],"names":[],"mappings":"","file":"SqliteConnectionOptions.js","sourcesContent":["import {BaseConnectionOptions} from \"../../connection/BaseConnectionOptions\";\n\n/**\n * Sqlite-specific connection options.\n */\nexport interface SqliteConnectionOptions extends BaseConnectionOptions {\n\n /**\n * Database type.\n */\n readonly type: \"sqlite\";\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(\"sqlite3\")\n */\n readonly driver?: any;\n\n /**\n * Encryption key for for SQLCipher.\n */\n readonly key?: string;\n\n /**\n * In your SQLite application when you perform parallel writes its common to face SQLITE_BUSY error.\n * This error indicates that SQLite failed to write to the database file since someone else already writes into it.\n * Since SQLite cannot handle parallel saves this error cannot be avoided.\n *\n * To simplify life's of those who have this error this particular option sets a timeout within which ORM will try\n * to perform requested write operation again and again until it receives SQLITE_BUSY error.\n *\n * Enabling WAL can improve your app performance and face less SQLITE_BUSY issues.\n * Time in milliseconds.\n */\n readonly busyErrorRetry?: number;\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}\n"],"sourceRoot":"../.."}
@@ -1,6 +1,6 @@
1
1
  import { __awaiter, __extends, __generator } from "tslib";
2
- import mkdirp from 'mkdirp';
3
- import path from 'path';
2
+ import mkdirp from "mkdirp";
3
+ import path from "path";
4
4
  import { DriverPackageNotInstalledError } from "../../error/DriverPackageNotInstalledError";
5
5
  import { SqliteQueryRunner } from "./SqliteQueryRunner";
6
6
  import { DriverOptionNotSetError } from "../../error/DriverOptionNotSetError";
@@ -119,7 +119,8 @@ var SqliteDriver = /** @class */ (function (_super) {
119
119
  */
120
120
  SqliteDriver.prototype.loadDependencies = function () {
121
121
  try {
122
- this.sqlite = PlatformTools.load("sqlite3").verbose();
122
+ var sqlite = this.options.driver || PlatformTools.load("sqlite3");
123
+ this.sqlite = sqlite.verbose();
123
124
  }
124
125
  catch (e) {
125
126
  throw new DriverPackageNotInstalledError("SQLite", "sqlite3");
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/driver/s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kB,GAAQ,SAK9B;6BAYE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAtB,wBAAsB;wBACtB,qBAAM,GAAG,CAAC,4BAA4B,CAAC,EAAA;;wBAAvC,SAAuC,CAAC;;;oBAG5C,yFAAyF;oBACzF,kEAAkE;oBAClE,qBAAM,GAAG,CAAC,2BAA2B,CAAC,EAAA;;wBAFtC,yFAAyF;wBACzF,kEAAkE;wBAClE,SAAsC,CAAC;6BAGnC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAhB,wBAAgB;wBAChB,qBAAM,GAAG,CAAC,kBAAgB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAG,CAAC,EAAA;;wBAA9D,SAA8D,CAAC;;4BAGnE,sBAAO,kBAAkB,EAAC;;;;KAC7B;IAED;;OAEG;IACO,uCAAgB,GAA1B;QACI,IAAI;YACA,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC;SAEzD;QAAC,OAAO,CAAC,EAAE;YACR,MAAM,IAAI,8BAA8B,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;SACjE;IACL,CAAC;IAED;;OAEG;IACa,8CAAuB,GAAvC,UAAwC,QAAgB;;;;4BACpD,qBAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAA;;wBAApC,SAAoC,CAAC;;;;;KACxC;IAEL,mBAAC;AAAD,CAjIA,AAiIC,CAjIiC,oBAAoB,GAiIrD","file":"SqliteDriver.js","sourcesContent":["import mkdirp from 'mkdirp';\nimport path from 'path';\nimport { DriverPackageNotInstalledError } from \"../../error/DriverPackageNotInstalledError\";\nimport { SqliteQueryRunner } from \"./SqliteQueryRunner\";\nimport { DriverOptionNotSetError } from \"../../error/DriverOptionNotSetError\";\nimport { PlatformTools } from \"../../platform/PlatformTools\";\nimport { Connection } from \"../../connection/Connection\";\nimport { SqliteConnectionOptions } from \"./SqliteConnectionOptions\";\nimport { ColumnType } from \"../types/ColumnTypes\";\nimport { QueryRunner } from \"../../query-runner/QueryRunner\";\nimport { AbstractSqliteDriver } from \"../sqlite-abstract/AbstractSqliteDriver\";\nimport {ReplicationMode} from \"../types/ReplicationMode\";\n\n/**\n * Organizes communication with sqlite DBMS.\n */\nexport class SqliteDriver extends AbstractSqliteDriver {\n\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection options.\n */\n options: SqliteConnectionOptions;\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 SqliteConnectionOptions;\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 return new Promise<void>((ok, fail) => {\n this.queryRunner = undefined;\n this.databaseConnection.close((err: any) => err ? fail(err) : ok());\n });\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 SqliteQueryRunner(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 await this.createDatabaseDirectory(this.options.database);\n\n const databaseConnection: any = await new Promise((ok, fail) => {\n const connection = new this.sqlite.Database(this.options.database, (err: any) => {\n if (err) return fail(err);\n ok(connection);\n });\n });\n\n // Internal function to run a command on the connection and fail if an error occured.\n function run(line: string): Promise<void> {\n return new Promise((ok, fail) => {\n databaseConnection.run(line, (err: any) => {\n if (err) return fail(err);\n ok();\n });\n });\n }\n\n if (this.options.enableWAL) {\n await run(`PRAGMA journal_mode = WAL;`);\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 await run(`PRAGMA foreign_keys = ON;`);\n\n // in the options, if encryption key for SQLCipher is setted.\n if (this.options.key) {\n await run(`PRAGMA key = ${JSON.stringify(this.options.key)};`);\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 this.sqlite = PlatformTools.load(\"sqlite3\").verbose();\n\n } catch (e) {\n throw new DriverPackageNotInstalledError(\"SQLite\", \"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/sqlite/SqliteDriver.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,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAK7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAG/E;;GAEG;AACH;IAAkC,gCAAoB;IAgBlD,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,sBAAY,UAAsB;QAAlC,YACI,kBAAM,UAAU,CAAC,SAYpB;QAVG,KAAI,CAAC,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AgB,GAA1B;QACI,IAAI;YACA,IAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACpE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;SAElC;QAAC,OAAO,CAAC,EAAE;YACR,MAAM,IAAI,8BAA8B,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;SACjE;IACL,CAAC;IAED;;OAEG;IACa,8CAAuB,GAAvC,UAAwC,QAAgB;;;;4BACpD,qBAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAA;;wBAApC,SAAoC,CAAC;;;;;KACxC;IAEL,mBAAC;AAAD,CAlIA,AAkIC,CAlIiC,oBAAoB,GAkIrD","file":"SqliteDriver.js","sourcesContent":["import mkdirp from \"mkdirp\";\nimport path from \"path\";\nimport { DriverPackageNotInstalledError } from \"../../error/DriverPackageNotInstalledError\";\nimport { SqliteQueryRunner } from \"./SqliteQueryRunner\";\nimport { DriverOptionNotSetError } from \"../../error/DriverOptionNotSetError\";\nimport { PlatformTools } from \"../../platform/PlatformTools\";\nimport { Connection } from \"../../connection/Connection\";\nimport { SqliteConnectionOptions } from \"./SqliteConnectionOptions\";\nimport { ColumnType } from \"../types/ColumnTypes\";\nimport { QueryRunner } from \"../../query-runner/QueryRunner\";\nimport { AbstractSqliteDriver } from \"../sqlite-abstract/AbstractSqliteDriver\";\nimport {ReplicationMode} from \"../types/ReplicationMode\";\n\n/**\n * Organizes communication with sqlite DBMS.\n */\nexport class SqliteDriver extends AbstractSqliteDriver {\n\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection options.\n */\n options: SqliteConnectionOptions;\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 SqliteConnectionOptions;\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 return new Promise<void>((ok, fail) => {\n this.queryRunner = undefined;\n this.databaseConnection.close((err: any) => err ? fail(err) : ok());\n });\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 SqliteQueryRunner(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 await this.createDatabaseDirectory(this.options.database);\n\n const databaseConnection: any = await new Promise((ok, fail) => {\n const connection = new this.sqlite.Database(this.options.database, (err: any) => {\n if (err) return fail(err);\n ok(connection);\n });\n });\n\n // Internal function to run a command on the connection and fail if an error occured.\n function run(line: string): Promise<void> {\n return new Promise((ok, fail) => {\n databaseConnection.run(line, (err: any) => {\n if (err) return fail(err);\n ok();\n });\n });\n }\n\n if (this.options.enableWAL) {\n await run(`PRAGMA journal_mode = WAL;`);\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 await run(`PRAGMA foreign_keys = ON;`);\n\n // in the options, if encryption key for SQLCipher is setted.\n if (this.options.key) {\n await run(`PRAGMA key = ${JSON.stringify(this.options.key)};`);\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 = this.options.driver || PlatformTools.load(\"sqlite3\");\n this.sqlite = sqlite.verbose();\n\n } catch (e) {\n throw new DriverPackageNotInstalledError(\"SQLite\", \"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":"../.."}
@@ -11,6 +11,11 @@ export interface SqljsConnectionOptions extends BaseConnectionOptions {
11
11
  * A Uint8Array that gets imported when the connection is opened.
12
12
  */
13
13
  readonly database?: Uint8Array;
14
+ /**
15
+ * The driver object
16
+ * This defaults to require("sql.js")
17
+ */
18
+ readonly driver?: any;
14
19
  /**
15
20
  * Config that's used to initialize sql.js.
16
21
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/driver/sqljs/SqljsConnectionOptions.ts"],"names":[],"mappings":"","file":"SqljsConnectionOptions.js","sourcesContent":["import {BaseConnectionOptions} from \"../../connection/BaseConnectionOptions\";\n\n/**\n * Sql.js-specific connection options.\n */\nexport interface SqljsConnectionOptions extends BaseConnectionOptions {\n\n /**\n * Database type.\n */\n readonly type: \"sqljs\";\n\n /**\n * A Uint8Array that gets imported when the connection is opened.\n */\n readonly database?: Uint8Array;\n\n /**\n * Config that's used to initialize sql.js.\n */\n readonly sqlJsConfig?: any;\n\n /**\n * Enables the autoSave mechanism which either saves to location\n * or calls autoSaveCallback every time a change to the database is made.\n */\n readonly autoSave?: boolean;\n\n /**\n * A function that gets called on every change instead of the internal autoSave function.\n * autoSave has to be enabled for this to work.\n */\n readonly autoSaveCallback?: Function;\n\n /**\n * File path (Node.js) or local storage key (browser) to load and save database from.\n * If this is specified without autoSave, the database is loaded from the location\n * and can be saved manually via the SqljsEntityManager. If autoSave is enabled,\n * location is used to automatically save the database.\n */\n readonly location?: string;\n\n /**\n * Enables the usage of the localforage library to save & load the database asynchronously from the\n * indexedDB instead of using the synchron local storage methods in a browser environment.\n */\n readonly useLocalForage?: boolean;\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../browser/src/driver/sqljs/SqljsConnectionOptions.ts"],"names":[],"mappings":"","file":"SqljsConnectionOptions.js","sourcesContent":["import {BaseConnectionOptions} from \"../../connection/BaseConnectionOptions\";\n\n/**\n * Sql.js-specific connection options.\n */\nexport interface SqljsConnectionOptions extends BaseConnectionOptions {\n\n /**\n * Database type.\n */\n readonly type: \"sqljs\";\n\n /**\n * A Uint8Array that gets imported when the connection is opened.\n */\n readonly database?: Uint8Array;\n\n /**\n * The driver object\n * This defaults to require(\"sql.js\")\n */\n readonly driver?: any;\n\n /**\n * Config that's used to initialize sql.js.\n */\n readonly sqlJsConfig?: any;\n\n /**\n * Enables the autoSave mechanism which either saves to location\n * or calls autoSaveCallback every time a change to the database is made.\n */\n readonly autoSave?: boolean;\n\n /**\n * A function that gets called on every change instead of the internal autoSave function.\n * autoSave has to be enabled for this to work.\n */\n readonly autoSaveCallback?: Function;\n\n /**\n * File path (Node.js) or local storage key (browser) to load and save database from.\n * If this is specified without autoSave, the database is loaded from the location\n * and can be saved manually via the SqljsEntityManager. If autoSave is enabled,\n * location is used to automatically save the database.\n */\n readonly location?: string;\n\n /**\n * Enables the usage of the localforage library to save & load the database asynchronously from the\n * indexedDB instead of using the synchron local storage methods in a browser environment.\n */\n readonly useLocalForage?: boolean;\n}\n"],"sourceRoot":"../.."}
@@ -48,18 +48,10 @@ var SqljsDriver = /** @class */ (function (_super) {
48
48
  */
49
49
  SqljsDriver.prototype.disconnect = function () {
50
50
  return __awaiter(this, void 0, void 0, function () {
51
- var _this = this;
52
51
  return __generator(this, function (_a) {
53
- return [2 /*return*/, new Promise(function (ok, fail) {
54
- try {
55
- _this.queryRunner = undefined;
56
- _this.databaseConnection.close();
57
- ok();
58
- }
59
- catch (e) {
60
- fail(e);
61
- }
62
- })];
52
+ this.queryRunner = undefined;
53
+ this.databaseConnection.close();
54
+ return [2 /*return*/];
63
55
  });
64
56
  });
65
57
  };
@@ -262,7 +254,6 @@ var SqljsDriver = /** @class */ (function (_super) {
262
254
  SqljsDriver.prototype.createDatabaseConnectionWithImport = function (database) {
263
255
  return __awaiter(this, void 0, void 0, function () {
264
256
  var isLegacyVersion, sqlite, _a;
265
- var _this = this;
266
257
  return __generator(this, function (_b) {
267
258
  switch (_b.label) {
268
259
  case 0:
@@ -282,16 +273,8 @@ var SqljsDriver = /** @class */ (function (_super) {
282
273
  else {
283
274
  this.databaseConnection = new sqlite.Database();
284
275
  }
285
- // Enable foreign keys for database
286
- return [2 /*return*/, new Promise(function (ok, fail) {
287
- try {
288
- _this.databaseConnection.exec("PRAGMA foreign_keys = ON;");
289
- ok(_this.databaseConnection);
290
- }
291
- catch (e) {
292
- fail(e);
293
- }
294
- })];
276
+ this.databaseConnection.exec("PRAGMA foreign_keys = ON;");
277
+ return [2 /*return*/, this.databaseConnection];
295
278
  }
296
279
  });
297
280
  });
@@ -301,11 +284,13 @@ var SqljsDriver = /** @class */ (function (_super) {
301
284
  */
302
285
  SqljsDriver.prototype.loadDependencies = function () {
303
286
  if (PlatformTools.type === "browser") {
304
- this.sqlite = window.SQL;
287
+ var sqlite = this.options.driver || window.SQL;
288
+ this.sqlite = sqlite;
305
289
  }
306
290
  else {
307
291
  try {
308
- this.sqlite = PlatformTools.load("sql.js");
292
+ var sqlite = this.options.driver || PlatformTools.load("sql.js");
293
+ this.sqlite = sqlite;
309
294
  }
310
295
  catch (e) {
311
296
  throw new DriverPackageNotInstalledError("sql.js", "sql.js");
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/driver/sqljs/SqljsDriver.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,oBAAoB,EAAC,MAAM,yCAAyC,CAAC;AAE7E,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAGpD,OAAO,EAAC,8BAA8B,EAAC,MAAM,4CAA4C,CAAC;AAC1F,OAAO,EAAC,uBAAuB,EAAC,MAAM,qCAAqC,CAAC;AAC5E,OAAO,E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CAAC,MAAM,GAAG,CAAC,EAAE;4BACjC,IAAI,CAAC,kBAAkB,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;yBAC3D;6BACI;4BACD,IAAI,CAAC,kBAAkB,GAAG,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;yBACnD;wBAED,mCAAmC;wBACnC,sBAAO,IAAI,OAAO,CAAM,UAAC,EAAE,EAAE,IAAI;gCAC7B,IAAI;oCACA,KAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;oCAC1D,EAAE,CAAC,KAAI,CAAC,kBAAkB,CAAC,CAAC;iCAC/B;gCACD,OAAO,CAAC,EAAE;oCACN,IAAI,CAAC,CAAC,CAAC,CAAC;iCACX;4BACL,CAAC,CAAC,EAAC;;;;KACN;IAED;;OAEG;IACO,sCAAgB,GAA1B;QACI,IAAI,aAAa,CAAC,IAAI,KAAK,SAAS,EAAE;YAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC;SAC5B;aACI;YACD,IAAI;gBACA,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;aAE9C;YAAC,OAAO,CAAC,EAAE;gBACR,MAAM,IAAI,8BAA8B,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;aAChE;SACJ;IACL,CAAC;IACL,kBAAC;AAAD,CA3QA,AA2QC,CA3QgC,oBAAoB,GA2QpD","file":"SqljsDriver.js","sourcesContent":["import {AbstractSqliteDriver} from \"../sqlite-abstract/AbstractSqliteDriver\";\nimport {SqljsConnectionOptions} from \"./SqljsConnectionOptions\";\nimport {SqljsQueryRunner} from \"./SqljsQueryRunner\";\nimport {QueryRunner} from \"../../query-runner/QueryRunner\";\nimport {Connection} from \"../../connection/Connection\";\nimport {DriverPackageNotInstalledError} from \"../../error/DriverPackageNotInstalledError\";\nimport {DriverOptionNotSetError} from \"../../error/DriverOptionNotSetError\";\nimport {PlatformTools} from \"../../platform/PlatformTools\";\nimport {EntityMetadata} from \"../../metadata/EntityMetadata\";\nimport {OrmUtils} from \"../../util/OrmUtils\";\nimport {ObjectLiteral} from \"../../common/ObjectLiteral\";\nimport {ReplicationMode} from \"../types/ReplicationMode\";\nimport { TypeORMError } from \"../../error\";\n\n// This is needed to satisfy the typescript compiler.\ninterface Window {\n SQL: any;\n localforage: any;\n}\ndeclare var window: Window;\n\nexport class SqljsDriver extends AbstractSqliteDriver {\n // The driver specific options.\n options: SqljsConnectionOptions;\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(connection: Connection) {\n super(connection);\n\n // If autoSave is enabled by user, location or autoSaveCallback have to be set\n // because either autoSave saves to location or calls autoSaveCallback.\n if (this.options.autoSave && !this.options.location && !this.options.autoSaveCallback) {\n throw new DriverOptionNotSetError(`location or autoSaveCallback`);\n }\n\n // load sql.js package\n this.loadDependencies();\n }\n\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Performs connection to the database.\n */\n async connect(): Promise<void> {\n this.databaseConnection = await this.createDatabaseConnection();\n }\n\n /**\n * Closes connection with database.\n */\n async disconnect(): Promise<void> {\n return new Promise<void>((ok, fail) => {\n try {\n this.queryRunner = undefined;\n this.databaseConnection.close();\n ok();\n }\n catch (e) {\n fail(e);\n }\n });\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 SqljsQueryRunner(this);\n\n return this.queryRunner;\n }\n\n /**\n * Loads a database from a given file (Node.js), local storage key (browser) or array.\n * This will delete the current database!\n */\n async load(fileNameOrLocalStorageOrData: string | Uint8Array, checkIfFileOrLocalStorageExists: boolean = true): Promise<any> {\n if (typeof fileNameOrLocalStorageOrData === \"string\") {\n // content has to be loaded\n if (PlatformTools.type === \"node\") {\n // Node.js\n // fileNameOrLocalStorageOrData should be a path to the file\n if (PlatformTools.fileExist(fileNameOrLocalStorageOrData)) {\n const database = PlatformTools.readFileSync(fileNameOrLocalStorageOrData);\n return this.createDatabaseConnectionWithImport(database);\n }\n else if (checkIfFileOrLocalStorageExists) {\n throw new TypeORMError(`File ${fileNameOrLocalStorageOrData} does not exist`);\n }\n else {\n // File doesn't exist and checkIfFileOrLocalStorageExists is set to false.\n // Therefore open a database without importing an existing file.\n // File will be written on first write operation.\n return this.createDatabaseConnectionWithImport();\n }\n }\n else {\n // browser\n // fileNameOrLocalStorageOrData should be a local storage / indexedDB key\n let localStorageContent = null;\n if (this.options.useLocalForage) {\n if (window.localforage) {\n localStorageContent = await window.localforage.getItem(fileNameOrLocalStorageOrData);\n } else {\n throw new TypeORMError(`localforage is not defined - please import localforage.js into your site`);\n }\n } else {\n localStorageContent = PlatformTools.getGlobalVariable().localStorage.getItem(fileNameOrLocalStorageOrData);\n }\n\n if (localStorageContent != null) {\n // localStorage value exists.\n return this.createDatabaseConnectionWithImport(JSON.parse(localStorageContent));\n }\n else if (checkIfFileOrLocalStorageExists) {\n throw new TypeORMError(`File ${fileNameOrLocalStorageOrData} does not exist`);\n }\n else {\n // localStorage value doesn't exist and checkIfFileOrLocalStorageExists is set to false.\n // Therefore open a database without importing anything.\n // localStorage value will be written on first write operation.\n return this.createDatabaseConnectionWithImport();\n }\n }\n }\n else {\n return this.createDatabaseConnectionWithImport(fileNameOrLocalStorageOrData);\n }\n }\n\n /**\n * Saved the current database to the given file (Node.js), local storage key (browser) or\n * indexedDB key (browser with enabled useLocalForage option).\n * If no location path is given, the location path in the options (if specified) will be used.\n */\n async save(location?: string) {\n if (!location && !this.options.location) {\n throw new TypeORMError(`No location is set, specify a location parameter or add the location option to your configuration`);\n }\n\n let path = \"\";\n if (location) {\n path = location;\n }\n else if (this.options.location) {\n path = this.options.location;\n }\n\n if (PlatformTools.type === \"node\") {\n try {\n const content = Buffer.from(this.databaseConnection.export());\n await PlatformTools.writeFile(path, content);\n }\n catch (e) {\n throw new TypeORMError(`Could not save database, error: ${e}`);\n }\n }\n else {\n const database: Uint8Array = this.databaseConnection.export();\n // convert Uint8Array to number array to improve local-storage storage\n const databaseArray = [].slice.call(database);\n if (this.options.useLocalForage) {\n if (window.localforage) {\n await window.localforage.setItem(path, JSON.stringify(databaseArray));\n } else {\n throw new TypeORMError(`localforage is not defined - please import localforage.js into your site`);\n }\n } else {\n PlatformTools.getGlobalVariable().localStorage.setItem(path, JSON.stringify(databaseArray));\n }\n }\n }\n\n /**\n * This gets called by the QueryRunner when a change to the database is made.\n * If a custom autoSaveCallback is specified, it get's called with the database as Uint8Array,\n * otherwise the save method is called which saves it to file (Node.js), local storage (browser)\n * or indexedDB (browser with enabled useLocalForage option).\n */\n async autoSave() {\n if (this.options.autoSave) {\n if (this.options.autoSaveCallback) {\n await this.options.autoSaveCallback(this.export());\n }\n else {\n await this.save();\n }\n }\n }\n\n /**\n * Returns the current database as Uint8Array.\n */\n export(): Uint8Array {\n return this.databaseConnection.export();\n }\n\n /**\n * Creates generated map of values generated or returned by database after INSERT query.\n */\n createGeneratedMap(metadata: EntityMetadata, insertResult: any) {\n const generatedMap = metadata.generatedColumns.reduce((map, generatedColumn) => {\n // seems to be the only way to get the inserted id, see https://github.com/kripken/sql.js/issues/77\n if (generatedColumn.isPrimary && generatedColumn.generationStrategy === \"increment\") {\n const query = \"SELECT last_insert_rowid()\";\n try {\n let result = this.databaseConnection.exec(query);\n this.connection.logger.logQuery(query);\n return OrmUtils.mergeDeep(map, generatedColumn.createValueMap(result[0].values[0][0]));\n }\n catch (e) {\n this.connection.logger.logQueryError(e, query, []);\n }\n }\n\n return map;\n }, {} as ObjectLiteral);\n\n return Object.keys(generatedMap).length > 0 ? generatedMap : undefined;\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates connection with the database.\n * If the location option is set, the database is loaded first.\n */\n protected createDatabaseConnection(): Promise<any> {\n if (this.options.location) {\n return this.load(this.options.location, false);\n }\n\n return this.createDatabaseConnectionWithImport(this.options.database);\n }\n\n /**\n * Creates connection with an optional database.\n * If database is specified it is loaded, otherwise a new empty database is created.\n */\n protected async createDatabaseConnectionWithImport(database?: Uint8Array): Promise<any> {\n // sql.js < 1.0 exposes an object with a `Database` method.\n const isLegacyVersion = typeof this.sqlite.Database === \"function\";\n const sqlite = isLegacyVersion ? this.sqlite : await this.sqlite(this.options.sqlJsConfig);\n if (database && database.length > 0) {\n this.databaseConnection = new sqlite.Database(database);\n }\n else {\n this.databaseConnection = new sqlite.Database();\n }\n\n // Enable foreign keys for database\n return new Promise<any>((ok, fail) => {\n try {\n this.databaseConnection.exec(`PRAGMA foreign_keys = ON;`);\n ok(this.databaseConnection);\n }\n catch (e) {\n fail(e);\n }\n });\n }\n\n /**\n * If driver dependency is not given explicitly, then try to load it via \"require\".\n */\n protected loadDependencies(): void {\n if (PlatformTools.type === \"browser\") {\n this.sqlite = window.SQL;\n }\n else {\n try {\n this.sqlite = PlatformTools.load(\"sql.js\");\n\n } catch (e) {\n throw new DriverPackageNotInstalledError(\"sql.js\", \"sql.js\");\n }\n }\n }\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../browser/src/driver/sqljs/SqljsDriver.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,oBAAoB,EAAC,MAAM,yCAAyC,CAAC;AAE7E,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAGpD,OAAO,EAAC,8BAA8B,EAAC,MAAM,4CAA4C,CAAC;AAC1F,OAAO,EAAC,uBAAuB,EAAC,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAC,aAAa,EAAC,MAAM,8BAA8B,CAAC;AAE3D,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAS3C;IAAiC,+BAAoB;IAIjD,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,qBAAY,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AM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,GAAG,CAAC;YACjD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;SACxB;aACI;YACD,IAAI;gBACA,IAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACnE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;aAExB;YAAC,OAAO,CAAC,EAAE;gBACR,MAAM,IAAI,8BAA8B,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;aAChE;SACJ;IACL,CAAC;IACL,kBAAC;AAAD,CA9PA,AA8PC,CA9PgC,oBAAoB,GA8PpD","file":"SqljsDriver.js","sourcesContent":["import {AbstractSqliteDriver} from \"../sqlite-abstract/AbstractSqliteDriver\";\nimport {SqljsConnectionOptions} from \"./SqljsConnectionOptions\";\nimport {SqljsQueryRunner} from \"./SqljsQueryRunner\";\nimport {QueryRunner} from \"../../query-runner/QueryRunner\";\nimport {Connection} from \"../../connection/Connection\";\nimport {DriverPackageNotInstalledError} from \"../../error/DriverPackageNotInstalledError\";\nimport {DriverOptionNotSetError} from \"../../error/DriverOptionNotSetError\";\nimport {PlatformTools} from \"../../platform/PlatformTools\";\nimport {EntityMetadata} from \"../../metadata/EntityMetadata\";\nimport {OrmUtils} from \"../../util/OrmUtils\";\nimport {ObjectLiteral} from \"../../common/ObjectLiteral\";\nimport {ReplicationMode} from \"../types/ReplicationMode\";\nimport { TypeORMError } from \"../../error\";\n\n// This is needed to satisfy the typescript compiler.\ninterface Window {\n SQL: any;\n localforage: any;\n}\ndeclare let window: Window;\n\nexport class SqljsDriver extends AbstractSqliteDriver {\n // The driver specific options.\n options: SqljsConnectionOptions;\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(connection: Connection) {\n super(connection);\n\n // If autoSave is enabled by user, location or autoSaveCallback have to be set\n // because either autoSave saves to location or calls autoSaveCallback.\n if (this.options.autoSave && !this.options.location && !this.options.autoSaveCallback) {\n throw new DriverOptionNotSetError(`location or autoSaveCallback`);\n }\n\n // load sql.js package\n this.loadDependencies();\n }\n\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Performs connection to the database.\n */\n async connect(): Promise<void> {\n this.databaseConnection = await this.createDatabaseConnection();\n }\n\n /**\n * Closes connection with database.\n */\n async disconnect(): Promise<void> {\n this.queryRunner = undefined;\n this.databaseConnection.close();\n }\n\n /**\n * Creates a query runner used to execute database queries.\n */\n createQueryRunner(mode: ReplicationMode): QueryRunner {\n if (!this.queryRunner)\n this.queryRunner = new SqljsQueryRunner(this);\n\n return this.queryRunner;\n }\n\n /**\n * Loads a database from a given file (Node.js), local storage key (browser) or array.\n * This will delete the current database!\n */\n async load(fileNameOrLocalStorageOrData: string | Uint8Array, checkIfFileOrLocalStorageExists: boolean = true): Promise<any> {\n if (typeof fileNameOrLocalStorageOrData === \"string\") {\n // content has to be loaded\n if (PlatformTools.type === \"node\") {\n // Node.js\n // fileNameOrLocalStorageOrData should be a path to the file\n if (PlatformTools.fileExist(fileNameOrLocalStorageOrData)) {\n const database = PlatformTools.readFileSync(fileNameOrLocalStorageOrData);\n return this.createDatabaseConnectionWithImport(database);\n }\n else if (checkIfFileOrLocalStorageExists) {\n throw new TypeORMError(`File ${fileNameOrLocalStorageOrData} does not exist`);\n }\n else {\n // File doesn't exist and checkIfFileOrLocalStorageExists is set to false.\n // Therefore open a database without importing an existing file.\n // File will be written on first write operation.\n return this.createDatabaseConnectionWithImport();\n }\n }\n else {\n // browser\n // fileNameOrLocalStorageOrData should be a local storage / indexedDB key\n let localStorageContent = null;\n if (this.options.useLocalForage) {\n if (window.localforage) {\n localStorageContent = await window.localforage.getItem(fileNameOrLocalStorageOrData);\n } else {\n throw new TypeORMError(`localforage is not defined - please import localforage.js into your site`);\n }\n } else {\n localStorageContent = PlatformTools.getGlobalVariable().localStorage.getItem(fileNameOrLocalStorageOrData);\n }\n\n if (localStorageContent != null) {\n // localStorage value exists.\n return this.createDatabaseConnectionWithImport(JSON.parse(localStorageContent));\n }\n else if (checkIfFileOrLocalStorageExists) {\n throw new TypeORMError(`File ${fileNameOrLocalStorageOrData} does not exist`);\n }\n else {\n // localStorage value doesn't exist and checkIfFileOrLocalStorageExists is set to false.\n // Therefore open a database without importing anything.\n // localStorage value will be written on first write operation.\n return this.createDatabaseConnectionWithImport();\n }\n }\n }\n else {\n return this.createDatabaseConnectionWithImport(fileNameOrLocalStorageOrData);\n }\n }\n\n /**\n * Saved the current database to the given file (Node.js), local storage key (browser) or\n * indexedDB key (browser with enabled useLocalForage option).\n * If no location path is given, the location path in the options (if specified) will be used.\n */\n async save(location?: string) {\n if (!location && !this.options.location) {\n throw new TypeORMError(`No location is set, specify a location parameter or add the location option to your configuration`);\n }\n\n let path = \"\";\n if (location) {\n path = location;\n }\n else if (this.options.location) {\n path = this.options.location;\n }\n\n if (PlatformTools.type === \"node\") {\n try {\n const content = Buffer.from(this.databaseConnection.export());\n await PlatformTools.writeFile(path, content);\n }\n catch (e) {\n throw new TypeORMError(`Could not save database, error: ${e}`);\n }\n }\n else {\n const database: Uint8Array = this.databaseConnection.export();\n // convert Uint8Array to number array to improve local-storage storage\n const databaseArray = [].slice.call(database);\n if (this.options.useLocalForage) {\n if (window.localforage) {\n await window.localforage.setItem(path, JSON.stringify(databaseArray));\n } else {\n throw new TypeORMError(`localforage is not defined - please import localforage.js into your site`);\n }\n } else {\n PlatformTools.getGlobalVariable().localStorage.setItem(path, JSON.stringify(databaseArray));\n }\n }\n }\n\n /**\n * This gets called by the QueryRunner when a change to the database is made.\n * If a custom autoSaveCallback is specified, it get's called with the database as Uint8Array,\n * otherwise the save method is called which saves it to file (Node.js), local storage (browser)\n * or indexedDB (browser with enabled useLocalForage option).\n */\n async autoSave() {\n if (this.options.autoSave) {\n if (this.options.autoSaveCallback) {\n await this.options.autoSaveCallback(this.export());\n }\n else {\n await this.save();\n }\n }\n }\n\n /**\n * Returns the current database as Uint8Array.\n */\n export(): Uint8Array {\n return this.databaseConnection.export();\n }\n\n /**\n * Creates generated map of values generated or returned by database after INSERT query.\n */\n createGeneratedMap(metadata: EntityMetadata, insertResult: any) {\n const generatedMap = metadata.generatedColumns.reduce((map, generatedColumn) => {\n // seems to be the only way to get the inserted id, see https://github.com/kripken/sql.js/issues/77\n if (generatedColumn.isPrimary && generatedColumn.generationStrategy === \"increment\") {\n const query = \"SELECT last_insert_rowid()\";\n try {\n let result = this.databaseConnection.exec(query);\n this.connection.logger.logQuery(query);\n return OrmUtils.mergeDeep(map, generatedColumn.createValueMap(result[0].values[0][0]));\n }\n catch (e) {\n this.connection.logger.logQueryError(e, query, []);\n }\n }\n\n return map;\n }, {} as ObjectLiteral);\n\n return Object.keys(generatedMap).length > 0 ? generatedMap : undefined;\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates connection with the database.\n * If the location option is set, the database is loaded first.\n */\n protected createDatabaseConnection(): Promise<any> {\n if (this.options.location) {\n return this.load(this.options.location, false);\n }\n\n return this.createDatabaseConnectionWithImport(this.options.database);\n }\n\n /**\n * Creates connection with an optional database.\n * If database is specified it is loaded, otherwise a new empty database is created.\n */\n protected async createDatabaseConnectionWithImport(database?: Uint8Array): Promise<any> {\n // sql.js < 1.0 exposes an object with a `Database` method.\n const isLegacyVersion = typeof this.sqlite.Database === \"function\";\n const sqlite = isLegacyVersion ? this.sqlite : await this.sqlite(this.options.sqlJsConfig);\n if (database && database.length > 0) {\n this.databaseConnection = new sqlite.Database(database);\n }\n else {\n this.databaseConnection = new sqlite.Database();\n }\n\n this.databaseConnection.exec(`PRAGMA foreign_keys = ON;`);\n\n return this.databaseConnection;\n }\n\n /**\n * If driver dependency is not given explicitly, then try to load it via \"require\".\n */\n protected loadDependencies(): void {\n if (PlatformTools.type === \"browser\") {\n const sqlite = this.options.driver || window.SQL;\n this.sqlite = sqlite;\n }\n else {\n try {\n const sqlite = this.options.driver || PlatformTools.load(\"sql.js\");\n this.sqlite = sqlite;\n\n } catch (e) {\n throw new DriverPackageNotInstalledError(\"sql.js\", \"sql.js\");\n }\n }\n }\n}\n"],"sourceRoot":"../.."}
@@ -77,15 +77,14 @@ var SqljsQueryRunner = /** @class */ (function (_super) {
77
77
  * Executes a given SQL query.
78
78
  */
79
79
  SqljsQueryRunner.prototype.query = function (query, parameters, useStructuredResult) {
80
- var _this = this;
81
80
  if (parameters === void 0) { parameters = []; }
82
81
  if (useStructuredResult === void 0) { useStructuredResult = false; }
83
- if (this.isReleased)
84
- throw new QueryRunnerAlreadyReleasedError();
85
- var command = query.trim().split(" ", 1)[0];
86
- return new Promise(function (ok, fail) { return __awaiter(_this, void 0, void 0, function () {
87
- var databaseConnection, queryStartTime, statement, maxQueryExecutionTime, queryEndTime, queryExecutionTime, records, result;
82
+ return __awaiter(this, void 0, void 0, function () {
83
+ var command, databaseConnection, queryStartTime, statement, maxQueryExecutionTime, queryEndTime, queryExecutionTime, records, result;
88
84
  return __generator(this, function (_a) {
85
+ if (this.isReleased)
86
+ throw new QueryRunnerAlreadyReleasedError();
87
+ command = query.trim().split(" ", 1)[0];
89
88
  databaseConnection = this.driver.databaseConnection;
90
89
  this.driver.connection.logger.logQuery(query, parameters, this);
91
90
  queryStartTime = +new Date();
@@ -113,10 +112,10 @@ var SqljsQueryRunner = /** @class */ (function (_super) {
113
112
  this.isDirty = true;
114
113
  }
115
114
  if (useStructuredResult) {
116
- ok(result);
115
+ return [2 /*return*/, result];
117
116
  }
118
117
  else {
119
- ok(result.raw);
118
+ return [2 /*return*/, result.raw];
120
119
  }
121
120
  }
122
121
  catch (e) {
@@ -124,11 +123,11 @@ var SqljsQueryRunner = /** @class */ (function (_super) {
124
123
  statement.free();
125
124
  }
126
125
  this.driver.connection.logger.logQueryError(e, query, parameters, this);
127
- fail(new QueryFailedError(query, parameters, e));
126
+ throw new QueryFailedError(query, parameters, e);
128
127
  }
129
128
  return [2 /*return*/];
130
129
  });
131
- }); });
130
+ });
132
131
  };
133
132
  return SqljsQueryRunner;
134
133
  }(AbstractSqliteQueryRunner));
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/driver/sqljs/SqljsQueryRunner.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,+BAA+B,EAAC,MAAM,6CAA6C,CAAC;AAC5F,OAAO,EAAC,yBAAyB,EAAC,MAAM,8CAA8C,CAAC;AAEvF,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAE7D;;GAEG;AACH;IAAsC,oCAAyB;IAY3D,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,0BAAY,MAAmB;QAA/B,YACI,iBAAO,SAIV;QAnBD;;WAEG;QACK,aAAO,GAAG,KAAK,CAAC;QAapB,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,KAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,KAAI,CAAC,WAAW,GAAG,IAAI,WAAW,CAAC,KAAI,CAAC,CAAC;;IAC7C,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE9D,gCAAK,GAAnB;;;;;6BACQ,IAAI,CAAC,OAAO,EAAZ,wBAAY;wBACZ,qBAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAA;;wBAA5B,SAA4B,CAAC;wBAC7B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;;;;;;KAE5B;IAEK,kCAAO,GAAb;;;;4BACI,qBAAM,IAAI,CAAC,KAAK,EAAE,EAAA;;wBAAlB,SAAkB,CAAC;wBACnB,sBAAO,iBAAM,OAAO,WAAE,EAAC;;;;KAC1B;IAED;;;OAGG;IACG,4CAAiB,GAAvB;;;;4BACI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erAlreadyReleasedError} from \"../../error/QueryRunnerAlreadyReleasedError\";\nimport {AbstractSqliteQueryRunner} from \"../sqlite-abstract/AbstractSqliteQueryRunner\";\nimport {SqljsDriver} from \"./SqljsDriver\";\nimport {Broadcaster} from \"../../subscriber/Broadcaster\";\nimport {QueryFailedError} from \"../../error/QueryFailedError\";\nimport { QueryResult } from \"../../query-runner/QueryResult\";\n\n/**\n * Runs queries on a single sqlite database connection.\n */\nexport class SqljsQueryRunner extends AbstractSqliteQueryRunner {\n\n /**\n * Flag to determine if a modification has happened since the last time this query runner has requested a save.\n */\n private isDirty = false;\n\n /**\n * Database driver used by connection.\n */\n driver: SqljsDriver;\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(driver: SqljsDriver) {\n super();\n this.driver = driver;\n this.connection = driver.connection;\n this.broadcaster = new Broadcaster(this);\n }\n\n // -------------------------------------------------------------------------\n // Public methods\n // -------------------------------------------------------------------------\n\n private async flush() {\n if (this.isDirty) {\n await this.driver.autoSave();\n this.isDirty = false;\n }\n }\n\n async release(): Promise<void> {\n await this.flush();\n return super.release();\n }\n\n /**\n * Commits transaction.\n * Error will be thrown if transaction was not started.\n */\n async commitTransaction(): Promise<void> {\n await super.commitTransaction();\n await this.flush();\n }\n\n /**\n * Executes a given SQL query.\n */\n query(query: string, parameters: any[] = [], useStructuredResult = false): Promise<any> {\n if (this.isReleased)\n throw new QueryRunnerAlreadyReleasedError();\n\n const command = query.trim().split(\" \", 1)[0];\n\n return new Promise(async (ok, fail) => {\n const databaseConnection = this.driver.databaseConnection;\n this.driver.connection.logger.logQuery(query, parameters, this);\n const queryStartTime = +new Date();\n let statement: any;\n try {\n statement = databaseConnection.prepare(query);\n if (parameters) {\n parameters = parameters.map(p => typeof p !== 'undefined' ? p : null);\n\n statement.bind(parameters);\n }\n\n // log slow queries if maxQueryExecution time is set\n const maxQueryExecutionTime = this.driver.options.maxQueryExecutionTime;\n const queryEndTime = +new Date();\n const queryExecutionTime = queryEndTime - queryStartTime;\n if (maxQueryExecutionTime && queryExecutionTime > maxQueryExecutionTime)\n this.driver.connection.logger.logQuerySlow(queryExecutionTime, query, parameters, this);\n\n const records: any[] = [];\n\n while (statement.step()) {\n records.push(statement.getAsObject());\n }\n\n const result = new QueryResult();\n\n result.affected = databaseConnection.getRowsModified();\n result.records = records;\n result.raw = records;\n\n statement.free();\n\n if (command !== \"SELECT\") {\n this.isDirty = true;\n }\n\n if (useStructuredResult) {\n ok(result);\n } else {\n ok(result.raw);\n }\n } catch (e) {\n if (statement) {\n statement.free();\n }\n\n this.driver.connection.logger.logQueryError(e, query, parameters, this);\n fail(new QueryFailedError(query, parameters, e));\n }\n });\n }\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../browser/src/driver/sqljs/SqljsQueryRunner.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,+BAA+B,EAAC,MAAM,6CAA6C,CAAC;AAC5F,OAAO,EAAC,yBAAyB,EAAC,MAAM,8CAA8C,CAAC;AAEvF,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAE7D;;GAEG;AACH;IAAsC,oCAAyB;IAY3D,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,0BAAY,MAAmB;QAA/B,YACI,iBAAO,SAIV;QAnBD;;WAEG;QACK,aAAO,GAAG,KAAK,CAAC;QAapB,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,KAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,KAAI,CAAC,WAAW,GAAG,IAAI,WAAW,CAAC,KAAI,CAAC,CAAC;;IAC7C,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE9D,gCAAK,GAAnB;;;;;6BACQ,IAAI,CAAC,OAAO,EAAZ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I,CAAC,CAAC;oBACxE,MAAM,IAAI,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;iBACpD;;;;KACJ;IACL,uBAAC;AAAD,CA5GA,AA4GC,CA5GqC,yBAAyB,GA4G9D","file":"SqljsQueryRunner.js","sourcesContent":["import {QueryRunnerAlreadyReleasedError} from \"../../error/QueryRunnerAlreadyReleasedError\";\nimport {AbstractSqliteQueryRunner} from \"../sqlite-abstract/AbstractSqliteQueryRunner\";\nimport {SqljsDriver} from \"./SqljsDriver\";\nimport {Broadcaster} from \"../../subscriber/Broadcaster\";\nimport {QueryFailedError} from \"../../error/QueryFailedError\";\nimport { QueryResult } from \"../../query-runner/QueryResult\";\n\n/**\n * Runs queries on a single sqlite database connection.\n */\nexport class SqljsQueryRunner extends AbstractSqliteQueryRunner {\n\n /**\n * Flag to determine if a modification has happened since the last time this query runner has requested a save.\n */\n private isDirty = false;\n\n /**\n * Database driver used by connection.\n */\n driver: SqljsDriver;\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(driver: SqljsDriver) {\n super();\n this.driver = driver;\n this.connection = driver.connection;\n this.broadcaster = new Broadcaster(this);\n }\n\n // -------------------------------------------------------------------------\n // Public methods\n // -------------------------------------------------------------------------\n\n private async flush() {\n if (this.isDirty) {\n await this.driver.autoSave();\n this.isDirty = false;\n }\n }\n\n async release(): Promise<void> {\n await this.flush();\n return super.release();\n }\n\n /**\n * Commits transaction.\n * Error will be thrown if transaction was not started.\n */\n async commitTransaction(): Promise<void> {\n await super.commitTransaction();\n await this.flush();\n }\n\n /**\n * Executes a given SQL query.\n */\n async query(query: string, parameters: any[] = [], useStructuredResult = false): Promise<any> {\n if (this.isReleased)\n throw new QueryRunnerAlreadyReleasedError();\n\n const command = query.trim().split(\" \", 1)[0];\n\n const databaseConnection = this.driver.databaseConnection;\n this.driver.connection.logger.logQuery(query, parameters, this);\n const queryStartTime = +new Date();\n let statement: any;\n try {\n statement = databaseConnection.prepare(query);\n if (parameters) {\n parameters = parameters.map(p => typeof p !== 'undefined' ? p : null);\n\n statement.bind(parameters);\n }\n\n // log slow queries if maxQueryExecution time is set\n const maxQueryExecutionTime = this.driver.options.maxQueryExecutionTime;\n const queryEndTime = +new Date();\n const queryExecutionTime = queryEndTime - queryStartTime;\n if (maxQueryExecutionTime && queryExecutionTime > maxQueryExecutionTime)\n this.driver.connection.logger.logQuerySlow(queryExecutionTime, query, parameters, this);\n\n const records: any[] = [];\n\n while (statement.step()) {\n records.push(statement.getAsObject());\n }\n\n const result = new QueryResult();\n\n result.affected = databaseConnection.getRowsModified();\n result.records = records;\n result.raw = records;\n\n statement.free();\n\n if (command !== \"SELECT\") {\n this.isDirty = true;\n }\n\n if (useStructuredResult) {\n return result;\n } else {\n return result.raw;\n }\n } catch (e) {\n if (statement) {\n statement.free();\n }\n\n this.driver.connection.logger.logQueryError(e, query, parameters, this);\n throw new QueryFailedError(query, parameters, e);\n }\n }\n}\n"],"sourceRoot":"../.."}
@@ -26,6 +26,11 @@ export interface SqlServerConnectionOptions extends BaseConnectionOptions, SqlSe
26
26
  * Database schema.
27
27
  */
28
28
  readonly schema?: string;
29
+ /**
30
+ * The driver object
31
+ * This defaults to `require("mssql")`
32
+ */
33
+ readonly driver?: any;
29
34
  /**
30
35
  * An optional object/dictionary with the any of the properties
31
36
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/driver/sqlserver/SqlServerConnectionOptions.ts"],"names":[],"mappings":"","file":"SqlServerConnectionOptions.js","sourcesContent":["import {BaseConnectionOptions} from \"../../connection/BaseConnectionOptions\";\nimport {SqlServerConnectionCredentialsOptions} from \"./SqlServerConnectionCredentialsOptions\";\n\n/**\n * Microsoft Sql Server specific connection options.\n */\nexport interface SqlServerConnectionOptions extends BaseConnectionOptions, SqlServerConnectionCredentialsOptions {\n\n /**\n * Database type.\n */\n readonly type: \"mssql\";\n\n /**\n * Connection timeout in ms (default: 15000).\n */\n readonly connectionTimeout?: number;\n\n /**\n * Request timeout in ms (default: 15000). NOTE: msnodesqlv8 driver doesn't support timeouts < 1 second.\n */\n readonly requestTimeout?: number;\n\n /**\n * Stream recordsets/rows instead of returning them all at once as an argument of callback (default: false).\n * You can also enable streaming for each request independently (request.stream = true).\n * Always set to true if you plan to work with large amount of rows.\n */\n readonly stream?: boolean;\n\n /**\n * Database schema.\n */\n readonly schema?: string;\n\n /**\n * An optional object/dictionary with the any of the properties\n */\n readonly pool?: {\n\n /**\n * Maximum number of resources to create at any given time. (default=1)\n */\n readonly max?: number;\n\n /**\n * Minimum number of resources to keep in pool at any given time. If this is set >= max, the pool will silently\n * set the min to equal max. (default=0)\n */\n readonly min?: number;\n\n /**\n * Maximum number of queued requests allowed, additional acquire calls will be callback with an err in a future\n * cycle of the event loop.\n */\n readonly maxWaitingClients?: number;\n\n /**\n * Should the pool validate resources before giving them to clients. Requires that either factory.validate or\n * factory.validateAsync to be specified\n */\n readonly testOnBorrow?: boolean;\n\n /**\n * Max milliseconds an acquire call will wait for a resource before timing out. (default no limit), if supplied should non-zero positive integer.\n */\n readonly acquireTimeoutMillis?: number;\n\n /**\n * If true the oldest resources will be first to be allocated. If false the most recently released resources will\n * be the first to be allocated. This in effect turns the pool's behaviour from a queue into a stack. boolean,\n * (default true)\n */\n readonly fifo?: boolean;\n\n /**\n * Int between 1 and x - if set, borrowers can specify their relative priority in the queue if no resources\n * are available. see example. (default 1)\n */\n readonly priorityRange?: number;\n\n /**\n * How often to run eviction checks. Default: 0 (does not run).\n */\n readonly evictionRunIntervalMillis?: number;\n\n /**\n * Number of resources to check each eviction run. Default: 3.\n */\n readonly numTestsPerRun?: number;\n\n /**\n * Amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object\n * evictor (if any), with the extra condition that at least \"min idle\" object instances remain in the pool.\n * Default -1 (nothing can get evicted)\n */\n readonly softIdleTimeoutMillis?: number;\n\n /**\n * The minimum amount of time that an object may sit idle in the pool before it is eligible for eviction due\n * to idle time. Supercedes softIdleTimeoutMillis Default: 30000\n */\n readonly idleTimeoutMillis?: number;\n\n /*\n * Function handling errors thrown by drivers pool.\n * Defaults to logging error with `warn` level.\n */\n readonly errorHandler?: (err: any) => any;\n };\n\n /**\n * Extra options\n */\n readonly options?: {\n\n /**\n * By default, if the database requestion by options.database cannot be accessed, the connection will fail with\n * an error. However, if options.fallbackToDefaultDb is set to true, then the user's default database will\n * be used instead (Default: false).\n */\n readonly fallbackToDefaultDb?: boolean;\n\n /**\n * If true, SET ANSI_NULL_DFLT_ON ON will be set in the initial sql. This means new columns will be nullable by\n * default. See the T-SQL documentation for more details. (Default: true).\n */\n readonly enableAnsiNullDefault?: boolean;\n\n /**\n * The number of milliseconds before the attempt to connect is considered failed (default: 15000).\n */\n readonly connectTimeout?: number;\n\n /**\n * The number of milliseconds before the cancel (abort) of a request is considered failed (default: 5000).\n */\n readonly cancelTimeout?: number;\n\n /**\n * The size of TDS packets (subject to negotiation with the server). Should be a power of 2. (default: 4096).\n */\n readonly packetSize?: number;\n\n /**\n * A boolean determining whether to pass time values in UTC or local time. (default: true).\n */\n readonly useUTC?: boolean;\n\n /**\n * A boolean determining whether to rollback a transaction automatically if any error is encountered during\n * the given transaction's execution. This sets the value for SET XACT_ABORT during the initial SQL phase\n * of a connection (documentation).\n */\n readonly abortTransactionOnError?: boolean;\n\n /**\n * A string indicating which network interface (ip address) to use when connecting to SQL Server.\n */\n readonly localAddress?: string;\n\n /**\n * A boolean determining whether to return rows as arrays or key-value collections. (default: false).\n */\n readonly useColumnNames?: boolean;\n\n /**\n * A boolean, controlling whether the column names returned will have the first letter converted to lower case\n * (true) or not. This value is ignored if you provide a columnNameReplacer. (default: false).\n */\n readonly camelCaseColumns?: boolean;\n\n /**\n * A boolean, controlling whatever to disable RETURNING / OUTPUT statements.\n */\n readonly disableOutputReturning?: boolean;\n\n /**\n * Debug options\n */\n readonly debug?: {\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet details\n * (default: false).\n */\n readonly packet?: boolean;\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet data details\n * (default: false).\n */\n readonly data?: boolean;\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet payload details\n * (default: false).\n */\n readonly payload?: boolean;\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing token stream tokens\n * (default: false).\n */\n readonly token?: boolean;\n };\n\n /**\n * The default isolation level that transactions will be run with. The isolation levels are available\n * from require('tedious').ISOLATION_LEVEL. (default: READ_COMMITTED).\n */\n readonly isolation?: \"READ_UNCOMMITTED\"|\"READ_COMMITTED\"|\"REPEATABLE_READ\"|\"SERIALIZABLE\"|\"SNAPSHOT\";\n\n /**\n * The default isolation level for new connections. All out-of-transaction queries are executed with this\n * setting. The isolation levels are available from require('tedious').ISOLATION_LEVEL .\n */\n readonly connectionIsolationLevel?: \"READ_UNCOMMITTED\"|\"READ_COMMITTED\"|\"REPEATABLE_READ\"|\"SERIALIZABLE\"|\"SNAPSHOT\";\n\n /**\n * A boolean, determining whether the connection will request read only access from a SQL Server\n * Availability Group. For more information, see here. (default: false).\n */\n readonly readOnlyIntent?: boolean;\n\n /**\n * A boolean determining whether or not the connection will be encrypted. Set to true if you're on\n * Windows Azure. (default: false).\n */\n readonly encrypt?: boolean;\n\n /**\n * When encryption is used, an object may be supplied that will be used for the first argument when calling\n * tls.createSecurePair (default: {}).\n */\n readonly cryptoCredentialsDetails?: any;\n\n /**\n * A boolean, that when true will expose received rows in Requests' done* events. See done, doneInProc and\n * doneProc. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnDone?: boolean;\n\n /**\n * A boolean, that when true will expose received rows in Requests' completion callback. See new Request. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnRequestCompletion?: boolean;\n\n /**\n * The version of TDS to use. If server doesn't support specified version, negotiated version is used instead.\n * The versions are available from require('tedious').TDS_VERSION. (default: 7_4).\n */\n readonly tdsVersion?: string;\n\n /**\n * A boolean, that when true will abort a query when an overflow or divide-by-zero error occurs during query execution.\n */\n readonly enableArithAbort?: boolean\n };\n\n /**\n * Replication setup.\n */\n readonly replication?: {\n\n /**\n * Master server used by orm to perform writes.\n */\n readonly master: SqlServerConnectionCredentialsOptions;\n\n /**\n * List of read-from severs (slaves).\n */\n readonly slaves: SqlServerConnectionCredentialsOptions[];\n\n };\n\n\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../browser/src/driver/sqlserver/SqlServerConnectionOptions.ts"],"names":[],"mappings":"","file":"SqlServerConnectionOptions.js","sourcesContent":["import {BaseConnectionOptions} from \"../../connection/BaseConnectionOptions\";\nimport {SqlServerConnectionCredentialsOptions} from \"./SqlServerConnectionCredentialsOptions\";\n\n/**\n * Microsoft Sql Server specific connection options.\n */\nexport interface SqlServerConnectionOptions extends BaseConnectionOptions, SqlServerConnectionCredentialsOptions {\n\n /**\n * Database type.\n */\n readonly type: \"mssql\";\n\n /**\n * Connection timeout in ms (default: 15000).\n */\n readonly connectionTimeout?: number;\n\n /**\n * Request timeout in ms (default: 15000). NOTE: msnodesqlv8 driver doesn't support timeouts < 1 second.\n */\n readonly requestTimeout?: number;\n\n /**\n * Stream recordsets/rows instead of returning them all at once as an argument of callback (default: false).\n * You can also enable streaming for each request independently (request.stream = true).\n * Always set to true if you plan to work with large amount of rows.\n */\n readonly stream?: boolean;\n\n /**\n * Database schema.\n */\n readonly schema?: string;\n\n /**\n * The driver object\n * This defaults to `require(\"mssql\")`\n */\n readonly driver?: any;\n\n /**\n * An optional object/dictionary with the any of the properties\n */\n readonly pool?: {\n\n /**\n * Maximum number of resources to create at any given time. (default=1)\n */\n readonly max?: number;\n\n /**\n * Minimum number of resources to keep in pool at any given time. If this is set >= max, the pool will silently\n * set the min to equal max. (default=0)\n */\n readonly min?: number;\n\n /**\n * Maximum number of queued requests allowed, additional acquire calls will be callback with an err in a future\n * cycle of the event loop.\n */\n readonly maxWaitingClients?: number;\n\n /**\n * Should the pool validate resources before giving them to clients. Requires that either factory.validate or\n * factory.validateAsync to be specified\n */\n readonly testOnBorrow?: boolean;\n\n /**\n * Max milliseconds an acquire call will wait for a resource before timing out. (default no limit), if supplied should non-zero positive integer.\n */\n readonly acquireTimeoutMillis?: number;\n\n /**\n * If true the oldest resources will be first to be allocated. If false the most recently released resources will\n * be the first to be allocated. This in effect turns the pool's behaviour from a queue into a stack. boolean,\n * (default true)\n */\n readonly fifo?: boolean;\n\n /**\n * Int between 1 and x - if set, borrowers can specify their relative priority in the queue if no resources\n * are available. see example. (default 1)\n */\n readonly priorityRange?: number;\n\n /**\n * How often to run eviction checks. Default: 0 (does not run).\n */\n readonly evictionRunIntervalMillis?: number;\n\n /**\n * Number of resources to check each eviction run. Default: 3.\n */\n readonly numTestsPerRun?: number;\n\n /**\n * Amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object\n * evictor (if any), with the extra condition that at least \"min idle\" object instances remain in the pool.\n * Default -1 (nothing can get evicted)\n */\n readonly softIdleTimeoutMillis?: number;\n\n /**\n * The minimum amount of time that an object may sit idle in the pool before it is eligible for eviction due\n * to idle time. Supercedes softIdleTimeoutMillis Default: 30000\n */\n readonly idleTimeoutMillis?: number;\n\n /*\n * Function handling errors thrown by drivers pool.\n * Defaults to logging error with `warn` level.\n */\n readonly errorHandler?: (err: any) => any;\n };\n\n /**\n * Extra options\n */\n readonly options?: {\n\n /**\n * By default, if the database requestion by options.database cannot be accessed, the connection will fail with\n * an error. However, if options.fallbackToDefaultDb is set to true, then the user's default database will\n * be used instead (Default: false).\n */\n readonly fallbackToDefaultDb?: boolean;\n\n /**\n * If true, SET ANSI_NULL_DFLT_ON ON will be set in the initial sql. This means new columns will be nullable by\n * default. See the T-SQL documentation for more details. (Default: true).\n */\n readonly enableAnsiNullDefault?: boolean;\n\n /**\n * The number of milliseconds before the attempt to connect is considered failed (default: 15000).\n */\n readonly connectTimeout?: number;\n\n /**\n * The number of milliseconds before the cancel (abort) of a request is considered failed (default: 5000).\n */\n readonly cancelTimeout?: number;\n\n /**\n * The size of TDS packets (subject to negotiation with the server). Should be a power of 2. (default: 4096).\n */\n readonly packetSize?: number;\n\n /**\n * A boolean determining whether to pass time values in UTC or local time. (default: true).\n */\n readonly useUTC?: boolean;\n\n /**\n * A boolean determining whether to rollback a transaction automatically if any error is encountered during\n * the given transaction's execution. This sets the value for SET XACT_ABORT during the initial SQL phase\n * of a connection (documentation).\n */\n readonly abortTransactionOnError?: boolean;\n\n /**\n * A string indicating which network interface (ip address) to use when connecting to SQL Server.\n */\n readonly localAddress?: string;\n\n /**\n * A boolean determining whether to return rows as arrays or key-value collections. (default: false).\n */\n readonly useColumnNames?: boolean;\n\n /**\n * A boolean, controlling whether the column names returned will have the first letter converted to lower case\n * (true) or not. This value is ignored if you provide a columnNameReplacer. (default: false).\n */\n readonly camelCaseColumns?: boolean;\n\n /**\n * A boolean, controlling whatever to disable RETURNING / OUTPUT statements.\n */\n readonly disableOutputReturning?: boolean;\n\n /**\n * Debug options\n */\n readonly debug?: {\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet details\n * (default: false).\n */\n readonly packet?: boolean;\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet data details\n * (default: false).\n */\n readonly data?: boolean;\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet payload details\n * (default: false).\n */\n readonly payload?: boolean;\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing token stream tokens\n * (default: false).\n */\n readonly token?: boolean;\n };\n\n /**\n * The default isolation level that transactions will be run with. The isolation levels are available\n * from require('tedious').ISOLATION_LEVEL. (default: READ_COMMITTED).\n */\n readonly isolation?: \"READ_UNCOMMITTED\"|\"READ_COMMITTED\"|\"REPEATABLE_READ\"|\"SERIALIZABLE\"|\"SNAPSHOT\";\n\n /**\n * The default isolation level for new connections. All out-of-transaction queries are executed with this\n * setting. The isolation levels are available from require('tedious').ISOLATION_LEVEL .\n */\n readonly connectionIsolationLevel?: \"READ_UNCOMMITTED\"|\"READ_COMMITTED\"|\"REPEATABLE_READ\"|\"SERIALIZABLE\"|\"SNAPSHOT\";\n\n /**\n * A boolean, determining whether the connection will request read only access from a SQL Server\n * Availability Group. For more information, see here. (default: false).\n */\n readonly readOnlyIntent?: boolean;\n\n /**\n * A boolean determining whether or not the connection will be encrypted. Set to true if you're on\n * Windows Azure. (default: false).\n */\n readonly encrypt?: boolean;\n\n /**\n * When encryption is used, an object may be supplied that will be used for the first argument when calling\n * tls.createSecurePair (default: {}).\n */\n readonly cryptoCredentialsDetails?: any;\n\n /**\n * A boolean, that when true will expose received rows in Requests' done* events. See done, doneInProc and\n * doneProc. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnDone?: boolean;\n\n /**\n * A boolean, that when true will expose received rows in Requests' completion callback. See new Request. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnRequestCompletion?: boolean;\n\n /**\n * The version of TDS to use. If server doesn't support specified version, negotiated version is used instead.\n * The versions are available from require('tedious').TDS_VERSION. (default: 7_4).\n */\n readonly tdsVersion?: string;\n\n /**\n * A boolean, that when true will abort a query when an overflow or divide-by-zero error occurs during query execution.\n */\n readonly enableArithAbort?: boolean\n };\n\n /**\n * Replication setup.\n */\n readonly replication?: {\n\n /**\n * Master server used by orm to perform writes.\n */\n readonly master: SqlServerConnectionCredentialsOptions;\n\n /**\n * List of read-from severs (slaves).\n */\n readonly slaves: SqlServerConnectionCredentialsOptions[];\n\n };\n\n}\n"],"sourceRoot":"../.."}
@@ -342,11 +342,11 @@ var SqlServerDriver = /** @class */ (function () {
342
342
  }
343
343
  if (database) {
344
344
  if (!schema) {
345
- tablePath.unshift('');
345
+ tablePath.unshift("");
346
346
  }
347
347
  tablePath.unshift(database);
348
348
  }
349
- return tablePath.join('.');
349
+ return tablePath.join(".");
350
350
  };
351
351
  /**
352
352
  * Parse a target table name or other types and return a normalized table definition.
@@ -754,7 +754,8 @@ var SqlServerDriver = /** @class */ (function () {
754
754
  */
755
755
  SqlServerDriver.prototype.loadDependencies = function () {
756
756
  try {
757
- this.mssql = PlatformTools.load("mssql");
757
+ var mssql = this.options.driver || PlatformTools.load("mssql");
758
+ this.mssql = mssql;
758
759
  }
759
760
  catch (e) { // todo: better error for browser env
760
761
  throw new DriverPackageNotInstalledError("SQL Server", "mssql");
@@ -806,9 +807,9 @@ var SqlServerDriver = /** @class */ (function () {
806
807
  var pool = new _this.mssql.ConnectionPool(connectionOptions);
807
808
  var logger = _this.connection.logger;
808
809
  var poolErrorHandler = (options.pool && options.pool.errorHandler) || (function (error) { return logger.log("warn", "MSSQL pool raised an error. " + error); });
809
- /*
810
- Attaching an error handler to pool errors is essential, as, otherwise, errors raised will go unhandled and
811
- cause the hosting app to crash.
810
+ /**
811
+ * Attaching an error handler to pool errors is essential, as, otherwise, errors raised will go unhandled and
812
+ * cause the hosting app to crash.
812
813
  */
813
814
  pool.on("error", poolErrorHandler);
814
815
  var connection = pool.connect(function (err) {