Skip to main content

postgres

Function postgres 

Source
pub const fn postgres<const N: usize>(spec: &TableSpec<'_>) -> Sql<N>
Expand description

The Postgres insert of spec: every column the database does not fill, in TableSpec::columns order, bound as $1, $2, ..; DEFAULT VALUES when there is none.

§Panics

When the text outgrows N, when the description reads the table with * (TableSpec::selecting_all), or when a name is longer than the 63 bytes Postgres keeps. In a const the panic is a build error.

§Examples

use ruststream_sqlx_dialect::insert::{self, Sql};
use ruststream_sqlx_dialect::{Column, Form, TableSpec};

const ORDERS: TableSpec<'static> =
    TableSpec::new("order_jobs", Column::new("job_id").generated(), Form::RowLock)
        .within("app")
        .payload(Column::new("payload"));
const INSERT: Sql<64> = insert::postgres(&ORDERS);

assert_eq!(INSERT.as_str(), r#"INSERT INTO "app"."order_jobs" ("payload") VALUES ($1)"#);