1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! Minimal example: open a database in the VFS, write a row, read it back.
//!
//! Run with:
//!
//! ```bash
//! cargo run --example sqlite_basic --features sqlite
//! ```
use bashkit::Bash;
#[tokio::main]
async fn main() -> bashkit::Result<()> {
let mut bash = Bash::builder()
.sqlite()
.env("BASHKIT_ALLOW_INPROCESS_SQLITE", "1")
.build();
// Create a table and insert a row in one invocation.
let r = bash
.exec(
r#"
sqlite /tmp/notes.sqlite "
CREATE TABLE IF NOT EXISTS notes(id INTEGER PRIMARY KEY, body TEXT);
INSERT INTO notes(body) VALUES ('hello world');
"
"#,
)
.await?;
println!("write: exit={}, stderr={:?}", r.exit_code, r.stderr);
// Read it back in a second invocation — proves persistence to the VFS.
let r = bash
.exec(r#"sqlite -header /tmp/notes.sqlite "SELECT id, body FROM notes ORDER BY id""#)
.await?;
print!("{}", r.stdout);
Ok(())
}