mirror of
https://github.com/fluencelabs/sqlite-wasm-connector
synced 2025-03-14 22:10:49 +00:00
Run rustfmt (nightly)
This commit is contained in:
parent
7c5d11120a
commit
e0793a38a6
@ -13,9 +13,7 @@ macro_rules! ok(($result:expr) => ($result.unwrap()));
|
|||||||
fn read_cursor(bencher: &mut Bencher) {
|
fn read_cursor(bencher: &mut Bencher) {
|
||||||
let connection = create();
|
let connection = create();
|
||||||
populate(&connection, 100);
|
populate(&connection, 100);
|
||||||
let mut cursor = ok!(connection.prepare(
|
let mut cursor = ok!(connection.prepare("SELECT * FROM data WHERE a > ? AND b > ?")).cursor();
|
||||||
"SELECT * FROM data WHERE a > ? AND b > ?",
|
|
||||||
)).cursor();
|
|
||||||
|
|
||||||
bencher.iter(|| {
|
bencher.iter(|| {
|
||||||
ok!(cursor.bind(&[Integer(42), Float(42.0)]));
|
ok!(cursor.bind(&[Integer(42), Float(42.0)]));
|
||||||
@ -30,9 +28,7 @@ fn read_cursor(bencher: &mut Bencher) {
|
|||||||
fn read_statement(bencher: &mut Bencher) {
|
fn read_statement(bencher: &mut Bencher) {
|
||||||
let connection = create();
|
let connection = create();
|
||||||
populate(&connection, 100);
|
populate(&connection, 100);
|
||||||
let mut statement = ok!(connection.prepare(
|
let mut statement = ok!(connection.prepare("SELECT * FROM data WHERE a > ? AND b > ?"));
|
||||||
"SELECT * FROM data WHERE a > ? AND b > ?",
|
|
||||||
));
|
|
||||||
|
|
||||||
bencher.iter(|| {
|
bencher.iter(|| {
|
||||||
ok!(statement.reset());
|
ok!(statement.reset());
|
||||||
@ -48,14 +44,11 @@ fn read_statement(bencher: &mut Bencher) {
|
|||||||
#[bench]
|
#[bench]
|
||||||
fn write_cursor(bencher: &mut Bencher) {
|
fn write_cursor(bencher: &mut Bencher) {
|
||||||
let connection = create();
|
let connection = create();
|
||||||
let mut cursor = ok!(connection.prepare(
|
let mut cursor =
|
||||||
"INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)",
|
ok!(connection.prepare("INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)")).cursor();
|
||||||
)).cursor();
|
|
||||||
|
|
||||||
bencher.iter(|| {
|
bencher.iter(|| {
|
||||||
ok!(cursor.bind(
|
ok!(cursor.bind(&[Integer(42), Float(42.0), Float(42.0), Float(42.0)]));
|
||||||
&[Integer(42), Float(42.0), Float(42.0), Float(42.0)],
|
|
||||||
));
|
|
||||||
ok!(cursor.next());
|
ok!(cursor.next());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -63,9 +56,8 @@ fn write_cursor(bencher: &mut Bencher) {
|
|||||||
#[bench]
|
#[bench]
|
||||||
fn write_statement(bencher: &mut Bencher) {
|
fn write_statement(bencher: &mut Bencher) {
|
||||||
let connection = create();
|
let connection = create();
|
||||||
let mut statement = ok!(connection.prepare(
|
let mut statement =
|
||||||
"INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)",
|
ok!(connection.prepare("INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)"));
|
||||||
));
|
|
||||||
|
|
||||||
bencher.iter(|| {
|
bencher.iter(|| {
|
||||||
ok!(statement.reset());
|
ok!(statement.reset());
|
||||||
@ -79,16 +71,13 @@ fn write_statement(bencher: &mut Bencher) {
|
|||||||
|
|
||||||
fn create() -> Connection {
|
fn create() -> Connection {
|
||||||
let connection = ok!(Connection::open(":memory:"));
|
let connection = ok!(Connection::open(":memory:"));
|
||||||
ok!(connection.execute(
|
ok!(connection.execute("CREATE TABLE data (a INTEGER, b REAL, c REAL, d REAL)"));
|
||||||
"CREATE TABLE data (a INTEGER, b REAL, c REAL, d REAL)",
|
|
||||||
));
|
|
||||||
connection
|
connection
|
||||||
}
|
}
|
||||||
|
|
||||||
fn populate(connection: &Connection, count: usize) {
|
fn populate(connection: &Connection, count: usize) {
|
||||||
let mut statement = ok!(connection.prepare(
|
let mut statement =
|
||||||
"INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)",
|
ok!(connection.prepare("INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)"));
|
||||||
));
|
|
||||||
for i in 0..count {
|
for i in 0..count {
|
||||||
ok!(statement.reset());
|
ok!(statement.reset());
|
||||||
ok!(statement.bind(1, i as i64));
|
ok!(statement.bind(1, i as i64));
|
||||||
|
@ -295,7 +295,7 @@ mod statement;
|
|||||||
|
|
||||||
pub use connection::Connection;
|
pub use connection::Connection;
|
||||||
pub use cursor::Cursor;
|
pub use cursor::Cursor;
|
||||||
pub use statement::{Statement, State, Bindable, Readable};
|
pub use statement::{Bindable, Readable, State, Statement};
|
||||||
|
|
||||||
/// Open a connection to a new or existing database.
|
/// Open a connection to a new or existing database.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
13
tests/lib.rs
13
tests/lib.rs
@ -10,12 +10,10 @@ macro_rules! ok(($result:expr) => ($result.unwrap()));
|
|||||||
fn connection_error() {
|
fn connection_error() {
|
||||||
let connection = setup_users(":memory:");
|
let connection = setup_users(":memory:");
|
||||||
match connection.execute(":)") {
|
match connection.execute(":)") {
|
||||||
Err(error) => {
|
Err(error) => assert_eq!(
|
||||||
assert_eq!(
|
|
||||||
error.message,
|
error.message,
|
||||||
Some(String::from(r#"unrecognized token: ":""#))
|
Some(String::from(r#"unrecognized token: ":""#))
|
||||||
)
|
),
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,12 +123,7 @@ fn cursor_workflow() {
|
|||||||
ok!(select.bind(&[Value::Integer(42)]));
|
ok!(select.bind(&[Value::Integer(42)]));
|
||||||
assert_eq!(ok!(select.next()), None);
|
assert_eq!(ok!(select.next()), None);
|
||||||
|
|
||||||
ok!(insert.bind(
|
ok!(insert.bind(&[Value::Integer(42), Value::String("Bob".to_string())]));
|
||||||
&[
|
|
||||||
Value::Integer(42),
|
|
||||||
Value::String("Bob".to_string()),
|
|
||||||
],
|
|
||||||
));
|
|
||||||
assert_eq!(ok!(insert.next()), None);
|
assert_eq!(ok!(insert.next()), None);
|
||||||
|
|
||||||
ok!(select.bind(&[Value::Integer(42)]));
|
ok!(select.bind(&[Value::Integer(42)]));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user