Skip to content
/ cursors Public

A simple SQL and Mongo implementation of cursor based pagination

License

Notifications You must be signed in to change notification settings

wappla/cursors

Repository files navigation

Dashdot Cursors

build codecov

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()

About

A simple SQL and Mongo implementation of cursor based pagination

Resources

License

Stars

Watchers

Forks

Languages