Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add reverse param to query method #67

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/contract/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface QueryParams {
to?: API.v1.TableIndexType | string | number
maxRows?: number
rowsPerAPIRequest?: number
reverse?: boolean
}

interface FieldToIndex {
Expand Down Expand Up @@ -123,6 +124,7 @@ export class Table<RowType = any> {
lower_bound: wrapIndexValue(params.from),
upper_bound: wrapIndexValue(params.to),
limit: params.rowsPerAPIRequest || this.defaultRowLimit,
reverse: params.reverse,
}

if (params.index) {
Expand Down Expand Up @@ -173,6 +175,7 @@ export class Table<RowType = any> {
index_position: params.index_position,
key_type: params.key_type,
json: false,
reverse: params.reverse,
}

if (params.index) {
Expand Down Expand Up @@ -259,6 +262,7 @@ export class Table<RowType = any> {
lower_bound: wrapIndexValue(params.from),
upper_bound: wrapIndexValue(params.to),
limit: params.rowsPerAPIRequest || this.defaultRowLimit,
reverse: params.reverse,
}

return new TableScopeCursor({
Expand Down
19 changes: 19 additions & 0 deletions test/data/requests/74068b42051d704bf454c567035d80e7be11dfaf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"request": {
"path": "https://eos.greymass.com/v1/chain/get_table_rows",
"params": {
"method": "POST",
"body": "{\"json\":false,\"limit\":1000,\"table\":\"trending\",\"code\":\"decentiumorg\",\"scope\":\"decentiumorg\",\"key_type\":\"i64\",\"lower_bound\":\"5\",\"upper_bound\":\"6\",\"reverse\":true}"
}
},
"status": 200,
"json": {
"rows": [
"06000000000000000895010000000000104d76cca58c6534ca009b2e9baba662bfbfed5c000000006c958ee2037f9a9c039e4c50d4f9473dc7972fa19a2808d37d988f24cba96d0ff3b41474754673da3801598bc003cc70fbcc0a5dfc134b91db86ecbae70d497fd2f2e8bc32e31aa1aaee41c4e61d010000000000000000000000000000",
"05000000000000004190010000000000a02ecd5845b73055a02ecd5845b730557d41ec5c000090dae5a9904a039c9e9903de1a09302017b9bbe1ba8aec85617dd6513aaf4bc65e5e1e3663be34cd9cfaac00010000000000000000000000000000"
],
"more": false,
"next_key": ""
},
"text": "{\"rows\":[\"06000000000000000895010000000000104d76cca58c6534ca009b2e9baba662bfbfed5c000000006c958ee2037f9a9c039e4c50d4f9473dc7972fa19a2808d37d988f24cba96d0ff3b41474754673da3801598bc003cc70fbcc0a5dfc134b91db86ecbae70d497fd2f2e8bc32e31aa1aaee41c4e61d010000000000000000000000000000\",\"05000000000000004190010000000000a02ecd5845b73055a02ecd5845b730557d41ec5c000090dae5a9904a039c9e9903de1a09302017b9bbe1ba8aec85617dd6513aaf4bc65e5e1e3663be34cd9cfaac00010000000000000000000000000000\"],\"more\":false,\"next_key\":\"\"}"
}
10 changes: 10 additions & 0 deletions test/tests/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ suite('Table', () => {
assert.equal(rowsSellTxtScope.length, 348)
})
})

test('reverse', async function () {
const tableRowCursor = decentiumTrendingTable.query({from: 5, to: 6, reverse: true})
tableRowCursor.reset()

assert.deepEqual(
Serializer.objectify(await tableRowCursor.next()).map((row) => row.id),
[6, 5]
)
})
})

suite('get', () => {
Expand Down
Loading