mirror of
https://github.com/fluencelabs/sqlite-wasm-connector
synced 2025-04-22 07:32:14 +00:00
Merge branch 'bindable-option' of https://github.com/danieldulaney/sqlite into danieldulaney-bindable-option
This commit is contained in:
commit
adcff3b1d8
@ -229,6 +229,17 @@ impl Bindable for () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: Bindable> Bindable for Option<T> {
|
||||||
|
#[inline]
|
||||||
|
fn bind(self, statement: &mut Statement, i: usize) -> Result<()> {
|
||||||
|
debug_assert!(i > 0, "the indexing starts from 1");
|
||||||
|
match self {
|
||||||
|
Some(inner) => inner.bind(statement, i),
|
||||||
|
None => ().bind(statement, i),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Readable for Value {
|
impl Readable for Value {
|
||||||
fn read(statement: &Statement, i: usize) -> Result<Self> {
|
fn read(statement: &Statement, i: usize) -> Result<Self> {
|
||||||
Ok(match statement.kind(i) {
|
Ok(match statement.kind(i) {
|
||||||
|
22
tests/lib.rs
22
tests/lib.rs
@ -186,6 +186,28 @@ fn statement_bind() {
|
|||||||
assert_eq!(ok!(statement.next()), State::Done);
|
assert_eq!(ok!(statement.next()), State::Done);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn statement_optional_bind() {
|
||||||
|
let connection = setup_users(":memory:");
|
||||||
|
let statement = "INSERT INTO users VALUES (?, ?, ?, ?)";
|
||||||
|
let mut statement = ok!(connection.prepare(statement));
|
||||||
|
|
||||||
|
ok!(statement.bind(1, None::<i64>));
|
||||||
|
ok!(statement.bind(2, None::<&str>));
|
||||||
|
ok!(statement.bind(3, None::<f64>));
|
||||||
|
ok!(statement.bind(4, None::<&[u8]>));
|
||||||
|
assert_eq!(ok!(statement.next()), State::Done);
|
||||||
|
|
||||||
|
let statement = "INSERT INTO users VALUES (?, ?, ?, ?)";
|
||||||
|
let mut statement = ok!(connection.prepare(statement));
|
||||||
|
|
||||||
|
ok!(statement.bind(1, Some(2i64)));
|
||||||
|
ok!(statement.bind(2, Some("Bob")));
|
||||||
|
ok!(statement.bind(3, Some(69.42)));
|
||||||
|
ok!(statement.bind(4, Some(&[0x69u8, 0x42u8][..])));
|
||||||
|
assert_eq!(ok!(statement.next()), State::Done);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn statement_count() {
|
fn statement_count() {
|
||||||
let connection = setup_users(":memory:");
|
let connection = setup_users(":memory:");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user