forked from gluesql/gluesql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add examples for MemoryStorage (gluesql#499)
- Loading branch information
1 parent
d3d2a9d
commit 2a8e386
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |