Skip to content

Commit

Permalink
enhancement: renamed where to query and find to get
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Jul 6, 2023
1 parent 783cbdf commit 5ec10e7
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 53 deletions.
40 changes: 20 additions & 20 deletions contracts/decentiumorg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export namespace _Decentiumorg {
export namespace tables {
export class blogs {
static fieldToIndex = {author: {type: 'name', index_position: 'primary'}}
static where(
static query(
{limit = 10},
queryParams: _Decentiumorg.types.blogsQueryParams,
client: APIClient
Expand All @@ -183,9 +183,9 @@ export namespace _Decentiumorg {
rowType: _Decentiumorg.types.Blog_row,
fieldToIndex: blogs.fieldToIndex,
})
return blogsTable.where(queryParams)
return blogsTable.query(queryParams)
}
static find(
static get(
queryParams: _Decentiumorg.types.blogsQueryParams,
client: APIClient
): Promise<_Decentiumorg.types.Blog_row> {
Expand All @@ -196,7 +196,7 @@ export namespace _Decentiumorg {
rowType: _Decentiumorg.types.Blog_row,
fieldToIndex: blogs.fieldToIndex,
})
return blogsTable.find(queryParams)
return blogsTable.get(queryParams)
}
static all(
queryParams: _Decentiumorg.types.blogsQueryParams,
Expand All @@ -218,7 +218,7 @@ export namespace _Decentiumorg {
from: {type: 'uint128', index_position: 'secondary'},
to: {type: 'uint128', index_position: 'tertiary'},
}
static where(
static query(
{limit = 10},
queryParams: _Decentiumorg.types.linksQueryParams,
client: APIClient
Expand All @@ -230,9 +230,9 @@ export namespace _Decentiumorg {
rowType: _Decentiumorg.types.Link_row,
fieldToIndex: links.fieldToIndex,
})
return linksTable.where(queryParams)
return linksTable.query(queryParams)
}
static find(
static get(
queryParams: _Decentiumorg.types.linksQueryParams,
client: APIClient
): Promise<_Decentiumorg.types.Link_row> {
Expand All @@ -243,7 +243,7 @@ export namespace _Decentiumorg {
rowType: _Decentiumorg.types.Link_row,
fieldToIndex: links.fieldToIndex,
})
return linksTable.find(queryParams)
return linksTable.get(queryParams)
}
static all(
queryParams: _Decentiumorg.types.linksQueryParams,
Expand All @@ -264,7 +264,7 @@ export namespace _Decentiumorg {
slug: {type: 'name', index_position: 'primary'},
updated: {type: 'uint64', index_position: 'secondary'},
}
static where(
static query(
{limit = 10},
queryParams: _Decentiumorg.types.postsQueryParams,
client: APIClient
Expand All @@ -276,9 +276,9 @@ export namespace _Decentiumorg {
rowType: _Decentiumorg.types.Post_row,
fieldToIndex: posts.fieldToIndex,
})
return postsTable.where(queryParams)
return postsTable.query(queryParams)
}
static find(
static get(
queryParams: _Decentiumorg.types.postsQueryParams,
client: APIClient
): Promise<_Decentiumorg.types.Post_row> {
Expand All @@ -289,7 +289,7 @@ export namespace _Decentiumorg {
rowType: _Decentiumorg.types.Post_row,
fieldToIndex: posts.fieldToIndex,
})
return postsTable.find(queryParams)
return postsTable.get(queryParams)
}
static all(
queryParams: _Decentiumorg.types.postsQueryParams,
Expand All @@ -307,7 +307,7 @@ export namespace _Decentiumorg {
}
export class state {
static fieldToIndex = {}
static where(
static query(
{limit = 10},
queryParams: _Decentiumorg.types.stateQueryParams,
client: APIClient
Expand All @@ -319,9 +319,9 @@ export namespace _Decentiumorg {
rowType: _Decentiumorg.types.State,
fieldToIndex: state.fieldToIndex,
})
return stateTable.where(queryParams)
return stateTable.query(queryParams)
}
static find(
static get(
queryParams: _Decentiumorg.types.stateQueryParams,
client: APIClient
): Promise<_Decentiumorg.types.State> {
Expand All @@ -332,7 +332,7 @@ export namespace _Decentiumorg {
rowType: _Decentiumorg.types.State,
fieldToIndex: state.fieldToIndex,
})
return stateTable.find(queryParams)
return stateTable.get(queryParams)
}
static all(
queryParams: _Decentiumorg.types.stateQueryParams,
Expand All @@ -355,7 +355,7 @@ export namespace _Decentiumorg {
cscore: {type: 'uint128', index_position: 'tertiary'},
permlink: {type: 'uint128', index_position: 'fourth'},
}
static where(
static query(
{limit = 10},
queryParams: _Decentiumorg.types.trendingQueryParams,
client: APIClient
Expand All @@ -367,9 +367,9 @@ export namespace _Decentiumorg {
rowType: _Decentiumorg.types.Trending_row,
fieldToIndex: trending.fieldToIndex,
})
return trendingTable.where(queryParams)
return trendingTable.query(queryParams)
}
static find(
static get(
queryParams: _Decentiumorg.types.trendingQueryParams,
client: APIClient
): Promise<_Decentiumorg.types.Trending_row> {
Expand All @@ -380,7 +380,7 @@ export namespace _Decentiumorg {
rowType: _Decentiumorg.types.Trending_row,
fieldToIndex: trending.fieldToIndex,
})
return trendingTable.find(queryParams)
return trendingTable.get(queryParams)
}
static all(
queryParams: _Decentiumorg.types.trendingQueryParams,
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {capitalize} from '../utils'

export async function generateTableClass(contractName, namespaceName, table, abi) {
const tableName = table.name
const struct = abi.structs.find((struct) => struct.name === table.type)
const struct = abi.structs.get((struct) => struct.name === table.type)
const members: ts.ClassElement[] = []
const rowType = `${namespaceName}.types.${capitalize(struct.name)}`

Expand Down
2 changes: 1 addition & 1 deletion src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class Contract {
async getTable(name: NameType): Promise<Table> {
const tables = await this.getTables()

const table = tables.find((table) => table.name.equals(name))
const table = tables.get((table) => table.name.equals(name))

if (!table) {
throw new Error(`No table found with name ${name}`)
Expand Down
2 changes: 1 addition & 1 deletion src/contract/table-cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class TableCursor<TableRow> {
*
* @returns A new cursor with updated parameters.
*/
where(query: WhereQuery, queryOptions?: QueryOptions) {
query(query: WhereQuery, queryOptions?: QueryOptions) {
return new TableCursor({
table: this.table,
tableParams: {
Expand Down
4 changes: 2 additions & 2 deletions src/contract/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class Table<TableRow extends ABISerializableConstructor = ABISerializable
* - `limit`: Maximum number of rows to return.
* @returns {TableCursor<TableRow>} Promise resolving to a `TableCursor` of the filtered table rows.
*/
where(
query(
query: WhereQuery,
{limit = 10, scope = this.contract.account, index, index_type}: WhereQueryOptions = {}
): TableCursor<TableRow> {
Expand Down Expand Up @@ -131,7 +131,7 @@ export class Table<TableRow extends ABISerializableConstructor = ABISerializable
* Each key-value pair in the queryParams object corresponds to a field and its expected value in the table.
* @returns {Promise<TableRow>} Promise resolving to a single table row.
*/
async find(query, queryOptions?: QueryOptions): Promise<TableRow> {
async get(query, queryOptions?: QueryOptions): Promise<TableRow> {
if (!query) {
throw new Error('Index value must be provided')
}
Expand Down
8 changes: 4 additions & 4 deletions src/example-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export namespace _Blog {
},
}

static where(
static query(
queryParams: _Blog.types.UsersWhereQueryParams,
{limit = 10} = {},
client: APIClient
Expand All @@ -60,10 +60,10 @@ export namespace _Blog {
fieldToIndex: Users.fieldToIndex,
})

return usersTable.where(queryParams, {limit})
return usersTable.query(queryParams, {limit})
}

static async find(
static async get(
queryParams: _Blog.types.UsersFindQueryParams,
client: APIClient
): Promise<_Blog.types.UsersRow> {
Expand All @@ -74,7 +74,7 @@ export namespace _Blog {
fieldToIndex: Users.fieldToIndex,
})

return usersTable.find(queryParams)
return usersTable.get(queryParams)
}

static first(limit, client): TableCursor<_Blog.types.UsersRow> {
Expand Down
16 changes: 8 additions & 8 deletions test/codegen-samples/rewards.gm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export namespace _RewardsGm {
export namespace tables {
export class config {
static fieldToIndex = {}
static where(
static query(
queryParams: _RewardsGm.types.ConfigWhereQueryParams,
getTableRowsOptions: GetTableRowsOptions,
client: APIClient
Expand All @@ -76,9 +76,9 @@ export namespace _RewardsGm {
rowType: _RewardsGm.types.Config,
fieldToIndex: config.fieldToIndex,
})
return configTable.where(queryParams, getTableRowsOptions)
return configTable.query(queryParams, getTableRowsOptions)
}
static find(
static get(
queryParams: _RewardsGm.types.ConfigFindQueryParams,
client: APIClient
): Promise<_RewardsGm.types.Config> {
Expand All @@ -88,7 +88,7 @@ export namespace _RewardsGm {
rowType: _RewardsGm.types.Config,
fieldToIndex: config.fieldToIndex,
})
return configTable.find(queryParams)
return configTable.get(queryParams)
}
static first(limit: number, client: APIClient): TableCursor<_RewardsGm.types.Config> {
const configTable = Table.from({
Expand All @@ -102,7 +102,7 @@ export namespace _RewardsGm {
}
export class users {
static fieldToIndex = {}
static where(
static query(
queryParams: _RewardsGm.types.UsersWhereQueryParams,
getTableRowsOptions: GetTableRowsOptions,
client: APIClient
Expand All @@ -113,9 +113,9 @@ export namespace _RewardsGm {
rowType: _RewardsGm.types.User_row,
fieldToIndex: users.fieldToIndex,
})
return usersTable.where(queryParams, getTableRowsOptions)
return usersTable.query(queryParams, getTableRowsOptions)
}
static find(
static get(
queryParams: _RewardsGm.types.UsersFindQueryParams,
client: APIClient
): Promise<_RewardsGm.types.User_row> {
Expand All @@ -125,7 +125,7 @@ export namespace _RewardsGm {
rowType: _RewardsGm.types.User_row,
fieldToIndex: users.fieldToIndex,
})
return usersTable.find(queryParams)
return usersTable.get(queryParams)
}
static first(limit: number, client: APIClient): TableCursor<_RewardsGm.types.User_row> {
const usersTable = Table.from({
Expand Down
16 changes: 8 additions & 8 deletions test/data/contracts/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
// export namespace tables {
// export class accounts {
// static fieldToIndex = {balance: {type: 'balance', index_position: 'primary'}}
// static where(
// static query(
// queryParams: _EosioToken.types.AccountsWhereQueryParams,
// getTableRowsOptions: GetTableRowsOptions,
// client: APIClient
Expand All @@ -92,9 +92,9 @@
// rowType: _EosioToken.types.Account,
// fieldToIndex: accounts.fieldToIndex,
// })
// return accountsTable.where(queryParams, getTableRowsOptions)
// return accountsTable.query(queryParams, getTableRowsOptions)
// }
// static find(
// static get(
// queryParams: _EosioToken.types.AccountsFindQueryParams,
// client: APIClient
// ): Promise<_EosioToken.types.Account> {
Expand All @@ -104,7 +104,7 @@
// rowType: _EosioToken.types.Account,
// fieldToIndex: accounts.fieldToIndex,
// })
// return accountsTable.find(queryParams)
// return accountsTable.get(queryParams)
// }
// static first(limit: number, client: APIClient): TableCursor<_EosioToken.types.Account> {
// const accountsTable = Table.from({
Expand Down Expand Up @@ -136,7 +136,7 @@
// }
// export class stat {
// static fieldToIndex = {supply: {type: 'supply', index_position: 'primary'}}
// static where(
// static query(
// queryParams: _EosioToken.types.StatWhereQueryParams,
// getTableRowsOptions: GetTableRowsOptions,
// client: APIClient
Expand All @@ -147,9 +147,9 @@
// rowType: _EosioToken.types.Currency_stats,
// fieldToIndex: stat.fieldToIndex,
// })
// return statTable.where(queryParams, getTableRowsOptions)
// return statTable.query(queryParams, getTableRowsOptions)
// }
// static find(
// static get(
// queryParams: _EosioToken.types.StatFindQueryParams,
// client: APIClient
// ): Promise<_EosioToken.types.Currency_stats> {
Expand All @@ -159,7 +159,7 @@
// rowType: _EosioToken.types.Currency_stats,
// fieldToIndex: stat.fieldToIndex,
// })
// return statTable.find(queryParams)
// return statTable.get(queryParams)
// }
// static first(
// limit: number,
Expand Down
4 changes: 2 additions & 2 deletions test/tests/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ suite('codegen', function () {
suite('where', function () {
test('returns a cursor that lets you filter rows', async function () {
const rows = await _RewardsGm.tables.users
.where({from: 'dafuga.gm', to: 'tony.gm'}, {}, client)
.query({from: 'dafuga.gm', to: 'tony.gm'}, {}, client)
.all()

assert.equal(rows.length, 6)
Expand All @@ -67,7 +67,7 @@ suite('codegen', function () {

suite('find', function () {
test('returns a single row', async function () {
const row = await _RewardsGm.tables.users.find('dafuga.gm', {}, client)
const row = await _RewardsGm.tables.users.get('dafuga.gm', {}, client)

assert.equal(String(row.account), 'dafuga.gm')
})
Expand Down
Loading

0 comments on commit 5ec10e7

Please sign in to comment.