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

Commit

Permalink
feat: add options to input init config for sql.js (typeorm#4560)
Browse files Browse the repository at this point in the history
* add options to input init config for sql.js

* update changelog

* updated connection-options docs
  • Loading branch information
DavidChen-minted authored and pleerock committed Sep 5, 2019
1 parent 3cf470d commit 5c311ed
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ feel free to ask us and community.
* extend afterLoad() subscriber interface to take LoadEvent ([issue #4185](https://github.com/typeorm/typeorm/issues/4185))
* 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))
* added support for metadata reflection in typeorm-class-transformer-shim.js ([issue #4219](https://github.com/typeorm/typeorm/issues/4219))
* added `sqlJsConfig` to input config when initializing sql.js ([issue #4559](https://github.com/typeorm/typeorm/issues/4559))

## 0.2.17 (2019-05-01)

Expand Down
2 changes: 2 additions & 0 deletions docs/connection-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ See [SSL options](https://github.com/mysqljs/mysql#ssl-options).

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

* `sqlJsConfig`: Optional initialize config for sql.js.

* `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.

* `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.
Expand Down
2 changes: 2 additions & 0 deletions docs/zh_CN/connection-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@

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

- `sqlJsConfig`: sql.js可选启动配置

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

- `autoSaveCallback`: 在对数据库进行更改并启用`autoSave`时调用的函数。该函数获取表示数据库的`UInt8Array`
Expand Down
5 changes: 5 additions & 0 deletions src/driver/sqljs/SqljsConnectionOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export interface SqljsConnectionOptions extends BaseConnectionOptions {
*/
readonly database?: Uint8Array;

/**
* Config that's used to initialize sql.js.
*/
readonly sqlJsConfig?: any;

/**
* Enables the autoSave mechanism which either saves to location
* or calls autoSaveCallback every time a change to the database is made.
Expand Down
2 changes: 1 addition & 1 deletion src/driver/sqljs/SqljsDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export class SqljsDriver extends AbstractSqliteDriver {
protected async createDatabaseConnectionWithImport(database?: Uint8Array): Promise<any> {
// sql.js < 1.0 exposes an object with a `Database` method.
const isLegacyVersion = typeof this.sqlite.Database === "function";
const sqlite = isLegacyVersion ? this.sqlite : await this.sqlite();
const sqlite = isLegacyVersion ? this.sqlite : await this.sqlite(this.options.sqlJsConfig);
if (database && database.length > 0) {
this.databaseConnection = new sqlite.Database(database);
}
Expand Down

0 comments on commit 5c311ed

Please sign in to comment.