Server and data examplesORM examples
Kysely example
Answer a server grid from a Kysely table with the query layer: one column map and one route handler.
A server grid sends its spec (sorts, filters, searchText) and a row range (start, end) to your route. The query layer checks the request and runs it with Kysely. Kysely has no schema at run time, so you write the column map with defineColumnMap. This route serves a users table.
pnpm dlx shadcn@latest add @gridcn/data-grid-server-query-kysely
The route
Name the table and the dialect, "pg" or "sqlite". Every column reference is qualified with the table name:
import { defineColumnMap } from "@/components/data-grid-server-query/data-grid-server-query";
import { createKyselyGridQuery } from "@/components/data-grid-server-query-kysely/data-grid-server-query-kysely";
import { db } from "./db";
const columns = defineColumnMap({
id: { type: "number", numeric: "int8", primaryKey: true },
name: { type: "text", searchable: true },
email: { type: "text", searchable: true },
role: { type: "select", choices: ["admin", "member"] },
createdAt: { type: "date", time: true },
});
export const usersQuery = createKyselyGridQuery({
db, table: "users", dialect: "pg", columns,
});import { handleGridRequest } from "@/components/data-grid-server-query/data-grid-server-query";
import { usersQuery } from "./users-query";
export const POST = (req: Request) =>
handleGridRequest(req, usersQuery.fetchRows);The client is the one in the Drizzle example.