Quick start

This walkthrough starts with local execution so you can see the query model without configuring a server. The same query value can then be sent to a RAQ catalog endpoint.

Install the query package

pnpm add @raquery/query

Inside this repository, install the workspace and run the checked example:

pnpm install
pnpm --filter raq-quickstart start

Build a query

import {
  evaluate,
  limit,
  order,
  project,
  relation,
  where,
} from "@raquery/query";

const featuredProducts = limit(
  order(
    project(
      where(relation("products"), "price > 100"),
      ["id", "name", "price"]
    ),
    "price desc"
  ),
  2
);

The result is a serializable relational AST. It does not fetch data when you construct it.

Evaluate it locally

const rows = evaluate(featuredProducts, {
  products: [
    { id: 1, name: "Canvas Weekender", price: 129 },
    { id: 2, name: "Travel Pouch", price: 32 },
    { id: 3, name: "Utility Jacket", price: 188 },
  ],
});

rows contains the jacket followed by the weekender. The checked implementation is in examples/quickstart.

Run the same query remotely

When an application exposes a products catalog endpoint:

import { runQuery } from "@raquery/query";

const result = await runQuery("/products", featuredProducts);

console.log(result.rows);
console.log(result.sql);
console.log(result.params);

The server resolves the public products relation, composes application-owned constraints, validates the resulting tree, and compiles it to parameterized SQL.

Next, read Query composition to understand why catalog relations are different from exposing database tables.