Writable

Trait Writable 

Source
pub trait Writable
where Self: Sealed,
{ }
Expand description

Trait governing types which can be written to in-place.

Use with Statement::read_into.

Implementations on Foreign Types§

Source§

impl Writable for String

Writable implementation for String which appends the content of the column to the current container.

§Examples

use sqlite_ll::{Connection, State};

let c = Connection::open_memory()?;

c.execute(r##"
CREATE TABLE users (name TEXT);
INSERT INTO users (name) VALUES ('Alice'), ('Bob');
"##)?;

let mut stmt = c.prepare("SELECT name FROM users")?;
let mut name = String::new();

while let State::Row = stmt.step()? {
    name.clear();
    stmt.read_into(0, &mut name)?;
    assert!(matches!(name.as_str(), "Alice" | "Bob"));
}

Automatic conversion:

use sqlite_ll::{Connection, State};

let c = Connection::open_memory()?;

c.execute(r##"
CREATE TABLE users (id INTEGER);
INSERT INTO users (id) VALUES (1), (2);
"##)?;

let mut stmt = c.prepare("SELECT id FROM users")?;
let mut name = String::new();

while let State::Row = stmt.step()? {
    name.clear();
    stmt.read_into(0, &mut name)?;
    assert!(matches!(name.as_str(), "1" | "2"));
}
Source§

impl Writable for Vec<u8>

Writable implementation for String which appends the content of the column to the current container.

§Examples

use sqlite_ll::{Connection, State};

let c = Connection::open_memory()?;

c.execute(r##"
CREATE TABLE users (name TEXT);
INSERT INTO users (name) VALUES ('Alice'), ('Bob');
"##)?;

let mut stmt = c.prepare("SELECT name FROM users")?;
let mut name = Vec::<u8>::new();

while let State::Row = stmt.step()? {
    name.clear();
    stmt.read_into(0, &mut name)?;
    assert!(matches!(name.as_slice(), b"Alice" | b"Bob"));
}

Automatic conversion:

use sqlite_ll::{Connection, State};

let c = Connection::open_memory()?;

c.execute(r##"
CREATE TABLE users (id INTEGER);
INSERT INTO users (id) VALUES (1), (2);
"##)?;

let mut stmt = c.prepare("SELECT id FROM users")?;
let mut name = Vec::<u8>::new();

while let State::Row = stmt.step()? {
    name.clear();
    stmt.read_into(0, &mut name)?;
    assert!(matches!(name.as_slice(), b"1" | b"2"));
}
Source§

impl<T> Writable for &mut T
where T: ?Sized + Writable,

Implementors§