A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
core: destroy kysely on error
Abdullah Atta573a37f671b6
diff --git a/packages/core/src/database/index.ts b/packages/core/src/database/index.tsindex bc2047d0d..c46892aac 100644--- a/packages/core/src/database/index.ts+++ b/packages/core/src/database/index.ts@@ -225,61 +225,64 @@ export async function createDatabase(name: string, options: SQLiteOptions) {dialect: options.dialect(name),plugins: [new SqliteBooleanPlugin()]});- if (options.password)- await sql`PRAGMA key = ${sql.ref(options.password)}`- .execute(db)- .then((r) => console.log(r));-- const migrator = new Migrator({- db,- provider: new NNMigrationProvider()- });-- await sql`PRAGMA journal_mode = ${sql.raw(- options.journalMode || "WAL"- )}`.execute(db);+ try {+ if (options.password)+ await sql`PRAGMA key = ${sql.ref(options.password)}`.execute(db);- await sql`PRAGMA synchronous = ${sql.raw(- options.synchronous || "normal"- )}`.execute(db);+ const migrator = new Migrator({+ db,+ provider: new NNMigrationProvider()+ });- // recursive_triggers are required so that SQLite fires DELETE trigger on- // REPLACE INTO statements- await sql`PRAGMA recursive_triggers = true`.execute(db);+ await sql`PRAGMA journal_mode = ${sql.raw(+ options.journalMode || "WAL"+ )}`.execute(db);- if (options.pageSize)- await sql`PRAGMA page_size = ${sql.raw(- options.pageSize.toString()+ await sql`PRAGMA synchronous = ${sql.raw(+ options.synchronous || "normal")}`.execute(db);- if (options.tempStore)- await sql`PRAGMA temp_store = ${sql.raw(options.tempStore)}`.execute(db);+ // recursive_triggers are required so that SQLite fires DELETE trigger on+ // REPLACE INTO statements+ await sql`PRAGMA recursive_triggers = true`.execute(db);- if (options.cacheSize)- await sql`PRAGMA cache_size = ${sql.raw(- options.cacheSize.toString()- )}`.execute(db);+ if (options.pageSize)+ await sql`PRAGMA page_size = ${sql.raw(+ options.pageSize.toString()+ )}`.execute(db);- if (options.lockingMode)- await sql`PRAGMA locking_mode = ${sql.raw(options.lockingMode)}`.execute(- db- );+ if (options.tempStore)+ await sql`PRAGMA temp_store = ${sql.raw(options.tempStore)}`.execute(db);- const { error, results } = await migrator.migrateToLatest();+ if (options.cacheSize)+ await sql`PRAGMA cache_size = ${sql.raw(+ options.cacheSize.toString()+ )}`.execute(db);- results?.forEach((it) => {- if (it.status === "Error")- console.error(`failed to execute migration "${it.migrationName}"`);- });+ if (options.lockingMode)+ await sql`PRAGMA locking_mode = ${sql.raw(options.lockingMode)}`.execute(+ db+ );- if (error) {- console.error("failed to run `migrateToLatest`");- console.error(error);- }+ const { error, results } = await migrator.migrateToLatest();++ results?.forEach((it) => {+ if (it.status === "Error")+ console.error(`failed to execute migration "${it.migrationName}"`);+ });- await createTriggers(db);+ if (error) {+ console.error("failed to run `migrateToLatest`");+ console.error(error);+ }- return db;+ await createTriggers(db);++ return db;+ } catch (e) {+ await db.destroy();+ throw e;+ }}export async function changeDatabasePassword(