compileInsert method

Compiled compileInsert(
  1. String table,
  2. List<Map<String, Object?>> rows
)

Implementation

Compiled compileInsert(String table, List<Map<String, Object?>> rows) {
  final columns = rows.first.keys.toList();
  for (final c in columns) {
    assertIdentifier(c);
  }
  final bindings = <Object?>[];
  final marks = '(${List.filled(columns.length, '?').join(', ')})';
  final values = <String>[];
  for (final row in rows) {
    bindings.addAll(encodeAll(columns.map((c) => row[c])));
    values.add(marks);
  }
  return (
    'insert into ${wrapTable(table)} (${columns.map(wrapValue).join(', ')}) '
        'values ${values.join(', ')}',
    bindings,
  );
}