Skip to content

Commit

Permalink
wasi,demo: add creating a table
Browse files Browse the repository at this point in the history
  • Loading branch information
psarna committed Nov 26, 2023
1 parent 52bf745 commit 3b0d30f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions libsql-sqlite3/ext/libsql-wasi-demo/src/main.rs
Expand Up @@ -42,10 +42,24 @@ fn main() -> anyhow::Result<()> {

libsql_wasi_init.call(&mut store, ())?;
let db = open_func.call(&mut store, db_path)?;

let sql = malloc.call(&mut store, 64)?;
memory.write(&mut store, sql as usize, b"PRAGMA journal_mode=WAL;\0")?;
let rc = exec_func.call(&mut store, (db, sql))?;
free.call(&mut store, sql)?;
if rc != 0 {
anyhow::bail!("Failed to execute SQL");
}

let sql = malloc.call(&mut store, 64)?;
memory.write(
&mut store,
sql as usize,
b"CREATE TABLE testme(id, v1, v2);\0",
)?;
let rc = exec_func.call(&mut store, (db, sql))?;
free.call(&mut store, sql)?;

let _ = close_func.call(&mut store, db)?;
free.call(&mut store, db_path)?;

Expand Down

0 comments on commit 3b0d30f

Please sign in to comment.