Get up and running with jasonisnthappy in 5 minutes
This quickstart guide will help you create your first jasonisnthappy database and perform basic CRUD operations. We’ll use Rust for this example, but jasonisnthappy works with Go, Python, and JavaScript too.
Here’s a complete example that demonstrates the core features of jasonisnthappy:
1
Open a database
Create or open a database file. If the file doesn’t exist, jasonisnthappy will create it.
examples/collection_crud.rs
use jasonisnthappy::core::database::Database;use serde_json::json;use std::sync::Arc;let db = Arc::new(Database::open("crud_example.db")?);let users = db.collection("users");
The database file stores all your data. Additional files like .lock and -wal (write-ahead log) are created automatically for concurrency control and durability.
2
Insert documents
Add JSON documents to a collection. Collections are created automatically when you first use them.
examples/collection_crud.rs
let alice = json!({"name": "Alice", "age": 30, "city": "New York"});let bob = json!({"name": "Bob", "age": 25, "city": "San Francisco"});let charlie = json!({"name": "Charlie", "age": 35, "city": "Seattle"});let id1 = users.insert(alice)?;let id2 = users.insert(bob)?;let id3 = users.insert(charlie)?;println!("Inserted Alice: {}", id1);println!("Inserted Bob: {}", id2);println!("Inserted Charlie: {}", id3);
Each document is automatically assigned a unique ID that’s returned from the insert() operation.
3
Query documents
Retrieve documents by ID or count all documents in a collection.
examples/collection_crud.rs
// Count total documentslet count = users.count()?;println!("Total documents: {}", count);// Find by IDlet found = users.find_by_id(&id1)?;println!("Found: {}", serde_json::to_string_pretty(&found)?);// Find all documentslet all_users = users.find_all()?;for user in &all_users { println!("- {}", user["name"]);}
For operations that need atomicity, use explicit transactions. This example shows how to perform multiple operations that either all succeed or all fail together:
examples/basic_usage.rs
use jasonisnthappy::core::database::Database;let db = Database::open("example.db")?;// Begin a transactionlet mut tx = db.begin()?;// Write documents within the transactiontx.write_document("users", "user1", 100)?;tx.write_document("users", "user2", 101)?;// Commit to make changes permanenttx.commit()?;db.close()?;
If you don’t call commit(), the transaction will be automatically rolled back when it goes out of scope, discarding all changes.
jasonisnthappy includes a built-in web interface for exploring your data:
examples/web_ui_demo.rs
use jasonisnthappy::Database;let db = Database::open("web_demo.db")?;// Start the web UI on port 8080let _web_server = db.start_web_ui("127.0.0.1:8080")?;println!("Web UI running at http://127.0.0.1:8080");// Keep server alivestd::thread::park();
The Web UI provides:
Collection browser with document viewer
Real-time metrics dashboard
Search and pagination
Auto-refresh every 5 seconds
The Web UI is perfect for development and debugging. You can inspect your data, test queries, and monitor database performance in real-time.