Skip to main content

Overview

There are 7 methods you can use to interact with the database. They are used in conjunction with the db property from the useBasic() hook, and are appended in the format of db.collection('tablename').METHOD().

Methods

.get()

.get(id: string)
Promise<T | null>
Fetch a single item from the table by its ID. Returns null if not found.

.getAll()

.getAll()
Promise<T[]>
Fetch all items from the table. Returns an empty array if no items exist.
In the React / Next.js client SDK (sync or remote mode), .getAll() loads items for that collection and .filter() applies your predicate on the client after fetch. For server-side query parameters on HTTP, use the REST API filtering guide against the PDS endpoints instead.

.add()

.add(data: Omit<T, 'id'>)
Promise<T>
Adds a new item to the table. The id is automatically generated by the server. Returns the created object with its new ID.

.put()

.put(data: T)
Promise<T>
Upsert (insert or replace) an item. The data object must include an id field. If an item with that ID exists, it will be replaced entirely. If not, a new item will be created. Returns the upserted object.

.update()

.update(id: string, data: Partial<T>)
Promise<T | null>
Partially update an existing item by ID. Only the fields you provide will be updated—other fields remain unchanged. Returns the updated object, or null if the item was not found.

.delete()

.delete(id: string)
Promise<boolean>
Deletes an item from the table by ID. Returns true if deleted, false if the item was not found.

.filter()

.filter(fn: (item: T) => boolean)
Promise<T[]>
Filter records using a predicate function. This fetches all records and filters client-side. Returns an array of matching objects.

Examples

Read items

There are 2 ways to read items from the database:
  • .get('ID_OF_ITEM'): Fetches a single item by ID
  • .getAll(): Fetches all items from the table
App.tsx

Add new item

App.tsx

Put (upsert) item

App.tsx

Update item

App.tsx

Delete item

App.tsx

Filter items

App.tsx

TypeScript Support

The collection method supports generics for type-safe database operations:
App.tsx