insert<KeyType> method

  1. @override
Future<KeyType> insert<KeyType>(
  1. Table<KeyType> table,
  2. Map<String, Object?> values, {
  3. ConflictAlgorithm conflictAlgorithm = ConflictAlgorithm.abort,
})
override

Implementation

@override
Future<KeyType> insert<KeyType>(Table<KeyType> table, Map<String, Object?> values, {ConflictAlgorithm conflictAlgorithm = ConflictAlgorithm.abort}) async {
  try {
    // final newKey = await _db!.insert(table.name,
    //     table.columns.validateMapExcept(table.columns.preprocessMap(values)),
    //     conflictAlgorithm: conflictAlgorithm.intoPrivate());

    final insertionValues = table.columns.validateMapExcept(table.columns.preprocessMap(values));
    final arguments = insertionValues.entries.toList();
    final newKey = await _db!.rawQuery(
      table.buildInsertStatement(columnNames: arguments.map((e) => e.key), onConflict: conflictAlgorithm),
      arguments.map((e) => e.value).toList(),
    );

    _tableChangeController.add(table);
    _insertController.add((table, values, conflictAlgorithm));

    return newKey.first.values.first as KeyType;
  } catch (e, stack) {
    print(stack);
    throw sqlliteGenericException(e);
  }
}