mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
feat: add capacitor driver options for encryption & version (#7868)
This commit is contained in:
parent
4b45ae1e81
commit
a2bd94b146
@ -209,6 +209,10 @@ See [SSL options](https://github.com/mysqljs/mysql#ssl-options).
|
||||
|
||||
* `driver` - The capacitor-sqlite instance. For example, `new SQLiteConnection(CapacitorSQLite)`.
|
||||
|
||||
* `mode` - Set the mode for database encryption: "no-encryption" | "encryption" | "secret" | "newsecret"
|
||||
|
||||
* `version` - Database version
|
||||
|
||||
* `journalMode` - The SQLite journal mode (optional)
|
||||
|
||||
## `cordova` connection options
|
||||
|
||||
@ -9,15 +9,25 @@ export interface CapacitorConnectionOptions extends BaseConnectionOptions {
|
||||
*/
|
||||
readonly type: "capacitor";
|
||||
|
||||
/**
|
||||
* The capacitor-sqlite instance. For example, `new SQLiteConnection(CapacitorSQLite)`.
|
||||
*/
|
||||
readonly driver: any;
|
||||
|
||||
/**
|
||||
* Database name (capacitor-sqlite will add the suffix `SQLite.db`)
|
||||
*/
|
||||
readonly database: string;
|
||||
|
||||
/**
|
||||
* The capacitor-sqlite instance. For example, `new SQLiteConnection(CapacitorSQLite)`.
|
||||
* Set the mode for database encryption
|
||||
*/
|
||||
readonly driver: any;
|
||||
readonly mode?: "no-encryption" | "encryption" | "secret" | "newsecret";
|
||||
|
||||
/**
|
||||
* Database version
|
||||
*/
|
||||
readonly version?: number;
|
||||
|
||||
/**
|
||||
* The SQLite journal mode (optional)
|
||||
|
||||
@ -74,17 +74,23 @@ export class CapacitorDriver extends AbstractSqliteDriver {
|
||||
* Creates connection with the database.
|
||||
*/
|
||||
protected async createDatabaseConnection() {
|
||||
const databaseMode = this.options.mode || "no-encryption";
|
||||
const isDatabaseEncryted = databaseMode !== "no-encryption";
|
||||
const databaseVersion =
|
||||
typeof this.options.version === "undefined"
|
||||
? 1
|
||||
: this.options.version;
|
||||
const connection = await this.sqlite.createConnection(
|
||||
this.options.database,
|
||||
false,
|
||||
"no-encryption",
|
||||
1
|
||||
isDatabaseEncryted,
|
||||
databaseMode,
|
||||
databaseVersion
|
||||
);
|
||||
await connection.open();
|
||||
|
||||
// we need to enable foreign keys in sqlite to make sure all foreign key related features
|
||||
// working properly. this also makes onDelete to work with sqlite.
|
||||
await connection.query(`PRAGMA foreign_keys = ON`, []);
|
||||
await connection.query(`PRAGMA foreign_keys = ON`);
|
||||
|
||||
if (
|
||||
this.options.journalMode &&
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user