Registry / database / baked-orm

baked-orm

JSON →
library0.14.3jsnpmunverified

An ActiveRecord-inspired ORM and migration tool for Bun, version 0.14.3. PostgreSQL-native with auto-generated typed schemas from introspection. Release cadence is monthly. Key differentiators: convention-over-configuration, single `db/schema.ts` generated by migrations that feeds both backend models and frontend hydration, TypeScript-first, supports lazy/eager loading, polymorphic associations, soft deletes, recursive tree traversal, and serialization with `__typename` for frontend hydration.

npm install baked-orm
INSTALL
IMPORT
SIG · BAKED-ORM
B
baked-orm
databasejavascriptv0.14.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Model
import { Model } from 'baked-orm';
import Model from 'baked-orm'; or const { Model } = require('baked-orm');
Model is a named export. CommonJS require is not supported; this package is ESM-only for Bun. Also note that Model is a function that returns a class, not a class itself.
connect
import { connect } from 'baked-orm';
import { connect } from 'baked-orm/connect'; or const connect = require('baked-orm').connect;
connect is a named export from the main package. It reads DATABASE_URL from process.env by default and initializes the connection pool.
belongsTo, hasMany
import { belongsTo, hasMany } from 'baked-orm';
import { belongs_to, has_many } from 'baked-orm';
Association decorators use camelCase (JavaScript conventions), not snake_case (Rails conventions).

Shows defining backend models with associations, connecting to the database, querying with eager loading, and serializing with __typename.

import { connect, Model, hasMany, belongsTo } from 'baked-orm'; // Assuming db/schema.ts exists after migrations import { users, posts } from './db/schema'; import type { Post } from './models/post'; import type { User } from './models/user'; class User extends Model(users, { posts: hasMany<Post>('Post'), }) { static sensitiveFields = ['passwordDigest']; } class Post extends Model(posts, { author: belongsTo<User>('User', { foreignKey: 'userId' }), }) {} await connect(); const user = await User.where({ id: 1 }).includes('posts').first(); const json = user.serialize({ include: { posts: { only: ['id', 'title'] } } }); console.log(json); // { __typename: 'User', id: 1, name: 'Alice', posts: [{ __typename: 'Post', id: 1, title: 'Hello' }] }
Debug
Known issues
breakingMigration-generated schema file is overwritten on every `bun bake db migrate up`. Manual edits to db/schema.ts will be lost.
fix
Do not edit db/schema.ts directly; treat it as generated code. For custom types, use raw SQL or define them in separate TS files.
affects: >=0.0.0
deprecatedThe `bun bake db generate` command for creating migration files uses an interactive prompt that may be deprecated in favor of direct file creation.
fix
Check the CLI help with `bun bake --help` for the latest syntax; consider creating migration files manually.
affects: >=0.14.0
gotchaModel function returns a class — you must use `class MyModel extends Model(table, associations)` not `class MyModel extends Model(table, associations) {}` with non-default export
fix
Wrap the Model call in a class declaration: `class User extends Model(users, { ... }) {}`
affects: >=0.0.0
gotchaAssociation foreign keys default to `tableNameId` (e.g., `userId` from `users` table) but can be overridden with `foreignKey` option.
fix
Specify `foreignKey` in association options if your column name doesn't match the default pattern.
affects: >=0.0.0
gotchaFrontend hydration expects `__typename` in JSON response. If omitted, frontend models cannot reconstruct associations.
fix
Always use `serialize()` method on backend models to include `__typename` automatically.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'baked-orm' or its corresponding type declarations.
Package not installed or TypeScript not configured to find node_modules.
fix
Run `bun add baked-orm` and ensure tsconfig.json includes `"moduleResolution": "bundler"` or `"node"`.
Error: connect ECONNREFUSED ::1:5432
PostgreSQL not running or DATABASE_URL incorrect.
fix
Ensure PostgreSQL is running and DATABASE_URL is set correctly in .env, e.g., `DATABASE_URL=postgres://user:pass@localhost:5432/mydb`.
TypeError: Class extends value undefined is not a constructor or null
Model import is default instead of named, or Model is not a function (e.g., wrong import).
fix
Use `import { Model } from 'baked-orm'` instead of default import.
error: No schema file found at ./db/schema.ts. Did you run migrations?
Migrations have not been run or the schema file is missing.
fix
Run `bun bake db migrate up` to generate db/schema.ts from migration files.
Property 'serialize' does not exist on type 'User'.
Calling serialize on a plain object instead of a model instance, or TypeScript doesn't recognize the method because Model returns a generic class.
fix
Ensure you are calling serialize on an instance of a class that extends Model(table, association).
Upgrade
Version history
0.14.3latest on npm
Audit
Dependencies
typescriptrequiredRequired as a peer dependency for type generation and TypeScript usage
Agent activity
10 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources