insert method
Insert a new record
Implementation
Future<Model?> insert() async {
try {
Database db = await database;
final data = toMap();
data.putIfAbsent("created_at", () => DateTime.now());
final id = await db.insert(
table,
_handleDataType(data),
conflictAlgorithm: ConflictAlgorithm.replace,
);
return find(id);
} catch (e) {
throw DatabaseException('Failed to insert record: $e');
}
}