Constructor of the model to retrieve
Arguments for retrieval
The retrieved model instance, or null if not found
Given a base object representing a Model, hydrates its D1, R2 and KV properties. Fetches all KV and R2 data concurrently.
Constructor of the model to hydrate
Arguments for hydration
The hydrated model instance
Lists all instances of a given Model from D1.
Constructor of the model to list
Include tree specifying which navigation properties to include
Array of listed model instances
Given a new Model object, performs an upsert operation for D1 and KV.
Concurrently performs all D1 and KV operations.
Some KV results depend on a successful D1 upsert to resolve their keys, and will be uploaded only after the D1 upsert completes.
If a Model is missing a primary key, and that primary key is of Integer type, it will be auto-incremented by D1. Else, upsert will fail if the primary key is missing.
Constructor of the model to upsert
The new model object to upsert
Include tree specifying which navigation properties to include
The upserted model instance, or null if upsert failed
StaticfromCreates an instance of an Orm
The Wrangler environment containing Cloudflare bindings.
StaticmapMaps D1 results into model instances. Capable of mapping a flat result set
(ie, SELECT * FROM Model) or a joined result granted it is aliased as select_model would produce.
Does not hydrate into an instance of the model; for that, use hydrate after mapping.
Constructor of the model to map to
Results from a D1 query
Include tree specifying which navigation properties to include
Array of mapped model instances
StaticselectGenerates a SELECT query string for a given Model, retrieving the model and its relations aliased as JSON.
Constructor of the model to select
Arguments specifying which relations/fields to select
The generated SELECT query string
Orm.select(Boss, Boss.withAll);
// Example result:
const result = `
SELECT
"Boss"."id" AS "id",
"Person_1"."id" AS "persons.id",
"Person_1"."bossId" AS "persons.bossId",
"Dog_2"."id" AS "persons.dogs.id",
"Dog_2"."personId" AS "persons.dogs.personId",
"Cat_3"."id" AS "persons.cats.id",
"Cat_3"."personId" AS "persons.cats.personId"
FROM "Boss"
LEFT JOIN "Person" AS "Person_1"
ON "Boss"."id" = "Person_1"."bossId"
LEFT JOIN "Dog" AS "Dog_2"
ON "Person_1"."id" = "Dog_2"."personId"
LEFT JOIN "Cat" AS "Cat_3"
ON "Person_1"."id" = "Cat_3"."personId"
`;
Fetches a model by its primary key ID or key parameters.