Hono
Use MeshQL with Hono via meshHonoRoutes. Works on Node, Bun, Deno, and edge runtimes.
Prerequisites
Section titled “Prerequisites”- Hono 4+
- Node.js 22+, Bun 1+, or Deno 2+
Install (Node / Bun)
Section titled “Install (Node / Bun)”npm:
npm install meshql-core meshql-httpnpm i honoJSR:
npx jsr add @meshql/core @meshql/httpnpm i hono# orbunx jsr add @meshql/core @meshql/http && bun add honoServer
Section titled “Server”import { Hono } from "hono";import { createMesh, buildSelectSql, type MeshSchema } from "@meshql/core";import { meshHonoRoutes } from "@meshql/http/hono";
const schema: MeshSchema = { entities: { user: { type: {} as { id: number; name: string }, fields: ["id", "name"], table: "users" }, token: { type: {} as { accessToken: string }, fields: ["accessToken"], table: "tokens", columns: { accessToken: "access_token" }, }, }, joins: { "user.tokens": { entity: "token", on: "tokens.user_id = users.id", type: "many", }, },};
const mesh = createMesh(schema);
mesh.resolve("user", async (plan) => { const { sql, params } = buildSelectSql(plan, schema); return [{ user_id: 1, user_name: "Ada", tokens_accessToken: "tok_abc" }];});
const app = new Hono();app.route("/", meshHonoRoutes(mesh, { basePath: "/mesh" }));
export default app;Run (Node with @hono/node-server)
Section titled “Run (Node with @hono/node-server)”npm i @hono/node-serverimport { serve } from "@hono/node-server";import app from "./app.js";
serve({ fetch: app.fetch, port: 3001 });Client test
Section titled “Client test”import { createClient } from "@meshql/client";
const client = createClient({ url: "http://localhost:3001/mesh" });const user = await client.query( { user: { id: true, name: true, tokens: { accessToken: true } } }, { entityId: "1" },);