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 different 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 }, id: { type: uuid, initialValue: "uuid" }, address: { type: string }, registeredAt: { type: timestampMilliseconds, fromMetadata: "createdAtTime", }, updatedAt: { type: timestampMilliseconds, 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.