Skip to content

Replace ignores Null values #133

@TillJohanndeiter

Description

@TillJohanndeiter

I have this data class with a custom upsert methode:

@MappableClass()
class TrainingRecord {
  static const tableName = "training_record";

  @override
  final String id;
  final DateTime? end;

  TrainingRecord({
    required this.id,
    this.end,
  });

  Future<void> upsert() async {
    await db.execute('''
      INSERT OR REPLACE INTO $tableName (id, end)
      VALUES (?, ?)
    ''', [
      id,
      end?.toIso8601String(),
    ]);
  }

If upsert is invoked then in my PowerSyncSupabaseConnector the map op.opData doesn't contains null values.

  @override
  Future<void> uploadData(PowerSyncDatabase database) async {
    final transaction = await database.getNextCrudTransaction();
    if (transaction == null) {
      return;
    }

    final rest = Supabase.instance.client.rest;
    CrudEntry? lastOp;
    try {
      for (var op in transaction.crud) {
        lastOp = op;

        final table = rest.from(op.table);
        if (op.op == UpdateType.put) {
          **var data = Map<String, dynamic>.of(op.opData!); // The 'end' field is missing from op.opData when its value is null“**

As a result i have to insert them manually in the map e.g:

if (op.table == TrainingRecord.tableName && !data.containsKey("end")) {
    data['end'] = null;
}

Otherwise they are ignore by

data['id'] = op.id;
await table.upsert(data);

I'm unsure if this is a bug or a feature 🤔

Thanks in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions