Quick Start
Get started with jasonisnthappy in minutes
Installation
Choose your language to get started:
# Add to Cargo.toml
[dependencies]
jasonisnthappy = "0.1"
pip install jasonisnthappy
npm install jasonisnthappy
# or
bun add jasonisnthappy
go get github.com/sohzm/jasonisnthappy
Basic Usage
Open a database, insert a document, query it, and perform basic operations:
use jasonisnthappy::{Database, Collection};
use serde_json::json;
// Open database
let db = Database::open("myapp.db")?;
let users = db.collection("users");
// Insert a document
let id = users.insert(json!({
"name": "Alice",
"age": 30,
"city": "NYC"
}))?;
// Find by ID
let user = users.find_by_id(&id)?;
println!("{}", user["name"]);
// Query documents
let results = users.find("age > 25")?;
// Update
users.update_by_id(&id, json!({"age": 31}))?;
// Delete
users.delete_by_id(&id)?;
// Close
db.close()?;
from jasonisnthappy import Database
# Open database
db = Database.open("./myapp.db")
try:
# Get collection
coll = db.get_collection("users")
# Insert a document
doc_id = coll.insert({
"name": "Alice",
"age": 30,
"city": "NYC"
})
# Find by ID
user = coll.find_by_id(doc_id)
print(user["name"])
# Query documents
results = coll.find("age > 25")
# Update
coll.update_by_id(doc_id, {"age": 31})
# Delete
coll.delete_by_id(doc_id)
coll.close()
finally:
db.close()
import { Database } from 'jasonisnthappy';
// Open database
const db = await Database.open('./myapp.db');
try {
const users = db.collection('users');
// Insert a document
const id = await users.insert({
name: 'Alice',
age: 30,
city: 'NYC'
});
// Find by ID
const user = await users.findById(id);
console.log(user.name);
// Query documents
const results = await users.find('age > 25');
// Update
await users.updateById(id, { age: 31 });
// Delete
await users.deleteById(id);
} finally {
await db.close();
}
package main
import (
"fmt"
"github.com/sohzm/jasonisnthappy"
)
func main() {
// Open database
db, err := jasonisnthappy.Open("myapp.db")
if err != nil {
panic(err)
}
defer db.Close()
users := db.Collection("users")
// Insert a document
id, err := users.Insert(map[string]interface{}{
"name": "Alice",
"age": 30,
"city": "NYC",
})
if err != nil {
panic(err)
}
// Find by ID
user, err := users.FindByID(id)
if err != nil {
panic(err)
}
fmt.Println(user["name"])
// Query documents
results, err := users.Find("age > 25")
if err != nil {
panic(err)
}
// Update
err = users.UpdateByID(id, map[string]interface{}{
"age": 31,
})
if err != nil {
panic(err)
}
// Delete
err = users.DeleteByID(id)
if err != nil {
panic(err)
}
}
Insert Documents
Insert documents into a collection:
let id = users.insert(json!({
"name": "Bob",
"age": 25
}))?;
doc_id = coll.insert({
"name": "Bob",
"age": 25
})
const id = await users.insert({
name: 'Bob',
age: 25
});
id, err := users.Insert(map[string]interface{}{
"name": "Bob",
"age": 25,
})
Find Documents
Query documents using the query language:
// Find by ID
let user = users.find_by_id(&id)?;
// Query with filter
let results = users.find("age > 25 and city is 'NYC'")?;
// Find all
let all = users.find_all()?;
# Find by ID
user = coll.find_by_id(doc_id)
# Query with filter
results = coll.find("age > 25 and city = 'NYC'")
# Find all
all_docs = coll.find_all()
// Find by ID
const user = await users.findById(id);
// Query with filter
const results = await users.find("age > 25 and city is 'NYC'");
// Find all
const all = await users.findAll();
// Find by ID
user, err := users.FindByID(id)
// Query with filter
results, err := users.Find("age > 25 and city is 'NYC'")
// Find all
all, err := users.FindAll()
Update Documents
Update documents by ID or using a query:
// Update by ID
users.update_by_id(&id, json!({
"age": 31,
"city": "SF"
}))?;
# Update by ID
coll.update_by_id(doc_id, {
"age": 31,
"city": "SF"
})
// Update by ID
await users.updateById(id, {
age: 31,
city: 'SF'
});
// Update by ID
err := users.UpdateByID(id, map[string]interface{}{
"age": 31,
"city": "SF",
})
Delete Documents
Delete documents by ID or using a query:
// Delete by ID
users.delete_by_id(&id)?;
# Delete by ID
coll.delete_by_id(doc_id)
// Delete by ID
await users.deleteById(id);
// Delete by ID
err := users.DeleteByID(id)