Data Models and the Data API
How to define your own data tables in Oalo, import a CSV, stage and promote data, and push data in from another system through the Data API.
Every Oalo app is backed by a live data layer (see sync-overview.md). A data
model is a table you define for your own content: a product catalog, a list
of bookings, support tickets, anything. You describe the fields in plain terms and the
model is ready. Rows sync to every connected device in real time, and work
offline.
Building a data model
A model has a name and a set of fields. Each field has a type:
- string and text for words (text is for longer content).
- integer and float for numbers.
- boolean for yes or no.
- date and datetime for dates and timestamps.
- list for an array of values (tags, categories).
- json for a nested object.
- references:<table> to point at a row in another model.
You do not run a database migration to add a field. All your fields live together in a flexible record, so you can add a field to a model at any time and connected apps pick it up. Adding the same field twice is harmless. Changing a field's type is not allowed (make a new field instead).
A few columns are always present and you do not define them: a unique id, the owner, a content availability setting (free, premium, or tied to a product, which is how you gate premium content), and a locale for language. You can also mark a field as indexed (to filter on it quickly) or unique (to prevent duplicates).
Two table names are reserved: products and orders belong to Commerce (see
commerce.md). Use your own names for everything else.
These field names are reserved too, because they are the fixed columns every
row has, and a model that uses one is refused: id, document, owner_id,
availability, product_id, last_modified_ms, seqnum, deleted_at,
row_hash, locale. Pick another name (product_ref instead of
product_id, for example).
Shared data versus personal data
When you create a model you choose who sees its rows:
- Shared: everyone sees all rows. Use this for a catalog, an event schedule, a help library. Anything the same for all users.
- Personal (user-owned): each person sees only their own rows. Use this for a member's notes, tickets, or saved items. You name the field that marks the owner.
You can switch a model between the two later. Making personal data shared exposes everyone's rows to everyone, so that change asks you to confirm.
Working with rows
You add, change, and remove rows and they sync to connected apps automatically:
- Add a row and it appears on every client.
- Update a row and only the fields you name change. The rest are kept.
- Delete a row and it is soft-deleted. It drops out of queries and off clients, but is not hard-erased.
- Query rows by matching fields, for example all tickets where status is open.
Importing a CSV
You can build a model straight from a spreadsheet. Upload a CSV (or TSV), review the columns and the types Oalo inferred, and import. One import can:
- Create the model if it is new, or add any new columns to an existing one.
- Load the rows (up to 50,000 per import), re-importing cleanly if you pick a key column.
- Make it searchable by turning on vectorization for the fields you choose, so a bot can answer questions over the imported data.
You choose whether the import lands in your staging copy or your live app.
Letting a bot search a data model
Turning on vectorization makes a model searchable, but a bot cannot see it until you attach it. In the bot's Knowledge tab, under Data sources, tick the model (only vectorized models and tables appear there). A bot with nothing attached searches only its own knowledge base; it has no access to the catalog until you attach it here. This is a common surprise: the catalog is imported and vectorized, yet the bot answers "I couldn't find that" because it was never attached.
From the terminal, the same two steps:
oalo data vectorize catalog --fields title,description --where "type in simple,variable" --describe "Store products, with prices"
oalo bots # the bots, by public id
oalo bots knowledge bot_ABC --add catalog # attach; --remove detaches
vectorize works on a model or on a table your app made itself, and with no
flags it shows how many rows are embedded. Rows added or edited later, by your
app, a sync or the dashboard, are embedded again within 15 minutes; until then
an edited row is still found by its old text. An edit to a field that isn't
embedded embeds nothing. The text of the chosen fields goes to the embedding
provider, and a bot's answer sends the rows its search finds to its AI model,
so leave out fields that shouldn't leave Oalo. To keep a field out of what
the bot's AI reads while the rest of the row is found, use oalo data keep-from-ai <table> <field,...> (see data sources).
Once attached, the bot's AI reaches the data two ways, and the difference matters for product catalogs with variations:
- Semantic search finds rows by meaning, matching a customer who describes what they want in their own words. For a product catalog this indexes the top-level products only. A product's variations (its sizes, colours, options) are deliberately left out of the index, because indexing dozens of near-identical variation rows per product would flood results and bury the products themselves.
- Related rows pulls the variations that belong to one product. Given a product the bot already has, it fetches that product's sizes/colours/options directly. This is how a bot answers "what options does this product come in?" once it knows which product the customer means. It drills into the known product, rather than searching for the variation as if it were its own product (which would fail, since variations are not in the search index).
For related rows to work, the model needs a parent/child reference: the column on a variation row that points at its parent product (a WooCommerce export's "parent" column, holding the parent's SKU). A CSV import that includes such a column gets this automatically, so a bot can go from a found product straight to its options.
Staging and going live
A model and its rows exist in a staging copy and a live copy. You build and load data in staging, check it, then promote it to live so the app and your customers see it. Promoting copies the rows across. It does not disturb what is already live except to update matching rows.
Which copy a bot reads. A draft (unpublished) bot searches the staging
(dev) copy of your tables and uses staging booking data. A published bot uses
the live (prod) copy. So a draft bot that "can't find" rows you loaded live is
looking in staging: load the rows into staging too, or publish the bot.
The booking setup events (booking:types:create, booking:availability:add
and the rest) write the live copy unless you pass "env": "dev" (see
business-kits.md). Dev and prod says which copy every part
of Oalo uses, tests, loops, charts and CLI commands included.
The Data API: pushing data in from another system
If your data lives in another system, you can push it into Oalo over HTTP instead of by hand. There are two halves:
- Define the shape with the Data API.
GET /api/data/v1/modelslists your models,POST /api/data/v1/modelscreates one (with fields, shared or owned, and optional vectorization), and a promote endpoint moves a model's rows to live. - Move the rows with the Sync API under
/api/sync/v1(seesync-rest-api.md). Read rows (GET /:table, with paging and an optional live stream), and write them (POSTto create,PUT/PATCHto update,DELETEto soft-delete, or abulkendpoint for up to 1000 changes at once). Every write also syncs to connected apps.
Access is a bearer token you create in the dashboard. It is shown once, so
copy it then. You can scope a token to read only, read and write, or specific
tables, give it an expiry, and revoke it. Send it as
Authorization: Bearer oalo_sync_....
Limits protect the service: reads are capped around 600 per minute and writes around 120 per minute per token, and every response tells you how much you have left.
Data models versus Commerce products
These are deliberately separate. Commerce owns the products and orders
tables that are tied to Stripe and drive payments and access (see commerce.md).
A data model is a general table you define freely. So a product catalog
people browse is a data model. A paid product they buy is a Commerce product.
You can have both: a catalog model for browsing, linked to Commerce products for
checkout.
Your own Base, with every feature, from $99 a month.