1
0
mirror of https://github.com/fluencelabs/sqlite-wasm-connector synced 2025-03-15 06:20:50 +00:00

Fix styles

This commit is contained in:
Ivan Ukhov 2017-08-23 06:06:04 +02:00
parent ec8ecc7f04
commit b3b10acd2a
3 changed files with 27 additions and 44 deletions

@ -40,11 +40,7 @@ the previous technique:
use sqlite::State;
let mut statement = connection
.prepare(
"
SELECT * FROM users WHERE age > ?
",
)
.prepare("SELECT * FROM users WHERE age > ?")
.unwrap();
statement.bind(1, 50).unwrap();
@ -62,11 +58,7 @@ statement providing the concept of row and featuring all-at-once binding:
use sqlite::Value;
let mut cursor = connection
.prepare(
"
SELECT * FROM users WHERE age > ?
",
)
.prepare("SELECT * FROM users WHERE age > ?")
.unwrap()
.cursor();

@ -14,9 +14,7 @@ fn read_cursor(bencher: &mut Bencher) {
let connection = create();
populate(&connection, 100);
let mut cursor = ok!(connection.prepare(
"
SELECT * FROM data WHERE a > ? AND b > ?
",
"SELECT * FROM data WHERE a > ? AND b > ?",
)).cursor();
bencher.iter(|| {
@ -33,9 +31,7 @@ fn read_statement(bencher: &mut Bencher) {
let connection = create();
populate(&connection, 100);
let mut statement = ok!(connection.prepare(
"
SELECT * FROM data WHERE a > ? AND b > ?
",
"SELECT * FROM data WHERE a > ? AND b > ?",
));
bencher.iter(|| {
@ -53,9 +49,7 @@ fn read_statement(bencher: &mut Bencher) {
fn write_cursor(bencher: &mut Bencher) {
let connection = create();
let mut cursor = ok!(connection.prepare(
"
INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)
",
"INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)",
)).cursor();
bencher.iter(|| {
@ -70,9 +64,7 @@ fn write_cursor(bencher: &mut Bencher) {
fn write_statement(bencher: &mut Bencher) {
let connection = create();
let mut statement = ok!(connection.prepare(
"
INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)
",
"INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)",
));
bencher.iter(|| {
@ -88,18 +80,14 @@ fn write_statement(bencher: &mut Bencher) {
fn create() -> Connection {
let connection = ok!(Connection::open(":memory:"));
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
}
fn populate(connection: &Connection, count: usize) {
let mut statement = ok!(connection.prepare(
"
INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)
",
"INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)",
));
for i in 0..count {
ok!(statement.reset());

@ -58,11 +58,7 @@
//! # .unwrap();
//!
//! let mut statement = connection
//! .prepare(
//! "
//! SELECT * FROM users WHERE age > ?
//! ",
//! )
//! .prepare("SELECT * FROM users WHERE age > ?")
//! .unwrap();
//!
//! statement.bind(1, 50).unwrap();
@ -90,11 +86,7 @@
//! # .unwrap();
//!
//! let mut cursor = connection
//! .prepare(
//! "
//! SELECT * FROM users WHERE age > ?
//! ",
//! )
//! .prepare("SELECT * FROM users WHERE age > ?")
//! .unwrap()
//! .cursor();
//!
@ -114,24 +106,35 @@ extern crate sqlite3_sys as ffi;
use std::{error, fmt};
macro_rules! raise(
($message:expr) => (return Err(::Error { code: None, message: Some($message.to_string()) }));
($message:expr) => (
return Err(::Error {
code: None,
message: Some($message.to_string()),
})
);
);
macro_rules! error(
($connection:expr, $code:expr) => (match ::last_error($connection) {
Some(error) => return Err(error),
_ => return Err(::Error { code: Some($code as isize), message: None }),
_ => return Err(::Error {
code: Some($code as isize),
message: None,
}),
});
);
macro_rules! ok(
($connection:expr, $result:expr) => (match $result {
::ffi::SQLITE_OK => {},
::ffi::SQLITE_OK => {}
code => error!($connection, code),
});
($result:expr) => (match $result {
::ffi::SQLITE_OK => {},
code => return Err(::Error { code: Some(code as isize), message: None }),
::ffi::SQLITE_OK => {}
code => return Err(::Error {
code: Some(code as isize),
message: None,
}),
});
);
@ -151,7 +154,7 @@ macro_rules! path_to_cstr(
Some(path) => match ::std::ffi::CString::new(path) {
Ok(string) => string,
_ => raise!("failed to process a path"),
},
}
_ => raise!("failed to process a path"),
});
);