You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-20Lines changed: 20 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ Are you running a service, using an SQL database, and want to support cursor sty
4
4
5
5
## How it works
6
6
7
-
1. When a request comes in you call the library with a `query` object containing how many items to fetch (`first`/`last`), where to fetch from (`before`/`after`) and the sort config (`sortFields`), along with a `setup` object.
7
+
1. When a request comes in you call the library with a `query` object containing how many items to fetch (`first`/`last`), where to fetch from (`before`/`after`), along with a `setup` object which contains the sort config.
8
8
2. The `runQuery` function you provided in `setup` is invoked, and provided with a `limit`, `whereFragmentBuilder` and `orderByFragmentBuilder`. You integrate these into your query, run it, and then return the results.
9
9
3. The library takes the results, and for each one it generates a unique `cursor`, which it then returns alongside each row. It also returns `hasNextPage`/`hasPreviousPage`/`startCursor`/`endCursor` properties.
10
10
@@ -66,17 +66,17 @@ async function fetchUsers(userInput: {
66
66
67
67
const { edges, pageInfo } =awaitwithPagination({
68
68
query: {
69
-
sortFields: [
70
-
{ field: 'first_name', order: userInput.order },
71
-
{ field: 'last_name', order: userInput.order },
72
-
{ field: 'id', order: userInput.order },
73
-
],
74
69
first: userInput.first,
75
70
last: userInput.last,
76
71
before: userInput.before,
77
72
after: userInput.after,
78
73
},
79
74
setup: {
75
+
sortFields: [
76
+
{ field: 'first_name', order: userInput.order },
77
+
{ field: 'last_name', order: userInput.order },
78
+
{ field: 'id', order: userInput.order },
79
+
],
80
80
// generate one with `npx -p sql-cursor-pagination generate-secret`
|`first`|`number`| If `last` isn't present. | The number of rows to fetch from the start of the window. |
145
-
|`last`|`number`| If `first` isn't present. | The number of rows to fetch from the end of the window. |
146
-
|`sortFields`|`{ field: string, order: 'asc' \| 'desc' }[]`| Yes | This takes an array of objects which have `field` and `order` properties. There must be at least one entry and you must include an entry that maps to a unique key, otherwise it's possible for there to be cursor collisions, which will result in an exception. |
147
-
|`after`|`string`| No | The window will cover the row after the provided cursor, and later rows. This takes the string `cursor` from a previous result`. |
148
-
|`before`|`string`| No | The window will cover the row before the provided cursor, and earlier rows. This takes the string `cursor` from a previous result. |
|`first`|`number`| If `last` isn't present. | The number of rows to fetch from the start of the window. |
145
+
|`last`|`number`| If `first` isn't present. | The number of rows to fetch from the end of the window. |
146
+
|`after`|`string`| No | The window will cover the row after the provided cursor, and later rows. This takes the string `cursor` from a previous result`. |
147
+
|`before`|`string`| No | The window will cover the row before the provided cursor, and earlier rows. This takes the string `cursor` from a previous result. |
|`runQuery`|`function`| Yes | This function is responsible for running the database query, and returning the array of rows. It is provided with a `QueryContent` object which contains a `WHERE` fragment, `ORDER BY` fragment and `limit`, which must be included in the query. |
155
-
|`queryName`|`string`| Yes | A name for this query. It should be unique to the query, and is used to bind the cursors to it. This prevents a cursor that was created for another query being used for this one. |
156
-
|`cursorSecret`|`CursorSecret`| Yes | The secret that is used to encrypt the cursor, created from `buildCursorSecret(secret: string)`. Must be at least 30 characters. Generate one with `npx -p sql-cursor-pagination generate-secret`. |
157
-
|`maxNodes`|`number`| No | The maximum number of allowed rows in the response before the `ErrTooManyNodes` error is thrown. _Default: 100_|
158
-
|`cursorGenerationConcurrency`|`number`| No | The maximum number of cursors to generate in parallel. _Default: 10_|
|`runQuery`|`function`| Yes | This function is responsible for running the database query, and returning the array of rows. It is provided with a `QueryContent` object which contains a `WHERE` fragment, `ORDER BY` fragment and `limit`, which must be included in the query. |
154
+
|`queryName`|`string`| Yes | A name for this query. It should be unique to the query, and is used to bind the cursors to it. This prevents a cursor that was created for another query being used for this one. |
155
+
|`sortFields`|`{ field: string, order: 'asc' \| 'desc' }[]`| Yes | This takes an array of objects which have `field` and `order` properties. There must be at least one entry and you must include an entry that maps to a unique key, otherwise it's possible for there to be cursor collisions, which will result in an exception. |
156
+
|`cursorSecret`|`CursorSecret`| Yes | The secret that is used to encrypt the cursor, created from `buildCursorSecret(secret: string)`. Must be at least 30 characters. Generate one with `npx -p sql-cursor-pagination generate-secret`. |
157
+
|`maxNodes`|`number`| No | The maximum number of allowed rows in the response before the `ErrTooManyNodes` error is thrown. _Default: 100_|
158
+
|`cursorGenerationConcurrency`|`number`| No | The maximum number of cursors to generate in parallel. _Default: 10_|
0 commit comments