copyRows method

Future<int> copyRows(
  1. String table,
  2. List<String> columns,
  3. Iterable<List<Object?>> rows, {
  4. String? schema,
  5. int? timeoutInSeconds,
})
inherited

Insere rows em table com COPY ... FROM STDIN (formato texto), muito mais rápido que INSERTs para muitas linhas. Devolve o número de linhas inseridas.

table, schema e columns são nomes (entre aspas no SQL gerado, portanto diferenciam maiúsculas de minúsculas). Cada linha deve ter um valor por coluna; os tipos aceitos estão em PgCopy.encodeTextValue. Se uma linha for inválida, nada é inserido.

Implementation

Future<int> copyRows(
    String table, List<String> columns, Iterable<List<Object?>> rows,
    {String? schema, int? timeoutInSeconds}) {
  if (columns.isEmpty) {
    throw ArgumentError.value(columns, 'columns', 'Must not be empty');
  }
  final target = schema == null
      ? _quoteIdentifier(table)
      : '${_quoteIdentifier(schema)}.${_quoteIdentifier(table)}';
  final sql = 'COPY $target (${columns.map(_quoteIdentifier).join(', ')}) '
      'FROM STDIN';
  return copyFrom(
      sql,
      PgCopy.encodeTextRows(rows,
          encoding: _connection.encoding, columnCount: columns.length),
      timeoutInSeconds: timeoutInSeconds);
}