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:

1
export const Customer = itemType("Customer", {
2
keyPath: "/cust-:id",
3
fields: {
4
name: { type: string, fieldNum: 1 },
5
id: { type: uuid, fieldNum: 2, initialValue: "uuid" },
6
address: { type: string, fieldNum: 4 },
7
registeredAt: {
8
type: timestampMilliseconds,
9
fieldNum: 5,
10
fromMetadata: "createdAtTime",
11
},
12
updatedAt: {
13
type: timestampMilliseconds,
14
fieldNum: 6,
15
fromMetadata: "lastModifiedAtTime",
16
},
17
},
18
});

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.