Postgres module

Script_Hooks

structsince 0.27.0Source

What run_script does with each statement's outcome. Every hook is optional.

Fields

on_result: (hooks: *Script_Hooks, result: *Result)
Called once per statement that completes, in order, with its rows (when it returns rows) and command tag. The result is freed after the call unless the hook moves it out (and leaves result.* zeroed). Without this hook rows are not kept at all.
chunk_rows: s64
When positive, rows reach on_result in pieces of this many as they arrive, marked partial, so a large result never has to fit in memory. The statement's last call has the remaining rows (maybe none) and the command tag. A partial result must not be moved out: its rows are dropped after the call and its columns kept for the next piece.
on_copy: (hooks: *Script_Hooks, copy: *Copy_Info)
Called when the server starts a COPY, before any data moves.
copy_in: (hooks: *Script_Hooks, copy: *Copy_Info) -> data : string, done: bool, failure: string
COPY ... FROM STDIN: called until it says done, each time for the next piece of data (any split; rows need not line up with calls). A non-empty failure aborts the COPY with that message instead, and the server answers with an error. Without this hook the COPY fails.
copy_out: (hooks: *Script_Hooks, copy: *Copy_Info, data: [] u8)
COPY ... TO STDOUT: called with each piece of data the server sends (one row in text and CSV formats). Without this hook the data is dropped.
user_data: *void

See also