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
+17-17Lines changed: 17 additions & 17 deletions
Display the source diff
Display the rich diff
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 (`beforeCursor`/`afterCursor`) 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`) and the sort config (`sortFields`), along with a `setup` object.
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
@@ -16,9 +16,9 @@ Cursor pagination was made popular by GraphQL, and this library conforms to the
16
16
- First you specify the sort config. This contains a list of field names with their orders. It must contain a unique key.
17
17
- Then you request how many items you would like to fetch with `first`.
18
18
- Each item you get back also contains an opaque string cursor. The cursor is an encrypted string that contains the names of the fields in the sort config, alongside their values.
19
-
- To fetch the next set of items you make a new request with `first` and `afterCursor` being the cursor of the last item you received.
19
+
- To fetch the next set of items you make a new request with `first` and `after` being the cursor of the last item you received.
20
20
21
-
If you want to fetch items in reverse order you can use `last` and `beforeCursor` instead.
21
+
If you want to fetch items in reverse order you can use `last` and `before` instead.
22
22
23
23
The use of cursors means if items are added/removed between requests, the user will never see the same item twice.
24
24
@@ -59,8 +59,8 @@ async function fetchUsers(userInput: {
|`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
-
|`afterCursor`|`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
-
|`beforeCursor`|`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
+
|`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. |
149
149
150
150
### Setup
151
151
@@ -166,9 +166,9 @@ The `whereFragmentBuilder`/`orderByFragmentBuilder` objects provide the followin
166
166
167
167
## Errors
168
168
169
-
This library exports various error objects. `SqlCursorPaginationQueryError` will be thrown if the `first`/`last`/`beforeCursor`/`afterCursor` properties are the correct javascript type, but the contents is not valid.
169
+
This library exports various error objects. `SqlCursorPaginationQueryError` will be thrown if the `first`/`last`/`before`/`after` properties are the correct javascript type, but the contents is not valid.
170
170
171
-
E.g. `ErrFirstNotInteger` is thrown if `first` was a `number`, but not an integer. `ErrBeforeCursorWrongQuery` is thrown if the provided `beforeCursor` was a valid cursor, but for a different query. You may want to map these errors to HTTP 400 responses.
171
+
E.g. `ErrFirstNotInteger` is thrown if `first` was a `number`, but not an integer. `ErrBeforeCursorWrongQuery` is thrown if the provided `before` was a valid cursor, but for a different query. You may want to map these errors to HTTP 400 responses.
0 commit comments