insertObjet method

Future<bool> insertObjet(
  1. Object? object
)

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, ...).

Implementation

Future<bool> insertObjet(Object? object) async {
  if (object == null) return false;
  await createTableIfNotExists(object);
  int rowId = 0;
  await (await db).transaction((txn) async {
    try {
      rowId = await txn.insert(
        object.runtimeType.toString(),
        mapToUse((object as dynamic).toMap() as Map<String, dynamic>),
      );
    } catch (e, s) {
      debugPrint('insertObjet failed: $e\n$s');
    }
  });
  return rowId > 0;
}