mirror of
https://github.com/fluencelabs/sqlite-wasm-connector
synced 2025-03-15 06:20:50 +00:00
Replace Connection::iterate with Statement::into_iter
This commit is contained in:
parent
42515bc5ec
commit
75bd2d94b6
@ -3,7 +3,7 @@ use libc::{c_char, c_int, c_void};
|
||||
use std::marker::PhantomData;
|
||||
use std::path::Path;
|
||||
|
||||
use {Iterator, Result, Statement};
|
||||
use {Result, Statement};
|
||||
|
||||
/// A database connection.
|
||||
pub struct Connection {
|
||||
@ -60,12 +60,6 @@ impl Connection {
|
||||
::statement::new(self.raw, statement)
|
||||
}
|
||||
|
||||
/// Create an iterator over the resulting rows of a prepared statement.
|
||||
#[inline]
|
||||
pub fn iterate<'l, T: AsRef<str>>(&'l self, statement: T) -> Result<Iterator<'l>> {
|
||||
::iterator::new(try!(::statement::new(self.raw, statement)))
|
||||
}
|
||||
|
||||
/// Set a callback for handling busy events.
|
||||
///
|
||||
/// The callback is triggered when the database cannot perform an operation
|
||||
|
@ -2,7 +2,7 @@ use ffi;
|
||||
use libc::{c_double, c_int};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use {Result, Type, Value};
|
||||
use {Iterator, Result, Type, Value};
|
||||
|
||||
/// A prepared statement.
|
||||
pub struct Statement<'l> {
|
||||
@ -100,6 +100,12 @@ impl<'l> Statement<'l> {
|
||||
self.state = None;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Upgrade the statement to an iterator.
|
||||
#[inline]
|
||||
pub fn into_iter(self) -> Result<Iterator<'l>> {
|
||||
::iterator::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'l> Drop for Statement<'l> {
|
||||
|
@ -73,7 +73,7 @@ fn connection_set_busy_handler() {
|
||||
fn iterator() {
|
||||
let connection = setup(":memory:");
|
||||
let statement = "SELECT id FROM users WHERE id = ?";
|
||||
let mut iterator = ok!(connection.iterate(statement));
|
||||
let mut iterator = ok!(connection.prepare(statement)).into_iter().unwrap();
|
||||
|
||||
ok!(iterator.start(&[Value::Integer(1)]));
|
||||
assert_eq!(ok!(ok!(iterator.next())), &[Value::Integer(1)]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user