CopyEncoder
struct CopyEncoderBuilds COPY row bytes in format, ready for PQputCopyData in chunks via take().
Field values are escaped/quoted as they are appended, so the buffer is
always valid COPY data up to the last completed row — size()/take()
can be called mid-row, though a caller normally flushes only after
end_row().
Implements Movable
- Fields
format: Intdelimiter: Stringnull_string: String
__init__
def __init__(out self, format: Int = Int(0), delimiter: Optional[String] = None, null: Optional[String] = None) Configure the encoder.
- Args
format:COPY_TEXTorCOPY_CSV.delimiter: One-byte field separator. Defaults to tab (text) or comma (CSV).null: The NULL marker. Defaults to\N(text) or the empty string (CSV) — PostgreSQL's own defaults for each sub-format.
Raises Error: If format is neither sub-format, or delimiter is not
exactly one byte.
field
def field(mut self, v: StringSpan) Append a non-NULL field, escaping/quoting it for self.format.
null
def null(mut self) Append a NULL field (the raw, unescaped null marker).
end_row
def end_row(mut self) Terminate the current row with \n and reset for the next one.
row
def row(mut self, values: List[Optional[String]]) Convenience: append a whole row (None entries as NULL) and terminate it.
size
def size(self) -> Int Bytes currently buffered.
take
def take(mut self) -> List[UInt8] Hand back the buffered bytes and reset the buffer, so a caller can flush in chunks without losing anything already appended.
bytes
def bytes(ref self) -> Span[UInt8, origin_of(self._buf)] A read-only view of the currently buffered bytes, without taking them.