diff --git a/docs/table-of-contents.json b/docs/table-of-contents.json index e146be0..1180612 100644 --- a/docs/table-of-contents.json +++ b/docs/table-of-contents.json @@ -19,5 +19,11 @@ "how-to": { "title": "How To", "pages": [["query-with-comunica", "Query with Comunica"]] + }, + "v2": { + "title": "Version 2 (not yet released)", + "pages": [ + ["pagination", "Pagination"] + ] } } diff --git a/docs/v2/index.md b/docs/v2/index.md new file mode 100644 index 0000000..9fc34fc --- /dev/null +++ b/docs/v2/index.md @@ -0,0 +1,4 @@ +# Version 2 (not yet released) + +This section of documentation describes upcoming features of LDkit that has not +yet been released. You can try them by checking out the GitHub repository. diff --git a/docs/v2/pagination.md b/docs/v2/pagination.md new file mode 100644 index 0000000..292fbce --- /dev/null +++ b/docs/v2/pagination.md @@ -0,0 +1,52 @@ +# Pagination + +Pagination feature enhances data accessibility by enabling users to efficiently +navigate through large datasets. The feature integrates seamlessly with the +existing [Lens](../components/lens) `find` method, allowing for controlled data +retrieval. + +### Specify a range of data to query + +```ts +import { createLens } from "ldkit"; +import { schema } from "ldkit/namespaces"; + +// Create a schema +const PersonSchema = { + "@type": schema.Person, + name: schema.name, +} as const; + +// Create a lens instance +const Persons = createLens(PersonSchema); + +await Persons.find({ take: 10 }); // returns first 10 persons or less +await Persons.find({ take: 10, skip: 10 }); // returns the next set of 10 persons +await Persons.find(); // returns the default set of 1000 persons maximum +``` + +### Setting global defaults + +For consistent pagination behavior across an application, you can define a +global `take` default in the [Context](../components/context). This eliminates +the need to repeatedly set take in each find call, streamlining the development +process. The default value for `take` is 1000. + +```ts +import { type Context, createLens, setDefaultContext } from "ldkit"; + +const context: Context = { + sources: ["https://example.com/sparql"], + take: 100, // set the default take value to 100 +}; + +setDefaultContext(context); + +const customContext: Context = { + ...context, + take: 10, +}; + +const First = createLens(FirstSchema); // will use the default context with take = 100 +const Second = createLens(SecondSchema, customContext); // will use custom context with take = 10 +```