upsertStudent method

Future<int> upsertStudent({
  1. required String studentId,
  2. String? name,
})

Returns the ID of an existing student row, or creates/updates one.

Implementation

Future<int> upsertStudent({required String studentId, String? name}) async {
  return (await into(students).insertReturning(
    StudentsCompanion.insert(
      studentId: studentId,
      name: Value(name),
    ),
    onConflict: DoUpdate(
      (old) => StudentsCompanion(name: Value(name)),
      target: [students.studentId],
    ),
  )).id;
}