From 70be9fed965797839c8112edff42834628d0c530 Mon Sep 17 00:00:00 2001 From: Tim Glasgow Date: Sun, 24 Jul 2022 18:47:17 -0500 Subject: [PATCH] realm object management --- squarenotsquare/realm/dbInit.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/squarenotsquare/realm/dbInit.js b/squarenotsquare/realm/dbInit.js index 8395352..171d525 100644 --- a/squarenotsquare/realm/dbInit.js +++ b/squarenotsquare/realm/dbInit.js @@ -41,7 +41,9 @@ export async function initDB(){ } } - if (realmDB === null){ + let dbRef = realmDB; + + if (dbRef === null){ let schemaList = [ {schemaVersion: 0, schema: [System, User, Score], migration: Migrations.migratev0, encryptionKey: dbKey}, {schemaVersion: 1, schema: [System, User, Score], migration: Migrations.migratev1, encryptionKey: dbKey} @@ -54,23 +56,24 @@ export async function initDB(){ } while (currentSchema < schemaList.length) { - if (realmDB !== null) { - realmDB.close(); + if (dbRef !== null) { + dbRef.close(); } - realmDB = new Realm(schemaList[currentSchema]); + dbRef = new Realm(schemaList[currentSchema]); currentSchema += 1; } - if (realmDB === null) { - realmDB = new Realm(schemaList[schemaList.length - 1]); + if (dbRef === null) { + dbRef = new Realm(schemaList[schemaList.length - 1]); } - systemRepo = new SystemRepo(realmDB); - userRepo = new UserRepo(realmDB); - scoreRepo = new ScoreRepo(realmDB) + systemRepo = new SystemRepo(dbRef); + userRepo = new UserRepo(dbRef); + scoreRepo = new ScoreRepo(dbRef) } + let realmDB = dbRef; return realmDB; } catch (err) { console.log(err);