A simple SQL and Mongo implementation of cursor based pagination
Inside your Node project directory, run the following:
npm i --save @dashdot/cursors
Or with Yarn:
yarn add @dashdot/cursors
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()