Skip to main content

Text

Struct Text 

Source
pub struct Text { /* private fields */ }
Expand description

Type implementation for a text column.

This is represented in rust by the Text value and corresponds to the TEXT runtime-time type.

This type is NotNull, use Nullable<Text> to make it nullable.

§Examples

use sqll::{Connection, FromColumn, Result, Statement};
use sqll::ty;

#[derive(Debug, PartialEq, Eq)]
struct MyString<'stmt>(&'stmt str);

impl<'stmt> FromColumn<'stmt> for MyString<'stmt> {
    type Type = ty::Text;

    #[inline]
    fn from_column(stmt: &'stmt Statement, index: ty::Text) -> Result<Self> {
        Ok(MyString(<_>::from_column(stmt, index)?))
    }
}

let c = Connection::open_in_memory()?;

c.execute(r#"
    CREATE TABLE test (value TEXT);

    INSERT INTO test (value) VALUES ('Hello, world!');
"#)?;

let mut stmt = c.prepare("SELECT value FROM test")?;

assert_eq!(stmt.next::<MyString>()?, Some(MyString("Hello, world!")));

Implementations§

Source§

impl Text

Source

pub const fn len(&self) -> usize

Returns the length in bytes text column.

Source

pub const fn is_empty(&self) -> bool

Returns if the text column is empty.

Trait Implementations§

Source§

impl Type for Text

Type implementation for a text column.

§Examples

use sqll::{Connection, FromColumn, Result, Statement};
use sqll::ty;

#[derive(Debug, PartialEq, Eq)]
struct MyString<'stmt>(&'stmt str);

impl<'stmt> FromColumn<'stmt> for MyString<'stmt> {
    type Type = ty::Text;

    #[inline]
    fn from_column(stmt: &'stmt Statement, index: ty::Text) -> Result<Self> {
        Ok(MyString(<_>::from_column(stmt, index)?))
    }
}

let c = Connection::open_in_memory()?;

c.execute(r#"
    CREATE TABLE test (value TEXT);

    INSERT INTO test (value) VALUES ('Hello, world!');
"#)?;

let mut stmt = c.prepare("SELECT value FROM test")?;

assert_eq!(stmt.next::<MyString>()?, Some(MyString("Hello, world!")));
Source§

fn check(stmt: &mut Statement, column: Column) -> Result<Self>

Perform checks and warm up for the given column ensuring that any auto-conversion that needs to occur to load the field is done.
Source§

impl NotNull for Text

Text values cannot be null.

ty::Nullable<ty::Text>

§Examples

use sqll::{Connection, Code};

let mut c = Connection::open_in_memory()?;

c.execute(r#"
    CREATE TABLE nulls (value);

    INSERT INTO nulls (value) VALUES (NULL);
"#)?;

let mut select = c.prepare("SELECT value FROM nulls")?;
let e = select.next::<&str>().unwrap_err();
assert_eq!(e.code(), Code::MISMATCH);

Auto Trait Implementations§

§

impl Freeze for Text

§

impl RefUnwindSafe for Text

§

impl Send for Text

§

impl Sync for Text

§

impl Unpin for Text

§

impl UnsafeUnpin for Text

§

impl UnwindSafe for Text

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.