@guren/orm

中文文档
2.16.2发布于 2026/11/16MITTypeScriptES Module构建来源已验证近 30 天下载 9603

Eloquent-style models for the Guren framework, on Drizzle ORM: PostgreSQL, MySQL, SQLite and Cloudflare D1.

原始使用文档
文档目录7 节
  1. Installation
  2. Defining a model
  3. Querying
  4. Mass assignment
  5. Dialect subpaths
  6. Documentation
  7. License

@guren/orm

Eloquent-style models for Guren, a Bun-first fullstack TypeScript framework with Laravel-style conventions. A Model API over Drizzle ORM, with PostgreSQL, MySQL, SQLite, and Cloudflare D1 behind one interface.

Installation

Application code gets the Model API from @guren/core, which re-exports it:

bun add @guren/core

Starting a new app? Scaffold one and pick a database:

bunx create-guren-app my-app

Defining a model

Tables are declared with Drizzle's schema DSL, re-exported per dialect so the app pins one copy of drizzle-orm:

// db/schema.ts
import { sqliteTable, integer, text } from '@guren/orm/drizzle/sqlite'

export const posts = sqliteTable('posts', {
  id: integer('id').primaryKey({ autoIncrement: true }),
  title: text('title').notNull(),
  body: text('body').notNull(),
  published: integer('published', { mode: 'boolean' }).notNull().default(false),
  createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
})
// app/Models/Post.ts
import { defineModel } from '@guren/core'
import { posts } from '@/db/schema'

export class Post extends defineModel(posts) {
  static fillable = ['title', 'body']
}

Querying

const post = await Post.find(1)                    // null when missing
const post = await Post.findOrFail(1)              // throws ModelNotFoundException (404)
const published = await Post.where('published', true).orderBy('createdAt', 'desc').get()
const page = await Post.paginate({ page: 1, perPage: 20 })
const post = await Post.create({ title: 'Hello', body: 'World' })

Relationships, scopes, soft deletes, observers, accessors and mutators, and eager loading are documented in the database guide.

Mass assignment

fillable is the allowlist, and it is always strict: primary keys are excluded, and an AuthenticatableModel refuses password hashes and remember tokens whatever the list says. A column the server chooses next to request data, such as an owner, goes in set and stays out of fillable:

const post = await Post.create(data, { set: { authorId: user.id } })

Writes that carry no request data at all (seeders, system records) go through forceCreate() and forceUpdate().

Dialect subpaths

ImportContents
@guren/orm/drizzle/pgDrizzle's PostgreSQL schema DSL, plus sql
@guren/orm/drizzle/mysqlThe MySQL schema DSL
@guren/orm/drizzle/sqliteThe SQLite and D1 schema DSL

Documentation

guren.dev/docs

License

MIT

版本与发布记录

@guren/orm 共发布 60 个版本,首次发布于 2025/11/02;过去 12 个月发布了 52 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.16.2latest2026/11/16今天
2.16.12026/11/142 天前
2.16.02026/11/134 天前
2.15.12026/11/124 天前
2.15.02026/10/2225 天前
2.14.02026/10/071 个月前

其他发布通道:alpha → 0.1.1-alpha.0,rc → 1.0.0-rc.27。

关于 @guren/orm 的常见问题

@guren/orm 是什么?

Eloquent-style models for the Guren framework, on Drizzle ORM: PostgreSQL, MySQL, SQLite and Cloudflare D1.

如何安装 @guren/orm?

在项目目录运行 npm install @guren/orm,或使用 pnpm add / yarn add / bun add。

@guren/orm 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@guren/orm 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@guren/orm 可以商用吗?

@guren/orm 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@guren/orm 的下载量有多少?

根据 npm 官方下载统计,@guren/orm 在 2026/10/17 – 2026/11/15 这 30 天内被下载 9,603 次,日均约 320 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@guren/orm 还在维护吗?

最新版本 2.16.2 发布于 2026/11/16(今天);至今共发布 60 个版本,其中过去 12 个月发布了 52 个;首次发布于 2025/11/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。