Skip to main content

Sql

Struct Sql 

Source
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>

Source

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§

Source§

impl<const N: usize> AsRef<str> for Sql<N>

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<const N: usize> Clone for Sql<N>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Copy for Sql<N>

Source§

impl<const N: usize> Debug for Sql<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Display for Sql<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Eq for Sql<N>

Source§

impl<const N: usize> Hash for Sql<N>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<const N: usize> PartialEq for Sql<N>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<const N: usize> StructuralPartialEq for Sql<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Sql<N>
where [u8; N]: Freeze,

§

impl<const N: usize> RefUnwindSafe for Sql<N>
where [u8; N]: RefUnwindSafe,

§

impl<const N: usize> Send for Sql<N>
where [u8; N]: Send,

§

impl<const N: usize> Sync for Sql<N>
where [u8; N]: Sync,

§

impl<const N: usize> Unpin for Sql<N>
where [u8; N]: Unpin,

§

impl<const N: usize> UnsafeUnpin for Sql<N>
where [u8; N]: UnsafeUnpin,

§

impl<const N: usize> UnwindSafe for Sql<N>
where [u8; N]: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.