use cratestack::include_embedded_schema;
use cratestack::{RusqliteRuntime, rusqlite_backend::ddl::create_table_sql};
include_embedded_schema!("examples/sqlite_quickstart.cstack");
use cratestack_rusqlite::ModelDelegate;
use cratestack_schema::models::Note;
use cratestack_schema::{CreateNoteInput, NOTE_MODEL};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let runtime = RusqliteRuntime::open_in_memory()?;
runtime.with_connection(|conn| {
conn.execute_batch(&create_table_sql(&NOTE_MODEL))
.expect("create table");
Ok(())
})?;
let notes = ModelDelegate::<Note, uuid::Uuid>::new(&runtime, &NOTE_MODEL);
let id = uuid::Uuid::new_v4();
let created = notes
.create(CreateNoteInput {
id,
title: "First note".to_string(),
body: "Hello from a Rust-only frontend.".to_string(),
pinned: true,
createdAt: chrono::Utc::now(),
})
.run()?;
println!("inserted note {} (pinned={})", created.id, created.pinned);
let fetched = notes
.find_unique(id)
.run()?
.expect("note we just inserted exists");
println!("fetched: {} — {}", fetched.title, fetched.body);
let all = notes
.find_many()
.order_by(cratestack_schema::note::createdAt().desc())
.run()?;
println!("total notes in store: {}", all.len());
Ok(())
}