enqueue method

Future<int> enqueue(
  1. SyncChange change
)

Inserts change into the queue. Must be called inside a transaction that is also the transaction the data write happened in (or in its own transaction if there is no data write). Returns the new row id.

Implementation

Future<int> enqueue(SyncChange change) async {
  await _ensureTable();
  final String? payloadJson = change.payload == null
      ? null
      : jsonEncode(change.payload);
  await _provider.executeAsync(
    'INSERT INTO $tableName '
    '(table_name, pk, change_type, payload_json, version, created_at) '
    'VALUES (?, ?, ?, ?, ?, ?)',
    <Object?>[
      change.tableName,
      change.pk,
      change.type.name,
      payloadJson,
      change.version,
      DateTime.now().millisecondsSinceEpoch,
    ],
  );
  final int id = await _provider.lastInsertRowIdAsync();
  await _trimToCap();
  return id;
}