import 'dart:async'; import 'dart:convert'; import 'dart:typed_data'; ///////////////////////////////////// /// VeilidTableDB abstract class VeilidTableDBTransaction { bool isDone(); Future commit(); Future rollback(); Future store(int col, Uint8List key, Uint8List value); Future delete(int col, Uint8List key); Future storeJson(int col, Uint8List key, Object? object, {Object? Function(Object? nonEncodable)? toEncodable}) async => store(col, key, utf8.encoder.convert(jsonEncode(object, toEncodable: toEncodable))); Future storeStringJson(int col, String key, Object? object, {Object? Function(Object? nonEncodable)? toEncodable}) => storeJson(col, utf8.encoder.convert(key), object, toEncodable: toEncodable); } abstract class VeilidTableDB { void close(); int getColumnCount(); Future> getKeys(int col); VeilidTableDBTransaction transact(); Future store(int col, Uint8List key, Uint8List value); Future load(int col, Uint8List key); Future delete(int col, Uint8List key); Future storeJson(int col, Uint8List key, Object? object, {Object? Function(Object? nonEncodable)? toEncodable}) => store(col, key, utf8.encoder.convert(jsonEncode(object, toEncodable: toEncodable))); Future storeStringJson(int col, String key, Object? object, {Object? Function(Object? nonEncodable)? toEncodable}) => storeJson(col, utf8.encoder.convert(key), object, toEncodable: toEncodable); Future loadJson(int col, Uint8List key, {Object? Function(Object? key, Object? value)? reviver}) async { final s = await load(col, key); if (s == null) { return null; } return jsonDecode(utf8.decode(s, allowMalformed: false), reviver: reviver); } Future loadStringJson(int col, String key, {Object? Function(Object? key, Object? value)? reviver}) => loadJson(col, utf8.encoder.convert(key), reviver: reviver); Future deleteJson(int col, Uint8List key, {Object? Function(Object? key, Object? value)? reviver}) async { final s = await delete(col, key); if (s == null) { return null; } return jsonDecode(utf8.decode(s, allowMalformed: false), reviver: reviver); } Future deleteStringJson(int col, String key, {Object? Function(Object? key, Object? value)? reviver}) => deleteJson(col, utf8.encoder.convert(key), reviver: reviver); }