Skip to content
This repository was archived by the owner on Mar 18, 2022. It is now read-only.

Commit 5c311ed

Browse files
DavidChen-mintedpleerock
authored andcommitted
feat: add options to input init config for sql.js (typeorm#4560)
* add options to input init config for sql.js * update changelog * updated connection-options docs
1 parent 3cf470d commit 5c311ed

5 files changed

Lines changed: 11 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ feel free to ask us and community.
2424
* extend afterLoad() subscriber interface to take LoadEvent ([issue #4185](https://github.com/typeorm/typeorm/issues/4185))
2525
* relation decorators (e.g. `@OneToMany`) now also accept `string` instead of `typeFunction`, which prevents circular dependency issues in the frontend/browser ([issue #4190](https://github.com/typeorm/typeorm/issues/4190))
2626
* added support for metadata reflection in typeorm-class-transformer-shim.js ([issue #4219](https://github.com/typeorm/typeorm/issues/4219))
27+
* added `sqlJsConfig` to input config when initializing sql.js ([issue #4559](https://github.com/typeorm/typeorm/issues/4559))
2728

2829
## 0.2.17 (2019-05-01)
2930

docs/connection-options.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,8 @@ See [SSL options](https://github.com/mysqljs/mysql#ssl-options).
465465

466466
* `database`: The raw UInt8Array database that should be imported.
467467

468+
* `sqlJsConfig`: Optional initialize config for sql.js.
469+
468470
* `autoSave`: Whether or not autoSave should be disabled. If set to true the database will be saved to the given file location (Node.js) or LocalStorage element (browser) when a change happens and `location` is specified. Otherwise `autoSaveCallback` can be used.
469471

470472
* `autoSaveCallback`: A function that get's called when changes to the database are made and `autoSave` is enabled. The function gets a `UInt8Array` that represents the database.

docs/zh_CN/connection-options.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@
372372

373373
- `database`: 应导入的原始 UInt8Array 数据库。
374374

375+
- `sqlJsConfig`: sql.js可选启动配置
376+
375377
- `autoSave`: 是否应禁用 autoSave。如果设置为 true,则在发生更改并指定`location`时,数据库将保存到给定的文件位置(Node.js)或 LocalStorage(浏览器)。否则可以使用`autoSaveCallback`
376378

377379
- `autoSaveCallback`: 在对数据库进行更改并启用`autoSave`时调用的函数。该函数获取表示数据库的`UInt8Array`

src/driver/sqljs/SqljsConnectionOptions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export interface SqljsConnectionOptions extends BaseConnectionOptions {
1515
*/
1616
readonly database?: Uint8Array;
1717

18+
/**
19+
* Config that's used to initialize sql.js.
20+
*/
21+
readonly sqlJsConfig?: any;
22+
1823
/**
1924
* Enables the autoSave mechanism which either saves to location
2025
* or calls autoSaveCallback every time a change to the database is made.

src/driver/sqljs/SqljsDriver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export class SqljsDriver extends AbstractSqliteDriver {
248248
protected async createDatabaseConnectionWithImport(database?: Uint8Array): Promise<any> {
249249
// sql.js < 1.0 exposes an object with a `Database` method.
250250
const isLegacyVersion = typeof this.sqlite.Database === "function";
251-
const sqlite = isLegacyVersion ? this.sqlite : await this.sqlite();
251+
const sqlite = isLegacyVersion ? this.sqlite : await this.sqlite(this.options.sqlJsConfig);
252252
if (database && database.length > 0) {
253253
this.databaseConnection = new sqlite.Database(database);
254254
}

0 commit comments

Comments
 (0)