NocoDB fetching utility
Add this package to the dependencies in the app's package.json
{
"dependencies": {
"@thailand-election-2023/database": "*"
}
}
Import project (according to NocoDB) from the package and call fetch or fetchAll from the table
import { TheyWorkForUs } from '@thailand-election-2023/database';
// Project = TheyWorkForUs, Table = People
const peopleOnTheFirstPage = await TheyWorkForUs.People.fetch();
const everyPeople = await TheyWorkForUs.People.fetchAll();
The following projects and tables are available
- TheyWorkForUs
- Parties
- People
- Note that People will sub-query party name from PeoplePartyHistory table by default. No need to fetch that seperately.
- VoteLog
- PeopleVotes
- Policies
.fetch()
Fetch the first page. Return list
of rows and pageInfo
for pagination.
function fetch(query?: QueryParams): PublicViewResponse;
.fetchAll()
Fetch all rows, return the list of object for each row
function fetchAll(
query?: Omit<QueryParams, 'limit' | 'offset'>
): Record<string, unknown>[];
Type definition can be found in nocodb.ts
QueryParams
allow us to select only nessesary field, filter row, sort, sub query etc. See more in NocoDB documentation
Example of subquery in People table (this is default behavior for People table)
TheyWorkForUs.People.fetch({
// Get Parties,EstablishedDate column from PeoplePartyHistory table
'nested[PeoplePartyHistory][fields]': 'Parties,EstablishedDate',
});