Skip to main content

TableQuery

TableQuery builds table-scoped selections and mutations. Query builder methods mutate the builder and return it.

Filter Rows

Add a predicate. Calls are combined with AND.

db.table("workers").where("id", "=", "w_001");
db.table("workers").where({ email: "ada@example.com" });
db.table("workers").where("email", "=", null);
db.table("workers").where("email IS NOT NULL");

Supported comparison operators are =, !=, <>, >, >=, <, and <=. Use IS NULL or IS NOT NULL in SQL text when filtering null values.

Select Columns

Choose projected columns.

db.table("workers").select(["id", "email"]).all();
db.table("workers").select("*").all();

Join Tables

Join a foreign-key relationship by relationship name.

db.table("sessions").join("worker").all();

Sort Rows

Sort results by a column.

db.table("workers").orderBy("id", "desc").all();

Limit Rows

Restrict result count.

db.table("workers").limit(10).all();

Read All Rows

Execute the select query and return rows.

const rows = db.table("workers").all();

Read First Row

Return the first matching row or no value.

const worker = db.table("workers").where("id", "=", "w_001").first();

Insert Rows

Insert one row or many rows.

db.table("workers").insert({ id: "w_001", name: "Ada", email: "ada@example.com" });
db.table("workers").insert([
{ id: "w_002", name: "Grace", email: "grace@example.com" }
]);

Update Rows

Update matching rows.

db.table("workers").where("id", "=", "w_001").update({ email: "ada@csdb.dev" });

Delete Rows

Delete matching rows.

db.table("workers").where("id", "=", "w_001").delete();

Find By Primary Key

Find a row using the table's primary key index.

const worker = db.table("workers").byPrimaryKey("w_001");
const line = db.table("invoice_lines").byPrimaryKey(["inv_001", "line_1"]);