Created
August 13, 2021 19:21
-
-
Save jcuffe/ebf260ea596f5be2596a6a40fac03ac6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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