Skip to content

Latest commit

 

History

History

database

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

@thailand-election-2023/database

NocoDB fetching utility

Set up

Add this package to the dependencies in the app's package.json

{
	"dependencies": {
		"@thailand-election-2023/database": "*"
	}
}

Usage

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();

Projects and tables

The following projects and tables are available

Fetch functions

  1. .fetch()

Fetch the first page. Return list of rows and pageInfo for pagination.

function fetch(query?: QueryParams): PublicViewResponse;
  1. .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',
});