save method

Future<T> save(
  1. T model
)

Updates an existing model in the database.

Implementation

Future<T> save(T model) async {
  if (!model.exists) {
    return await create(model);
  }

  final data = <String, dynamic>{...model.toMap()};
  if (model.timestamps) {
    data['updated_at'] = DateTime.now().toUtc();
  }

  await QueryBuilder(_tableName, _executor)
      .where('id', '=', model.id)
      .update(data);

  // Return a fresh copy from DB
  final id = model.id;
  return await findOrFail(id);
}