Skip to content

Instantly share code, notes, and snippets.

@jcuffe
Created August 13, 2021 19:21
Show Gist options
  • Save jcuffe/ebf260ea596f5be2596a6a40fac03ac6 to your computer and use it in GitHub Desktop.
Save jcuffe/ebf260ea596f5be2596a6a40fac03ac6 to your computer and use it in GitHub Desktop.
// New cursor format
const cursor = (record, columnName) => base64.encode(JSON.stringify({
name: record.constructor.name,
columnName,
value: record[columnName],
recordId: record.id
}))
// Paginate based on (potentially not unique) cursor column value, as well as (unique) record id
if (connection?.before) {
const cursor = cursorDecode(connection.before)
queryEdges = queryEdges.where(
cursor.columnName,
"<",
cursor.value,
).orWhere(builder => {
builder.where(cursor.columnName, "=", cursor.value)
.andWhere(Model.ref("id"), "<", cursor.recordId)
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment