-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c372a2
commit 97c84bb
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` |