Instance Method
copyFrom(table:columns:format:logger:file:line:writeData:)
COPY <table name> FROM STDIN query.func copyFrom(table: String, columns: [String] = [], format: PostgresCopyFromFormat = .text(.init()), logger: Logger, file: String = #fileID, line: Int = #line, writeData: nonisolated(nonsending) (PostgresCopyFromWriter) async throws -> Void) async throws
Parameters
tableThe name of the table into which to copy the data.
columnsThe name of the columns to copy. If an empty array is passed, all columns are assumed to be copied.
formatOptions that specify the format of the data that is produced by
writeData.loggerThe
Loggerto log into for the operation.fileThe file the operation was started in. Used for better error reporting.
lineThe line the operation was started in. Used for better error reporting.
writeDataClosure that produces the data for the table, to be streamed to the backend. Call
writeon the writer provided by the closure to send data to the backend and return from the closure once all data is sent. Throw an error from the closure to fail the data transfer. The error thrown by the closure will be rethrown by thecopyFromfunction.
Discussion
Important
The table and column names are inserted into the COPY FROM query as passed and might thus be susceptible to SQL injection. Ensure no untrusted data is contained in these strings.