pub struct Sql<const N: usize> { /* private fields */ }Expand description
The text of a statement rendered in a const: up to N bytes.
postgres, mysql and sqlite fill one from a TableSpec. N is the caller’s
choice; a text longer than N is refused with a panic that names N, the table and the length
the text needs, so in a const it is a build error that says what to raise N to.
§Examples
use ruststream_sqlx_dialect::insert::{self, Sql};
use ruststream_sqlx_dialect::{Column, Form, TableSpec};
const MAIL: TableSpec<'static> = TableSpec::new(
"mail",
Column::new("id").generated(),
Form::Lease(Column::new("locked_until")),
)
.data(&[Column::new("recipient")]);
const INSERT: Sql<96> = insert::sqlite(&MAIL);
// A constant's text lives as long as the program, as a driver's prepared statement needs.
let sql: &'static str = INSERT.as_str();
assert_eq!(sql, "INSERT INTO `mail` (`locked_until`, `recipient`) VALUES (?, ?)");A capacity the text outgrows does not build:
ⓘ
use ruststream_sqlx_dialect::insert::{self, Sql};
use ruststream_sqlx_dialect::{Column, Form, TableSpec};
const MAIL: TableSpec<'static> = TableSpec::new("mail", Column::new("id"), Form::RowLock)
.data(&[Column::new("recipient")]);
// The insert into `mail` takes 52 bytes, more than `Sql<16>` holds.
pub const INSERT: Sql<16> = insert::sqlite(&MAIL);Implementations§
Source§impl<const N: usize> Sql<N>
impl<const N: usize> Sql<N>
Sourcepub const fn as_str(&self) -> &str
pub const fn as_str(&self) -> &str
The text.
§Examples
use ruststream_sqlx_dialect::insert::{self, Sql};
use ruststream_sqlx_dialect::{Column, Form, TableSpec};
const JOBS: TableSpec<'static> =
TableSpec::new("jobs", Column::new("id"), Form::RowLock).payload(Column::new("payload"));
const INSERT: Sql<64> = insert::mysql(&JOBS);
assert_eq!(INSERT.as_str(), "INSERT INTO `jobs` (`id`, `payload`) VALUES (?, ?)");Trait Implementations§
impl<const N: usize> Copy for Sql<N>
impl<const N: usize> Eq for Sql<N>
impl<const N: usize> StructuralPartialEq for Sql<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for Sql<N>
impl<const N: usize> RefUnwindSafe for Sql<N>
impl<const N: usize> Send for Sql<N>
impl<const N: usize> Sync for Sql<N>
impl<const N: usize> Unpin for Sql<N>
impl<const N: usize> UnsafeUnpin for Sql<N>
impl<const N: usize> UnwindSafe for Sql<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more