Last active
November 3, 2020 11:45
-
-
Save randomnerd/e52f3d72f625873c631baa7cc8f651fb to your computer and use it in GitHub Desktop.
eos.get_full_table.js
This file contains 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
async function getFullTable(params, rpc) { | |
if (!params.limit) params.limit = 50 | |
const rows = [] | |
let more = true | |
let lastKey | |
let primaryKey | |
while (more) { | |
if (rows.length && primaryKey) lastKey = rows[rows.length - 1][primaryKey] | |
const result = await rpc.get_table_rows({ | |
...params, | |
json: true, | |
lower_bound: lastKey | |
}) | |
more = result.more | |
rows.push(...(lastKey ? result.rows.slice(1) : result.rows)) | |
if (result.rows.length) primaryKey = Object.keys(result.rows[0])[0] | |
} | |
return rows | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment