Struct pg_async::PgOperation

source ·
pub struct PgOperation {
    pub query_pieces: Vec<PgQueryPiece>,
    pub statements: u32,
    pub scheduling: PgSchedulingMode,
    pub on_escape: Option<Box<dyn Fn(&str) + Send + Sync + 'static>>,
    pub timeouts_at: f64,
}
Expand description

An atomic operation that is to be asynchronously executed.

Fields

query_pieces: Vec<PgQueryPiece>

Parts of SQL text, some of which are to be escaped and some are not.

Might contain several SQL statements (the number of statements MUST match the number in the statements field).

statements: u32

The number of separate top-level SQL statements withing query_pieces.
E.g. the number of results PostgreSQL will return.

scheduling: PgSchedulingMode

Affects the placement of the operation.

on_escape: Option<Box<dyn Fn(&str) + Send + Sync + 'static>>

Callback which fires when the SQL is escaped.
Useful for debugging. Escaped SQL can be copy-pasted “as is” into a third-party SQL client.

    let query = vec! [S ("UPDATE foo SET bar = "), L (user_input)];
    let mut op: PgOperation = query.into_query_pieces();
    if debug {op.on_escape = Some (Box::new (|sql| log! ("escaped query: {}", sql)))}
    let f = cluster.execute (op);
timeouts_at: f64

The time, in seconds since UNIX epoch, with fractions, when the operation SHOULD timeout.

If the timeout is negative then it only affects the scheduling (TBD).
If, on the other hand, the timeout is positive then “SET statement_timeout” is used on the database side to prevent the operation from taking too long.

Since timeouts affect a whole statement, operations with a positive timeout are never pipelined!

Trait Implementations

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Returns the number of SQL statements (the library must know how many results to expect) and the list of pieces to escape and join.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.