Objects
An object represents one thing in your domain, such as a customer, invoice, or project.
Use sixb.objects(Type) to read and update objects with types inferred from your
ontology.
These examples run in backend code. For React apps, see Querying data in apps.
Read an object
Pass the object's primary ID to get(). It returns the object, or null if it does not exist.
Property values are available under .properties:
import { Invoice } from "./ontology/invoice"
const invoices = sixb.objects(Invoice)
const invoice = await invoices.get("inv-001")
if (invoice) {
console.log(invoice.properties.amount, invoice.properties.status)
}
The returned object also includes primaryId, objectTypeId, and createdAt and updatedAt
as Date values.
Create or update an object
upsert() creates an object or updates the one with the same primary ID. Include the primary
property inside properties, along with all required properties when creating an object:
await invoices.upsert({
properties: {
id: "inv-001",
number: "INV-2026-001",
amount: 4800,
currency: "EUR",
status: "sent",
},
})
To update an existing object, pass only the primary ID and the properties to change. Omitted properties keep their values:
await invoices.upsert({
properties: { id: "inv-001", status: "paid" },
})
Inside an action's .edits() handler, use its objects helper to stage
changes instead. Those edits are synchronous and commit together when the handler succeeds.
List objects
Use list() to browse objects by ID or creation/update time. Set limit and offset to page
through the results:
const { objects, hasMore, total } = await invoices.list({
orderBy: "updatedAt",
order: "desc",
limit: 25,
offset: 0,
})
objects contains the current page, hasMore indicates another page, and total is the matching
count. Increase offset by limit to read the next page. For property filters, text search, or
related objects, use queries.
Add or remove relationships
Use byId() to work with one object's links. Pass a link token and the
target object's type and primary ID:
import { Customer } from "./ontology/customer"
const invoice = invoices.byId("inv-001")
const customer = { objectTypeId: Customer.id, primaryId: "cust-001" }
await invoice.link(Invoice.l.customer, customer)
const links = await invoice.listLinks(Invoice.l.customer)
await invoice.unlink(Invoice.l.customer, customer)
For a link with cardinality "one", remove the existing target before linking a different one.
Linking the same target updates the existing relationship. To replace a target atomically, use
action edits.
Write relationship properties
Pass values through the link call's properties option. This example uses the
reviewers relationship, which declares a required
assignedAt timestamp:
const reviewer = { objectTypeId: "Reviewer", primaryId: "reviewer-1" } as const
await invoices.byId("inv-001").link(Invoice.l.reviewers, reviewer, {
properties: { assignedAt: new Date() },
})
Each call replaces the relationship's properties, so include required values every time.
Use listLinks(Invoice.l.reviewers) to read the relationship rows, or
expand the link to read the related objects with their
linkProperties.
Open a file
file() reads a fileRef property through its object, with your permissions. open() returns the
fileRef and a body stream, or null when the object, the value, or the stored file is missing.
For a list of files, pass the index, such as file(Invoice.p.attachments, 0):
const pdf = await invoices.byId("inv-001").file(Invoice.p.pdf).open()
Delete and restore
delete() removes an object and its links. Deleting an object that does not exist has no effect:
await invoices.byId("inv-001").delete()
An object supplied by a projection stays hidden after deletion, even when the projection runs
again. Use restore() to reveal its projected state:
await invoices.byId("inv-001").restore()
For an object created only from code, deletion is permanent and restore() has no effect.
Use upsert() to create it again.
For commands against objects, see Actions. For values that change over time, see Telemetry.