.agents/skills/bknd-create-entity/SKILL.md
Use when creating a new entity/table in Bknd. Covers entity definition with em() and entity(), primary key configuration, field basics, UI creation via admin panel, and code-first approach with type safety.
npx skillsauth add cameronapak/cultivate-fellowship bknd-create-entityInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Create a new entity (database table) in Bknd. Entities are the foundation of your data model.
npx bknd create or existing project)bknd package installednpx bknd runhttp://localhost:1337 (default port)posts, users, comments)After entity creation, you're taken to the field editor:
first_name, created_at)Click Sync Database to apply changes to the actual database.
import { em, entity, text, number, boolean, date, enumm, json } from "bknd";
Create your entity within em():
const schema = em({
posts: entity("posts", {
title: text().required(),
content: text(),
published: boolean({ default_value: false }),
view_count: number({ default_value: 0 }),
}),
});
Default is auto-incrementing integer. For UUID:
const schema = em({
posts: entity("posts", {
title: text().required(),
}, {
primary_format: "uuid",
}),
});
Enable type-safe queries:
const schema = em({
posts: entity("posts", {
title: text().required(),
content: text(),
}),
});
// Extract and declare types
type Database = (typeof schema)["DB"];
declare module "bknd" {
interface DB extends Database {}
}
import { App } from "bknd";
const app = new App({
data: schema,
// ... other config
});
import { App, em, entity, text, number, boolean, date } from "bknd";
const schema = em({
users: entity("users", {
email: text().required().unique(),
name: text(),
active: boolean({ default_value: true }),
}),
posts: entity("posts", {
title: text().required(),
content: text(),
published: boolean({ default_value: false }),
published_at: date(),
}),
});
type Database = (typeof schema)["DB"];
declare module "bknd" {
interface DB extends Database {}
}
const app = new App({
data: schema,
});
export default app;
| Convention | Example | Notes |
|------------|---------|-------|
| Plural | users, posts | NOT user, post |
| Lowercase | blog_posts | NOT BlogPosts |
| snake_case | user_profiles | NOT userProfiles |
Every entity automatically includes:
| Field | Type | Description |
|-------|------|-------------|
| id | integer/uuid | Primary key (format depends on config) |
Note: For created_at/updated_at, use the timestamps plugin or add manually:
entity("posts", {
title: text().required(),
created_at: date({ default_value: "now" }),
updated_at: date(),
})
Error: Entity "posts" already defined
Fix: Each entity name must be unique within em(). Check for duplicates.
Error: Invalid entity name
Fix: Use lowercase letters, numbers, and underscores only. Must start with letter.
// ✅ Valid
entity("posts", { ... })
entity("user_profiles", { ... })
entity("blog_posts_2024", { ... })
// ❌ Invalid
entity("Posts", { ... }) // No uppercase
entity("2024_posts", { ... }) // Can't start with number
entity("post-items", { ... }) // No hyphens
Problem: Created entity in code but table doesn't exist in database.
Fix: Ensure you're using the schema in your App config:
const app = new App({
data: schema, // Must pass schema here
});
Then restart the server - Bknd auto-syncs on startup.
Problem: api.data.readMany("posts", ...) has no type hints.
Fix: Add type declaration:
type Database = (typeof schema)["DB"];
declare module "bknd" {
interface DB extends Database {}
}
// After app starts, verify entity exists
const api = app.getApi();
const result = await api.data.readMany("posts");
console.log(result); // Should return { data: [] } for empty entity
npx bknd debug routes
# Should show /api/data/posts endpoints
DO:
primary_format: "uuid" for distributed systemsDON'T:
user instead of users)development
Use btca (Better Context App) to efficiently query and learn from the bknd backend framework. Use when working with bknd for (1) Understanding data module and schema definitions, (2) Implementing authentication and authorization, (3) Setting up media file handling, (4) Configuring adapters (Node, Cloudflare, etc.), (5) Learning from bknd source code and examples, (6) Debugging bknd-specific issues
development
Use when configuring webhook integrations in Bknd. Covers receiving incoming webhooks via HTTP triggers, sending outgoing webhooks with FetchTask, event-triggered webhooks on data changes, signature verification, retry patterns, and async processing.
development
Use when encountering Bknd errors, getting error messages, something not working, or needing quick fixes. Covers error code reference, quick solutions, and common mistake patterns.
tools
Use when writing tests for Bknd applications, setting up test infrastructure, creating unit/integration tests, or testing API endpoints. Covers in-memory database setup, test helpers, mocking, and test patterns.