@dashdot/cursors
v0.4.0
Published
A simple SQL and Mongo implementation of cursor based pagination
Downloads
291
Keywords
Readme
Dashdot Cursors
A simple SQL and Mongo implementation of cursor based pagination
Usage
Inside your Node project directory, run the following:
npm i --save @dashdot/cursors
Or with Yarn:
yarn add @dashdot/cursors
API
import { cursorToSqlQuery } from '@dashdot/cursor'
import * as tables from './tables'
const user = await tables.users().fist()
const orderBy = {
email: 'ASC'
lastName: 'DESC',
firstName: 'ASC',
id: 'DESC',
}
const cursor = createCursor(user, orderBy)
const [
whereQuery,
whereValues,
orderQuery
] = cursorToSqlQuery(cursor, orderBy)
const nextUser = await tables.users()
.whereRaw(whereQuery, whereValues)
.orderByRaw(orderQuery)
.first()