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.
| Method | Calls | Returns |
|---|---|---|
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/rows | the created row, or rows |
update(id, changes) | PATCH /v1/tables/:t/rows/:id | the 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,
});filterscomposes the wire form of the nine operators:eq,neq,gt,gte,lt,lte,like(*is the wildcard, case-insensitive),in(rendered asin.(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.
orderis one column,column.ascorcolumn.desc; the default iscreated_at.desc.limitdefaults to 50 and is capped at 200 by the API, which refuses beyond it rather than truncating. Pass thecursorof a page back as{ cursor }to read the next one;cursor: nullmeans the last page.order,limitandcursorare 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" });insertaccepts one object or an array of up to 100. The API fillsid,owner_id(the signed-in user),created_atandupdated_at; a body carryingidorowner_idis refused.updatesends only the columns you pass and returns the complete row.idempotencyKeyis opt-in oninsert: 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 answers409.
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.
