Skip to content

@meshqljs/postgres (@meshql/postgres)

Postgres helper for MeshQL. Builds parameterised SELECT statements from a join plan; you supply the connection.

Terminal window
npm install @meshqljs/postgres @meshqljs/core pg
npm i pg
Terminal window
npx jsr add @meshql/postgres @meshql/core
npm i pg

Published on npm as @meshqljs/postgres and JSR as @meshql/postgres.

import { createMesh, type MeshSchema } from "@meshqljs/core";
import { buildSelectSql } from "@meshqljs/postgres";
import { Pool } from "pg";
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const schema: MeshSchema = { /* … */ };
const mesh = createMesh(schema);
mesh.resolve("user", async (plan) => {
const { sql, params } = buildSelectSql(plan, schema);
const result = await pool.query(sql, params);
return result.rows;
});
import { createMesh, type MeshSchema } from "@meshql/core";
import { buildSelectSql } from "@meshql/postgres";
import { Pool } from "pg";
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const schema: MeshSchema = { /* … */ };
const mesh = createMesh(schema);
mesh.resolve("user", async (plan) => {
const { sql, params } = buildSelectSql(plan, schema);
const result = await pool.query(sql, params);
return result.rows;
});

JSR imports: @meshql/core, @meshql/postgres.

See also @meshql/sqlite.