Fix store
This commit is contained in:
parent
f99fe9eda8
commit
6f6912aadf
|
@ -53,10 +53,7 @@ class Store extends StoreAPI {
|
||||||
onCreate: (Database db, int version) async {
|
onCreate: (Database db, int version) async {
|
||||||
await createTables(db);
|
await createTables(db);
|
||||||
}, onUpgrade: (Database db, int oldVersion, int newVersion) async {
|
}, onUpgrade: (Database db, int oldVersion, int newVersion) async {
|
||||||
if (client.debug) {
|
print("[Store] Migrate databse from version $oldVersion to $newVersion");
|
||||||
print(
|
|
||||||
"[Store] Migrate databse from version $oldVersion to $newVersion");
|
|
||||||
}
|
|
||||||
if (oldVersion != newVersion) {
|
if (oldVersion != newVersion) {
|
||||||
schemes.forEach((String name, String scheme) async {
|
schemes.forEach((String name, String scheme) async {
|
||||||
if (name != "Clients") await db.execute("DROP TABLE IF EXISTS $name");
|
if (name != "Clients") await db.execute("DROP TABLE IF EXISTS $name");
|
||||||
|
@ -73,6 +70,7 @@ class Store extends StoreAPI {
|
||||||
.rawQuery("SELECT * FROM Clients WHERE client=?", [client.clientName]);
|
.rawQuery("SELECT * FROM Clients WHERE client=?", [client.clientName]);
|
||||||
if (list.length == 1) {
|
if (list.length == 1) {
|
||||||
var clientList = list[0];
|
var clientList = list[0];
|
||||||
|
print("[Store] Previous batch: '${clientList["prev_batch"].toString()}'");
|
||||||
client.connect(
|
client.connect(
|
||||||
newToken: clientList["token"],
|
newToken: clientList["token"],
|
||||||
newHomeserver: clientList["homeserver"],
|
newHomeserver: clientList["homeserver"],
|
||||||
|
@ -132,19 +130,19 @@ class Store extends StoreAPI {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> transaction(Future<void> queries()) async {
|
Future<void> transaction(Function queries) async {
|
||||||
return _db.transaction((txnObj) async {
|
return _db.transaction((txnObj) async {
|
||||||
txn = txnObj;
|
txn = txnObj.batch();
|
||||||
await queries();
|
queries();
|
||||||
|
await txn.commit(noResult: true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Will be automatically called on every synchronisation. Must be called inside of
|
/// Will be automatically called on every synchronisation. Must be called inside of
|
||||||
// /// [transaction].
|
// /// [transaction].
|
||||||
Future<void> storePrevBatch(dynamic sync) {
|
void storePrevBatch(String prevBatch) {
|
||||||
txn.rawUpdate("UPDATE Clients SET prev_batch=? WHERE client=?",
|
txn.rawUpdate("UPDATE Clients SET prev_batch=? WHERE client=?",
|
||||||
[client.prevBatch, client.clientName]);
|
[prevBatch, client.clientName]);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> storeRoomPrevBatch(Room room) async {
|
Future<void> storeRoomPrevBatch(Room room) async {
|
||||||
|
|
|
@ -82,8 +82,8 @@ packages:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: "3fbb837f85dc40e741677823f323ad8c3eac6014"
|
ref: "45744331ead079443e0dcb280a86867af2e21ccf"
|
||||||
resolved-ref: "3fbb837f85dc40e741677823f323ad8c3eac6014"
|
resolved-ref: "45744331ead079443e0dcb280a86867af2e21ccf"
|
||||||
url: "https://gitlab.com/famedly/famedlysdk.git"
|
url: "https://gitlab.com/famedly/famedlysdk.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.0.1"
|
version: "0.0.1"
|
||||||
|
|
|
@ -27,7 +27,7 @@ dependencies:
|
||||||
famedlysdk:
|
famedlysdk:
|
||||||
git:
|
git:
|
||||||
url: https://gitlab.com/famedly/famedlysdk.git
|
url: https://gitlab.com/famedly/famedlysdk.git
|
||||||
ref: 3fbb837f85dc40e741677823f323ad8c3eac6014
|
ref: 45744331ead079443e0dcb280a86867af2e21ccf
|
||||||
|
|
||||||
localstorage: ^3.0.1+4
|
localstorage: ^3.0.1+4
|
||||||
bubble: ^1.1.9+1
|
bubble: ^1.1.9+1
|
||||||
|
|
Loading…
Reference in a new issue