disconnectAndClear method

Future<void> disconnectAndClear({
  1. bool clearLocal = true,
})
inherited

Disconnect and clear the database.

Use this when logging out.

The database can still be queried after this is called, but the tables would be empty.

To preserve data in local-only tables, set clearLocal to false.

Implementation

Future<void> disconnectAndClear({bool clearLocal = true}) async {
  await disconnect();

  await writeTransaction((tx) async {
    await tx.execute('select powersync_clear(?)', [clearLocal ? 1 : 0]);
  });
  // The data has been deleted - reset these
  currentStatus = SyncStatus(lastSyncedAt: null, hasSynced: false);
  statusStreamController.add(currentStatus);
}