Skip to content

Commit

Permalink
Added pagination docs
Browse files Browse the repository at this point in the history
  • Loading branch information
karelklima committed Nov 22, 2023
1 parent 1c372a2 commit 97c84bb
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/table-of-contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
]
}
}
4 changes: 4 additions & 0 deletions docs/v2/index.md
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.
52 changes: 52 additions & 0 deletions docs/v2/pagination.md
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
```

0 comments on commit 97c84bb

Please sign in to comment.