deleteRecords method
Implementation
Future<void> deleteRecords(ISQLiteItem item) async {
final db = await getOpenDatabase();
// Perform operations in a transaction for atomicity
await db.transaction((txn) async {
// Delete all records from the table
await txn.rawDelete('DELETE FROM ${item.getTableName()}');
// Check if the table has an INTEGER PRIMARY KEY before resetting the auto-increment
final hasPrimaryKey =
await txn.rawQuery('PRAGMA table_info(${item.getTableName()})');
if (hasPrimaryKey.any((column) => column['pk'] == 1)) {
await txn.rawUpdate(
'DELETE FROM sqlite_sequence WHERE name = ?',
[item.getTableName()],
);
}
});
}