upsertCourseOffering method
- required int semesterId,
- String? number,
- required String nameZh,
- String? nameEn,
- Value<
String?> courseCode = const Value.absent(), - Value<
double?> credits = const Value.absent(), - Value<
int?> hours = const Value.absent(), - Value<
int?> phase = const Value.absent(), - Value<
String?> status = const Value.absent(), - Value<
String?> language = const Value.absent(), - Value<
String?> remarks = const Value.absent(), - bool? inCourseTable,
Returns the ID of an existing course offering, or creates/updates one.
Upserts by number. Null-number entries always insert (SQLite treats NULLs as distinct) — caller must delete stale ones first.
Updates the offering's semester to semesterId, allowing a timetable to
correct a semester provisionally inferred from a score record. The score
keeps its own semester and reference to the same offering.
An omitted Value leaves the stored field untouched, so a source that cannot see a field must omit it rather than pass null.
Implementation
Future<int> upsertCourseOffering({
required int semesterId,
String? number,
required String nameZh,
String? nameEn,
Value<String?> courseCode = const Value.absent(),
Value<double?> credits = const Value.absent(),
Value<int?> hours = const Value.absent(),
Value<int?> phase = const Value.absent(),
Value<String?> status = const Value.absent(),
Value<String?> language = const Value.absent(),
Value<String?> remarks = const Value.absent(),
bool? inCourseTable,
}) async {
return (await into(courseOfferings).insertReturning(
CourseOfferingsCompanion.insert(
courseCode: courseCode,
semester: semesterId,
number: Value(number),
nameZh: nameZh,
nameEn: Value(nameEn),
credits: credits,
hours: hours,
phase: phase,
status: status,
language: language,
remarks: remarks,
inCourseTable: Value(inCourseTable ?? false),
),
onConflict: DoUpdate(
(old) => CourseOfferingsCompanion(
semester: Value(semesterId),
courseCode: courseCode,
nameZh: Value(nameZh),
nameEn: .absentIfNull(nameEn),
credits: credits,
hours: hours,
phase: phase,
status: status,
language: language,
remarks: remarks,
inCourseTable: .absentIfNull(inCourseTable),
),
target: [courseOfferings.number],
),
)).id;
}