Implementation
Future<UserNoteModel> createNote(UserNoteModel note) async {
final payload = note.toInsertJson();
if (payload.containsKey('id')) {
// Client-supplied id (outbox flow). Upsert idempotently; the server
// returns the row, including any defaults it filled in.
final response = await _client
.from('user_notes')
.upsert(payload, onConflict: 'id', ignoreDuplicates: false)
.select()
.single();
return UserNoteModel.fromJson(response);
}
final response = await _client
.from('user_notes')
.insert(payload)
.select()
.single();
return UserNoteModel.fromJson(response);
}