Abstract
Readonly
createdThe timestamp marking when the entity was created
Readonly
idA unique identifier for the entity itself, automatically generated upon creation.
Readonly
typeThe type of the Entity
Readonly
updatedThe timestamp marking the last update to the entity. Initially set to the same value as createdAt
.
Same as the static update
method but on an instance. Returns the full updated instance
const updatedInstance = await instance.update({ email: "newemail@example.com", profileId: 789 });
const updatedInstance = await instance.update({ email: "newemail@example.com", someKey: null });
Static
createCreate an entity. If foreign keys are included in the attributes then BelongsToLinks will be demoralized accordingly
Attributes of the model to create
The new Entity
const newUser = await User.create({ name: "Alice", email: "alice@example.com", profileId: "123" });
Static
deleteDelete an entity by ID
The id of the entity to update
await User.delete("userId");
Static
findFind an entity by Id and optionally include associations
Entity Id
Optional
options: OptsFindByIdOptions
An entity with included associations serialized
const user = await User.findById("userId");
const user = await User.findById("userId", { include: [{ association: "profile" }] });
Static
partitionStatic
queryQuery by PartitionKey and optional SortKey/Filter/Index conditions
PartitionKey value and optional SortKey condition. Keys must be attributes defined on the model
Optional
options: QueryOptionsQueryBuilderOptions
const user = await User.query({ pk: "User#123" });
const user = await User.query({ pk: "User#123", sk: "Profile#123" });
const user = await User.query({ pk: "User#123", sk: { $beginsWith: "Profile" } });
const result = await User.query(
{
myPk: "User|123"
},
{
filter: {
type: ["BelongsToLink", "Profile"],
createdAt: { $beginsWith: "202" },
$or: [
{
foreignKey: "111",
updatedAt: { $beginsWith: "2023-02-15" }
},
{
foreignKey: ["222", "333"],
createdAt: { $beginsWith: "2021-09-15T" },
foreignEntityType: "Order"
},
{
id: "123"
}
]
}
}
);
const result = await User.query(
{
pk: "User#123",
sk: { $beginsWith: "Profile" }
},
{ indexName: "myIndex" }
);
Query an EntityPartition by EntityId and optional SortKey/Filter conditions. QueryByIndex not supported. Use Query with keys if indexName is needed
Entity Id
Optional
options: Omit<QueryOptions, "indexName">QueryOptions. Supports filter and skCondition. indexName is not supported
const user = await User.query("123");
const user = await User.query("123", { skCondition: "Profile#111" });
const user = await User.query("123", { skCondition: { $beginsWith: "Profile" } })
const user = await User.query("123", {
filter: {
type: "BelongsToLink",
createdAt: "2023-11-21T12:31:21.148Z"
}
});
Static
updateUpdate an entity. If foreign keys are included in the attribute then:
The id of the entity to update
Attributes to update
await User.update("userId", { email: "newemail@example.com", profileId: 789 });
await User.update("userId", { email: "newemail@example.com", someKey: null });
Generated using TypeDoc
Serves as an abstract base class for entities in the ORM system. It defines standard fields such as
id
,type
,createdAt
, andupdatedAt
, and provides static methods for CRUD operations and queries. This class encapsulates common behaviors and properties that all entities share, leveraging decorators for attribute metadata and supporting operations like finding, creating, updating, and deleting entities.Table classes should extend this class, and each entity should extend the table class
Entities extending
DynaRecord
can utilize these operations to interact with their corresponding records in the database, including handling relationships between different entities.Example