Skip to content

Commit

Permalink
feat: implement driver options for NativeScript (#5217)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerbob92 authored and pleerock committed Dec 20, 2019
1 parent edc8e6d commit 3e58426
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
30 changes: 30 additions & 0 deletions src/driver/nativescript/NativescriptConnectionOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,34 @@ export interface NativescriptConnectionOptions extends BaseConnectionOptions {
*/
readonly driver: any;

/**
* Whether to mark the mark the database as read only on open (iOS only).
*/
readonly readOnly?: boolean;

/**
* The key to use for for using/opening encrypted databases. (requires the "Encrypted Plugin")
*/
readonly key?: string;

/**
* Whether to enable background multitasking. All SQL is ran on a background worker thread. (requires the "Commercial Plugin")
*/
readonly multithreading?: boolean;

/**
* Migrates a Encrypted Sql database from v3 to the new v4. If you are a new user you do not need to set this flag as new created databases will already be in v4.
* If you are upgrading a app that used v1.3.0 or earlier of NS-Sqlite-Encrypted; then you will probably want to set this flag to true. (requires the "Encrypted Plugin")
*/
readonly migrate?: boolean;

/**
* Flags to pass to SQLite when opening the database on iOS. (see https://www.sqlite.org/c3ref/open.html)
*/
readonly iosFlags?: number;

/**
* Flags to pass to SQLite when opening the database on Android. (see https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html)
*/
readonly androidFlags?: number;
}
9 changes: 7 additions & 2 deletions src/driver/nativescript/NativescriptDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,15 @@ export class NativescriptDriver extends AbstractSqliteDriver {
protected createDatabaseConnection() {
return new Promise<void>((ok, fail) => {
const options = Object.assign({}, {
name: this.options.database,
readOnly: this.options.readOnly,
key: this.options.key,
multithreading: this.options.multithreading,
migrate: this.options.migrate,
iosFlags: this.options.iosFlags,
androidFlags: this.options.androidFlags,
}, this.options.extra || {});

new this.sqlite(options.name, (err: Error, db: any): any => {
new this.sqlite(this.options.database, options, (err: Error, db: any): any => {
if (err) return fail(err);

// use object mode to work with TypeORM
Expand Down

0 comments on commit 3e58426

Please sign in to comment.