Expand description
The insert of a row into a queue table, for each built-in dialect, written by a const fn.
postgres, mysql and sqlite turn a TableSpec into the text of its insert while
the service compiles: every column the database does not fill, in TableSpec::columns
order, each bound by the next placeholder. The built-in dialects’ Dialect::insert, and
with it the insert #[derive(Inbox)] generates, take their text from the same writer, so a
table described by hand inserts with the same statement as a derived one.
The text lands in a Sql<N>: N bytes the caller chooses, a constant like the description
it renders. A capacity too small for the text, a description read with * and a name longer
than the database keeps are refused with a panic, which in a const is a build error naming
the table.
§Examples
use ruststream_sqlx_dialect::insert::{self, Sql};
use ruststream_sqlx_dialect::{Column, Form, TableSpec};
const EMAILS: TableSpec<'static> = TableSpec::new(
"email_jobs",
Column::new("job_id").generated(),
Form::Lease(Column::new("locked_until")),
)
.group(Column::new("name"))
.payload(Column::new("payload"))
.data(&[Column::new("recipient")]);
// The binds follow `TableSpec::columns`: the roles, then the data columns.
const INSERT: Sql<128> = insert::postgres(&EMAILS);
assert_eq!(
INSERT.as_str(),
r#"INSERT INTO "email_jobs" ("name", "locked_until", "payload", "recipient") VALUES ($1, $2, $3, $4)"#,
);Structs§
- Sql
- The text of a statement rendered in a
const: up toNbytes.
Functions§
- mysql
- The MySQL and MariaDB insert of
spec: every column the database does not fill, inTableSpec::columnsorder, bound as?;() VALUES ()when there is none. - postgres
- The Postgres insert of
spec: every column the database does not fill, inTableSpec::columnsorder, bound as$1,$2, ..;DEFAULT VALUESwhen there is none. - sqlite
- The SQLite insert of
spec: every column the database does not fill, inTableSpec::columnsorder, bound as?;DEFAULT VALUESwhen there is none.