Skip to content
esc

Search pages and sections. Try a tool name, an error code, a route.

↑↓ navigate↵ openesc close

SDK · @manybases/js

@manybases/js — rows

Read and write the rows of a table. mb.from("habits") returns five methods; every one returns { data, error } and never throws.

MethodCallsReturns
list(query?)GET /v1/tables/:t/rows{ data: Row[], cursor, error }
get(id)GET /v1/tables/:t/rows/:id{ data: Row, error }
insert(row | rows, { idempotencyKey? })POST /v1/tables/:t/rowsthe created row, or rows
update(id, changes)PATCH /v1/tables/:t/rows/:idthe complete row
remove(id)DELETE /v1/tables/:t/rows/:id{ id, deleted: true }

Listing and filtering#

ts
import { filters } from "@manybases/js";

const { data, cursor, error } = await mb.from("habits").list({
  filters: { status: filters.in(["todo", "doing"]), score: [filters.gte(1), filters.lte(9)] },
  order: "created_at.desc",
  limit: 50,
});
  • filters composes the wire form of the nine operators: eq, neq, gt, gte, lt, lte, like (* is the wildcard, case-insensitive), in (rendered as in.(todo,doing)), is ("null", "not_null", "true", "false"). A plain string such as "eq.true" works too.
  • Several filters combine with AND; an array of values on the same column means AND. There is no OR.
  • order is one column, column.asc or column.desc; the default is created_at.desc.
  • limit defaults to 50 and is capped at 200 by the API, which refuses beyond it rather than truncating. Pass the cursor of a page back as { cursor } to read the next one; cursor: null means the last page.
  • order, limit and cursor are reserved parameter names on the wire: filtering on a column with one of those names is refused before the request leaves, with the reason.

Writing#

ts
const { data, error } = await mb.from("habits").insert({ name: "Run" });
  • insert accepts one object or an array of up to 100. The API fills id, owner_id (the signed-in user), created_at and updated_at; a body carrying id or owner_id is refused.
  • update sends only the columns you pass and returns the complete row.
  • idempotencyKey is opt-in on insert: with it, a retry within 24 hours returns the first response (replayed: true) instead of creating a second row. For a visitor with no session the key only de-duplicates — a replay answers 409.

What the preset decides#

Which rows a call sees and which writes it may make depend on the table's access preset and on whether the client holds a session. A row the caller may not see answers 404; a write the caller may see but not make answers 403; an anonymous read of a non-public table answers 401. With an sk_ on the server, the matrix does not apply and rows are created with owner_id: null.