mirror of
https://github.com/fluencelabs/sqlite-wasm-connector
synced 2025-06-25 21:11:32 +00:00
improve tests
This commit is contained in:
@ -4,7 +4,7 @@
|
||||
//!
|
||||
//! Open a connection, create a table, and insert some rows:
|
||||
//!
|
||||
//! ```
|
||||
//! ```ignore
|
||||
//! let connection = sqlite::open(":memory:").unwrap();
|
||||
//!
|
||||
//! connection
|
||||
@ -20,7 +20,7 @@
|
||||
//!
|
||||
//! Select some rows and process them one by one as plain text:
|
||||
//!
|
||||
//! ```
|
||||
//! ```ignore
|
||||
//! # let connection = sqlite::open(":memory:").unwrap();
|
||||
//! # connection
|
||||
//! # .execute(
|
||||
@ -44,7 +44,7 @@
|
||||
//! The same query using a prepared statement, which is much more efficient than
|
||||
//! the previous technique:
|
||||
//!
|
||||
//! ```
|
||||
//! ```ignore
|
||||
//! use sqlite::State;
|
||||
//! # let connection = sqlite::open(":memory:").unwrap();
|
||||
//! # connection
|
||||
@ -72,7 +72,7 @@
|
||||
//! The same query using a cursor, which is a wrapper around a prepared
|
||||
//! statement providing the concept of row and featuring all-at-once binding:
|
||||
//!
|
||||
//! ```
|
||||
//! ```ignore
|
||||
//! use sqlite::Value;
|
||||
//! # let connection = sqlite::open(":memory:").unwrap();
|
||||
//! # connection
|
||||
|
61
src/test.rs
61
src/test.rs
@ -1,5 +1,6 @@
|
||||
use marine_rs_sdk::marine;
|
||||
use marine_sqlite_connector::State;
|
||||
use marine_sqlite_connector::Value;
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
@ -7,31 +8,6 @@ pub fn main() {}
|
||||
pub fn test1() {
|
||||
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
||||
|
||||
connection
|
||||
.execute(
|
||||
"
|
||||
CREATE TABLE users (name TEXT, age INTEGER);
|
||||
INSERT INTO users VALUES ('Alice', 42);
|
||||
INSERT INTO users VALUES ('Bob', 69);
|
||||
",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
connection
|
||||
.iterate("SELECT * FROM users WHERE age > 50", |pairs| {
|
||||
for &(column, value) in pairs.iter() {
|
||||
println!("{} = {}", column, value.unwrap());
|
||||
}
|
||||
true
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[marine]
|
||||
pub fn test2() {
|
||||
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
||||
|
||||
println!("connection id = {}\n", connection.as_raw());
|
||||
connection
|
||||
.execute(
|
||||
"
|
||||
@ -48,15 +24,13 @@ pub fn test2() {
|
||||
|
||||
statement.bind(1, 50).unwrap();
|
||||
|
||||
while let State::Row = statement.next().unwrap() {
|
||||
println!("name = {}", statement.read::<String>(0).unwrap());
|
||||
println!("age = {}", statement.read::<i64>(1).unwrap());
|
||||
}
|
||||
assert_eq!(statement.next().unwrap(), State::Row);
|
||||
assert_eq!(statement.read::<String>(0).unwrap(), "Bob");
|
||||
assert_eq!(statement.read::<i64>(1).unwrap(), 69);
|
||||
}
|
||||
#[marine]
|
||||
pub fn test3() {
|
||||
use marine_sqlite_connector::Value;
|
||||
|
||||
#[marine]
|
||||
pub fn test2() {
|
||||
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
||||
|
||||
connection
|
||||
@ -77,15 +51,13 @@ pub fn test3() {
|
||||
cursor.bind(&[Value::Integer(50)]).unwrap();
|
||||
|
||||
while let Some(row) = cursor.next().unwrap() {
|
||||
println!("name = {}", row[0].as_string().unwrap());
|
||||
println!("age = {}", row[1].as_integer().unwrap());
|
||||
assert_eq!(row[0].as_string().unwrap(), "Bob");
|
||||
assert_eq!(row[1].as_integer().unwrap(), 69);
|
||||
}
|
||||
}
|
||||
|
||||
#[marine]
|
||||
pub fn test4() {
|
||||
use marine_sqlite_connector::Value;
|
||||
|
||||
pub fn test3() {
|
||||
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
||||
|
||||
connection
|
||||
@ -103,13 +75,12 @@ pub fn test4() {
|
||||
cursor.bind(1, &Value::Integer(50)).unwrap();
|
||||
cursor.bind(2, &Value::Binary(vec![1, 2, 3])).unwrap();
|
||||
|
||||
cursor.next().unwrap();
|
||||
// check that blob is not null
|
||||
assert!(cursor.next().is_ok());
|
||||
}
|
||||
|
||||
#[marine]
|
||||
pub fn test5() {
|
||||
use marine_sqlite_connector::Value;
|
||||
|
||||
pub fn test4() {
|
||||
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
||||
|
||||
connection
|
||||
@ -137,12 +108,6 @@ pub fn test5() {
|
||||
cursor.bind(&[Value::Integer(50)]).unwrap();
|
||||
|
||||
while let Some(row) = cursor.next().unwrap() {
|
||||
if vec![1, 2, 3] != row[0].as_binary().unwrap().to_vec() {
|
||||
println!(
|
||||
"expected: {:?}, actual: {:?}",
|
||||
vec![1, 2, 3],
|
||||
row[0].as_binary().unwrap()
|
||||
);
|
||||
}
|
||||
assert_eq!(row[0].as_binary().unwrap().to_vec(), vec![1, 2, 3]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user