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

Make query in get() optional to just fetch first row #35

Merged
merged 1 commit into from
Jul 25, 2023
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
2 changes: 1 addition & 1 deletion src/contract/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class Table<RowType = any> {
* @returns {Promise<TableRow>} Promise resolving to a single table row.
*/
async get(
queryValue: API.v1.TableIndexType | string,
queryValue?: API.v1.TableIndexType | string,
{scope = this.account, index, key_type}: QueryOptions = {}
): Promise<RowType> {
const fieldToIndexMapping = this.getFieldToIndex()
Expand Down
18 changes: 18 additions & 0 deletions test/data/requests/5d3db67a54d5cb0135682b1ad03efaa2560a95ff.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"request": {
"path": "https://eos.greymass.com/v1/chain/get_table_rows",
"params": {
"method": "POST",
"body": "{\"table\":\"global\",\"code\":\"eosio\",\"scope\":\"eosio\",\"limit\":1,\"index_position\":\"primary\",\"key_type\":\"name\",\"json\":false}"
}
},
"status": 200,
"json": {
"rows": [
"000010000000000010270000000008000c000000f40100001400000064000000400d03000a000000f049020064000000100e00005802000080533b00ffff07000a000a00008c34915b000000cc968e630f000000d3fb69400a000000714fa458803b52ce49010600ff8a7a0e000000002983000200000000be2001001da5259d8a05000000e15fd7136f05001500ef04cfcfcf914244f4c4a358"
],
"more": false,
"next_key": ""
},
"text": "{\"rows\":[\"000010000000000010270000000008000c000000f40100001400000064000000400d03000a000000f049020064000000100e00005802000080533b00ffff07000a000a00008c34915b000000cc968e630f000000d3fb69400a000000714fa458803b52ce49010600ff8a7a0e000000002983000200000000be2001001da5259d8a05000000e15fd7136f05001500ef04cfcfcf914244f4c4a358\"],\"more\":false,\"next_key\":\"\"}"
}
8 changes: 8 additions & 0 deletions test/tests/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ContractKit, {Contract, Table, TableCursor} from '$lib'

import {Asset, Int64, Name, Serializer, Struct, TimePoint} from '@greymass/eosio'
import {makeClient} from '@wharfkit/mock-data'
import {EosioGlobalState} from '$test/data/structs/eosio'

const mockClient = makeClient('https://eos.greymass.com')

Expand Down Expand Up @@ -323,6 +324,13 @@ suite('Table', () => {
const row = await producersTable.get('teamgreymass')
assert.instanceOf(row.owner, Name)
})

test('should just get first row without params', async function () {
const table = eosio.table<EosioGlobalState>('global', EosioGlobalState)
const row = await table.get()
assert.instanceOf(row, EosioGlobalState)
assert.instanceOf(row.pervote_bucket, Int64)
})
})

suite('first', () => {
Expand Down