Skip to content

Items

In StatelyDB data is stored in units called Items. An Item is the basic building block of your data, similar to a row in a relational database or a document in a document-based database. Each Item Type is modeled in a Schema. Items have defined fields with specific data types, and can have nested objects and lists. Your Store can have many differen Item Types. Items may also have a heirarchical relationship, where a single parent Item contains multiple children that are independent Items.

Let’s look at an example of a Customer profile in an e-commerce app:

export const Customer = itemType("Customer", {
keyPath: "/cust-:id",
fields: {
name: { type: string, fieldNum: 1 },
id: { type: uuid, fieldNum: 2, initialValue: "uuid" },
address: { type: string, fieldNum: 4 },
registeredAt: {
type: timestampMilliseconds,
fieldNum: 5,
fromMetadata: "createdAtTime",
},
updatedAt: {
type: timestampMilliseconds,
fieldNum: 6,
fromMetadata: "lastModifiedAtTime",
},
},
});

This schema defines a Customer item type that stores some basic information. There are a number of fields such as id and address, with specific data types uuid and string. Notice how you can easily reference automatically-tracked metadata directly in the Item. Defining Item Types goes over how Items are described in more detail.