insertObjet method
Inserts object into its corresponding table.
The table is created on first use if it does not exist yet.
Returns true if exactly one row was inserted, false otherwise
(null object, missing/renamed columns, constraint violation, ...).
With orReplace, a row having the same primary key (or the same value
in a unique column) is replaced (INSERT OR REPLACE).
Implementation
Future<bool> insertObjet(Object? object, {bool orReplace = false}) async {
if (object == null) return false;
await createTableIfNotExists(object);
return _guard('insertObjet', false, () async {
final String table = _tableOf(object);
try {
return await _insertRow(
await _executor(),
table,
object,
orReplace: orReplace,
) >
0;
} on DatabaseException catch (e) {
// A table dropped behind the package's back (raw SQL): recreate it,
// as 2.0.3 did by looking it up before every insert.
if (!e.isNoSuchTableError()) rethrow;
_knownTables.remove(table);
await createTableIfNotExists(object);
return await _insertRow(
await _executor(),
table,
object,
orReplace: orReplace,
) >
0;
}
});
}