diff --git a/node_modules/@nozbe/watermelondb/adapters/sqlite/index.d.ts b/node_modules/@nozbe/watermelondb/adapters/sqlite/index.d.ts index 380f9c7..4302827 100644 --- a/node_modules/@nozbe/watermelondb/adapters/sqlite/index.d.ts +++ b/node_modules/@nozbe/watermelondb/adapters/sqlite/index.d.ts @@ -20,12 +20,19 @@ declare module '@nozbe/watermelondb/adapters/sqlite' { export type SQLiteQuery = [SQL, SQLiteArg[]] + export type MigrationEvents = { + onSuccess?: () => void, + onStarted?: () => void, + onFailure?: (error: string) => void, + } + export interface SQLiteAdapterOptions { dbName?: string migrations?: SchemaMigrations schema: AppSchema synchronous?: boolean experimentalUseJSI?: boolean + migrationEvents?: MigrationEvents } export default class SQLiteAdapter implements DatabaseAdapter { diff --git a/node_modules/@nozbe/watermelondb/adapters/sqlite/index.js b/node_modules/@nozbe/watermelondb/adapters/sqlite/index.js index 54fe949..f7d6acf 100644 --- a/node_modules/@nozbe/watermelondb/adapters/sqlite/index.js +++ b/node_modules/@nozbe/watermelondb/adapters/sqlite/index.js @@ -36,9 +36,11 @@ function () { dbName: dbName, schema: schema, migrations: migrations + migrationEvents: migrationEvents } = options; this.schema = schema; this.migrations = migrations; + this._migrationEvents = migrationEvents; this._dbName = this._getName(dbName); this._dispatcherType = (0, _makeDispatcher.getDispatcherType)(options); this._dispatcher = (0, _makeDispatcher.makeDispatcher)(this._dispatcherType, this._tag, this._dbName); @@ -160,6 +162,10 @@ function () { if (migrationSteps) { _common.logger.log("[WatermelonDB][SQLite] Migrating from version ".concat(databaseVersion, " to ").concat(this.schema.version, "...")); + if (this._migrationEvents && this._migrationEvents.onStarted) { + this._migrationEvents.onStarted(); + } + var $Try_1_Post = function () { try { return $If_4.call(this); @@ -172,11 +178,15 @@ function () { try { _common.logger.error('[WatermelonDB][SQLite] Migration failed', error); + if (this._migrationEvents && this._migrationEvents.onFailure) { + this._migrationEvents.onFailure(); + } + throw error; } catch ($boundEx) { return $error($boundEx); } - }; + }.bind(this); try { return Promise.resolve((0, _Result.toPromise)(function (callback) { @@ -185,11 +195,15 @@ function () { try { _common.logger.log('[WatermelonDB][SQLite] Migration successful'); + if (this._migrationEvents && this._migrationEvents.onSuccess) { + this._migrationEvents.onSuccess(); + } + return $Try_1_Post(); } catch ($boundEx) { return $Try_1_Catch($boundEx); } - }, $Try_1_Catch); + }.bind(this), $Try_1_Catch); } catch (error) { $Try_1_Catch(error) } diff --git a/node_modules/@nozbe/watermelondb/native/android/src/main/java/com/nozbe/watermelondb/Database.kt b/node_modules/@nozbe/watermelondb/native/android/src/main/java/com/nozbe/watermelondb/Database.kt index 2217222..afde44a 100644 --- a/node_modules/@nozbe/watermelondb/native/android/src/main/java/com/nozbe/watermelondb/Database.kt +++ b/node_modules/@nozbe/watermelondb/native/android/src/main/java/com/nozbe/watermelondb/Database.kt @@ -15,6 +15,19 @@ class Database(private val name: String, private val context: Context) { if (name == ":memory:" || name.contains("mode=memory")) { context.cacheDir.delete() File(context.cacheDir, name).path + } else if (name.contains("/") || name.contains("file")) { + // Extracts the database name from the path + val dbName = name.substringAfterLast("/") + + // Extracts the real path where the *.db file will be created + val truePath = name.substringAfterLast("file://").substringBeforeLast("/") + + // Creates the directory + val fileObj = File(truePath, "databases") + fileObj.mkdir() + + + File("${truePath}/databases", dbName).path } else // On some systems there is some kind of lock on `/databases` folder ¯\_(ツ)_/¯ context.getDatabasePath("$name.db").path.replace("/databases", ""),