Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.ub.bitbros.in/llms.txt

Use this file to discover all available pages before exploring further.

Access database methods via client.db. Collections must be created in the urBackend Dashboard before you can interact with them. Methods that return documents accept a generic type parameter T (extending DocumentData) so returned documents are fully typed. Methods like delete() return status objects and do not accept T.

Row-Level Security (RLS)

If a collection has RLS enabled, token requirements depend on mode:
  • public-read: token is required for writes (insert, update, patch, delete), optional for reads.
  • private: token is required for both reads and writes when using a publishable key (pk_live_...).
Example pattern:
const { accessToken } = await client.auth.login({ ... });
await client.db.insert('posts', { content: 'Hello' }, accessToken);

getAll

Fetch documents from a collection with optional filtering, sorting, and pagination.
getAll<T extends DocumentData>(collection: string, params?: QueryParams, token?: string): Promise<T[]>
Query Parameters (params)
ParameterTypeDescription
filterobjectFilter by field suffixes (e.g. { age_gt: 18 }).
sortstringSort order (e.g. "createdAt:desc").
limitnumberMax documents to return (max 100).
pagenumberPage number for pagination.
populatestring | string[]Expand Reference fields into full objects.
Example
const products = await client.db.getAll<Product>('products', {
  filter: { category: 'electronics', price_lt: 500 },
  sort: 'price:asc',
  limit: 20
});

// For private-mode reads with pk_live_..., pass the user token:
const privateItems = await client.db.getAll<Product>('products', { limit: 10 }, accessToken);

getOne

Fetch a single document by its ID.
getOne<T extends DocumentData>(collection: string, id: string, options?: { populate?: string | string[] }, token?: string): Promise<T>
Example
const product = await client.db.getOne<Product>('products', 'id_123', { populate: 'vendor' });

count

Count documents in a collection.
count(collection: string, params?: QueryParams, token?: string): Promise<number>
Use token for private-mode reads when using publishable keys.

insert

Insert a new document. If RLS is enabled, the token parameter is required.
insert<T extends DocumentData>(collection: string, data: Record<string, unknown>, token?: string): Promise<T>

update

Update an existing document by its ID. This performs a full replacement of the document fields.
update<T extends DocumentData>(collection: string, id: string, data: Record<string, unknown>, token?: string): Promise<T>

patch

Partially update a document. Only the fields provided in data will be modified.
patch<T extends DocumentData>(collection: string, id: string, data: Record<string, unknown>, token?: string): Promise<T>
Example
// Only updates the price, leaves other fields unchanged
await client.db.patch('products', 'id_123', { price: 45 });

delete

Delete a document by its ID.
delete(collection: string, id: string, token?: string): Promise<{ deleted: boolean }>

TypeScript Support

Define your interfaces to get full IDE autocomplete:
interface BlogPost {
  _id: string;
  title: string;
  author: string;
}

const posts = await client.db.getAll<BlogPost>('posts');
posts[0].title; // typed as string