Quick Start
1
Installation
# Install core, table, and Hono adapter
pnpm add @tablecraft/engine @tablecraft/table @tablecraft/adapter-hono
# Install codegen as dev dependency
pnpm add -D @tablecraft/codegen# Install core, table, and Express adapter
pnpm add @tablecraft/engine @tablecraft/table @tablecraft/adapter-express
# Install codegen as dev dependency
pnpm add -D @tablecraft/codegen# Install core, table, and Next.js adapter
pnpm add @tablecraft/engine @tablecraft/table @tablecraft/adapter-next
# Install codegen as dev dependency
pnpm add -D @tablecraft/codegen# Install core, table, and SvelteKit adapter
pnpm add @tablecraft/engine @tablecraft/table @tablecraft/adapter-sveltekit
# Install codegen as dev dependency
pnpm add -D @tablecraft/codegen# Install core, table, and Elysia adapter
pnpm add @tablecraft/engine @tablecraft/table @tablecraft/adapter-elysia
# Install codegen as dev dependency
pnpm add -D @tablecraft/codegen2
Define Your Table
// src/tables/products.ts
import { defineTable } from "@tablecraft/engine";
import { products } from "../db/schema";
export const productsConfig = defineTable(products)
.name("products")
.search("name", "description")
.sort("-createdAt")
.filter("category", "isArchived")
.pageSize(20)
.toConfig();3
Create API Routes
// src/index.ts
import { Hono } from "hono";
import { createHonoApp } from "@tablecraft/adapter-hono";
import { db } from "./db";
import * as schema from "./db/schema";
import { productsConfig } from "./tables/products";
const app = new Hono();
// Mount TableCraft engine at /api/engine
app.route(
"/api/engine",
createHonoApp({
db,
schema,
configs: { products: productsConfig },
}),
);
export default app;// src/server.ts
import express from "express";
import { createExpressMiddleware } from "@tablecraft/adapter-express";
import { db } from "./db";
import * as schema from "./db/schema";
import { productsConfig } from "./tables/products";
const app = express();
// Mount TableCraft engine at /api/engine/:table
// The adapter handles the dynamic :table route automatically
app.use(
"/api/engine",
createExpressMiddleware({
db,
schema,
configs: { products: productsConfig },
}),
);
app.listen(3000);4
6
Create DataTable Page
// src/pages/products-page.tsx
import { DataTable } from "@tablecraft/table";
import { createProductsAdapter, type ProductsRow } from "../generated";
export function ProductsPage() {
// Initialize the adapter with your API base URL
const adapter = createProductsAdapter({
baseUrl: "/api/engine",
});
return (
<DataTable<ProductsRow>
adapter={adapter}
config={{
enableSearch: true,
enableExport: true,
enableColumnResizing: true,
}}
/>
);
}Next Steps
Last updated
Was this helpful?
