insertOrIgnore method

Future<bool> insertOrIgnore(
  1. Map<String, Object?> row
)

SQLite INSERT OR IGNORE: if the row would conflict with the PK or any UNIQUE secondary index, skip the insert and return false. Returns true if the row was inserted.

Implementation

Future<bool> insertOrIgnore(Map<String, Object?> row) async {
  final pkVal = row[primaryKey.name];
  if (pkVal == null) {
    throw ArgumentError(
        'PagedTable.insertOrIgnore: primary-key value is null');
  }
  final pkBytes = _encodePrimaryKey(pkVal);
  if ((await _index.get(pkBytes)) != null) return false;
  for (final si in _secondary.values) {
    if (!si.unique) continue;
    final prefix = _encodeSecondaryPrefix(si, row);
    if (prefix == null) continue;
    if (await _uniqueConflict(si, prefix, null)) return false;
  }
  final rowBytes = _encodeRow(row);
  final rowId = await _heap.insert(rowBytes);
  await _index.put(pkBytes, rowId);
  for (final si in _secondary.values) {
    final key = _encodeSecondaryKey(si, row, pkBytes);
    if (key == null) continue;
    await si.btree.put(key, rowId);
  }
  return true;
}