Skip to content

Commit

Permalink
Add examples for MemoryStorage (gluesql#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonbrad committed Nov 6, 2022
1 parent d3d2a9d commit 2a8e386
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions pkg/rust/examples/memory_storage_usage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#[cfg(feature = "memory-storage")]
mod api_usage {
use gluesql::{memory_storage::MemoryStorage, prelude::Glue};

fn memory_basic() {
let storage = MemoryStorage::default();
let mut glue = Glue::new(storage);

glue.execute("DROP TABLE IF EXISTS api_test");

glue.execute(
"CREATE TABLE api_test (
id INTEGER,
name TEXT,
nullable TEXT NULL,
is BOOLEAN
)",
);

glue.execute(
"INSERT INTO api_test (
id,
name,
nullable,
is
) VALUES
(1, 'test1', 'not null', TRUE),
(2, 'test2', NULL, FALSE)",
);
}

fn memory_basic_async() {
use futures::executor::block_on;

let storage = MemoryStorage::default();
let mut glue = Glue::new(storage);

block_on(async {
glue.execute_async("DROP TABLE IF EXISTS api_test").await;

glue.execute_async(
"CREATE TABLE api_test (
id INTEGER,
name TEXT,
nullable TEXT NULL,
is BOOLEAN
)",
)
.await;
});
}

pub fn run() {
memory_basic();
memory_basic_async();
}
}

fn main() {
#[cfg(feature = "memory-storage")]
api_usage::run();
}

0 comments on commit 2a8e386

Please sign in to comment.