import { Lens } from "https://deno.land/x/ldkit/mod.ts";
Find entities with a custom SPARQL query.
The query must be a CONSTRUCT query, and the root nodes must be of type ldkit:Resource
.
So that the decoder can decode the results, the query must also return all properties
according to the data schema.
Examples
Example 1
Example 1
import { createLens } from "ldkit";
import { ldkit, schema } from "ldkit/namespaces";
import { CONSTRUCT } from "ldkit/sparql";
// 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);
// Query to find all persons named "Doe"
const query = CONSTRUCT`?s a <${ldkit.Resource}>; <${schema.name}> ?name`
.WHERE`?s <${schema.name}> ?name; <${schema.familyName}> "Doe"`.build();
// Find all persons that match the custom query
const doePersons = await Persons.query(query);