Skip to content

Commit

Permalink
Add example to use rustqlite to persist the example into a local file
Browse files Browse the repository at this point in the history
This includes very simple error logging, prompting the user to replace
the DB file if it exists on concecutive runs.
  • Loading branch information
bsodmike committed Nov 2, 2024
1 parent 2a4f717 commit 7cf2aa9
Show file tree
Hide file tree
Showing 8 changed files with 1,472 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/Cargo.lock
/examples/hello-toasty-rustqlite/*.sql
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ members = [
# Examples
"examples/composite-key",
"examples/hello-toasty",
"examples/hello-toasty-rustqlite",
"examples/cratehub",
"examples/user-has-one-profile",

Expand Down
11 changes: 11 additions & 0 deletions examples/hello-toasty-rustqlite/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "example-hello-toasty-rustqlite"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
toasty = { path = "../../src/toasty" }
toasty-sqlite = { path = "../../src/db/sqlite" }

tokio = { version = "1.18", features = ["full"] }
28 changes: 28 additions & 0 deletions examples/hello-toasty-rustqlite/schema.toasty
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
model User {
#[key]
#[auto]
id: Id,

name: String,

#[unique]
email: String,

todos: [Todo],

moto: Option<String>,
}

model Todo {
#[key]
#[auto]
id: Id,

#[index]
user_id: Id<User>,

#[relation(key = user_id, references = id)]
user: User,

title: String,
}
7 changes: 7 additions & 0 deletions examples/hello-toasty-rustqlite/src/db/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![allow(non_upper_case_globals, dead_code, warnings)]

mod user;
pub use user::User;

mod todo;
pub use todo::Todo;
Loading

0 comments on commit 7cf2aa9

Please sign in to comment.