Bobs
In Snappy, every piece of data is called a "Bob." Think of a Bob as a simple info card—like a product or a customer. Each Bob has a type (called a "flavor") and its own unique ID.
Here’s what a product Bob looks like:
{
"id": "ocb3rfqG9jBhhodNsdRAz",
"flavor": "products",
"name": "Silver Bracelet",
"price": 123.50
}
How Do You Work With Bobs?
Most of the time, you’ll add, change, or delete Bobs in the Dashboard. There’s a helper called bobApi that makes this super easy.
To use it, just add this to your code:
import { bobApi } from "@snpy";
Here’s what you can do with bobApi:
| Method | What it does |
|---|---|
merge(bob: Bob | NewBob): Bob | Adds a new Bob or updates one (makes an ID if needed) |
get(flavor: string, id: string): Bob | null | Finds a Bob by its type and ID (returns nothing if not found) |
Example: Make a Product and Change Its Price
const { id } = await bobApi.merge({
flavor: "products",
name: "Silver Bracelet",
price: 123.50
});
const bracelet = await bobApi.get("products", id);
bracelet.price *= 2;
await bobApi.merge(bracelet);
That’s it! You just made a product, found it, changed the price, and saved it again.