import { Lens } from "https://deno.land/x/ldkit/mod.ts";
Returns the total number of entities corresponding to the data schema. Optionally, you can specify search criteria and a maximum number of results to count. The maximum caps the number of distinct matching entities.
Examples
Example 1
Example 1
import { createLens } from "ldkit";
import { schema } from "ldkit/namespaces";
// Create a schema
const PersonSchema = {
"@type": schema.Person,
name: schema.name,
} as const;
// Create a resource using the data schema above
const Persons = createLens(PersonSchema);
// Count all persons
const count = await Persons.count(); // number
// Count all persons with name that starts with "Ada"
const adaCount = await Persons.count({
where: {
name: { $strStarts: "Ada" },
},
});
// Count matching persons identified by an IRI; other criteria still apply
const adaByIriCount = await Persons.count({
where: {
$id: "http://example.org/Ada_Lovelace",
name: { $strStarts: "Ada" },
},
});
// Count at most 100 distinct matching persons
const limitedCount = await Persons.count({ max: 100 });
Parameters
optional
options: { where?: SchemaSearchInterface<T>; max?: number; } = [UNSUPPORTED]Search criteria and maximum number of results to count