@dbml/core

中文文档
12.0.0发布于 2026/11/09Apache-2.0TypeScriptESM + CJS近 30 天下载 76.3万

TODO: description

原始使用文档
文档目录9 节
  1. Installation
  2. SQL Parser Feature Support
  3. Support Legend
  4. CREATE TABLE
  5. CREATE INDEX
  6. INSERT Statements
  7. ALTER TABLE
  8. Comments
  9. Other DDL Statements

@dbml/core

Refer to @dbml/core for the complete API reference.

Installation

npm install @dbml/core

# or if you're using yarn
yarn add @dbml/core

SQL Parser Feature Support

This section documents the SQL parsing capabilities for each supported database when importing SQL to DBML.

For more detailed documentation on each SQL parser, see the individual parser READMEs:

Support Legend

SymbolMeaning
✓Fully supported and correctly parsed
◐Valid SQL that is parsed, but some options/clauses are ignored
✗Valid SQL syntax, but the parser fails to generate output
—Syntax not valid for this database

CREATE TABLE

FeaturePostgreSQLMySQLMSSQLOracleSnowflake
Basic syntax✓✓✓✓✓
Parameterized types (e.g., VARCHAR(255))✓✓✓✓✓
Array types (e.g., INTEGER[])✓————
Enumerated types (ENUM)✓✓———
Temporary tables◐✗✓◐◐
CREATE TABLE AS SELECT✗✗✗✗✗
Table options (ENGINE, TABLESPACE, etc.)◐◐◐◐◐
Other column properties (COLLATE, etc.)◐✗◐◐◐
Generated/Computed columns◐◐◐◐◐

Notes:

  • MSSQL:
    • Temporary tables use # prefix (local) and ## prefix (global)
    • Square bracket identifiers ([identifier]) are supported

PRIMARY KEY

FeaturePostgreSQLMySQLMSSQLOracleSnowflake
Column-level✓✓✓✓✓
Table-level✓✓✓✓✓
Multi-column✓✓✓✓✓
Explicitly named (CONSTRAINT name)✓✓✓✓✓
CLUSTERED/NONCLUSTERED——◐——

FOREIGN KEY

FeaturePostgreSQLMySQLMSSQLOracleSnowflake
Column-level (REFERENCES)✓✓✗✓✗
Table-level✓✓✓✓✗
Multi-column✓✓✓✓✗
Explicitly named (CONSTRAINT name)✓✓✓✓✗
ON UPDATE action✓✓✓—✗
ON DELETE action✓✓✓✓✗

Notes:

  • MSSQL: Column-level FOREIGN KEY has a known bug - use table-level syntax instead
  • Snowflake: All FOREIGN KEY definitions have a known bug producing undefined errors

UNIQUE

FeaturePostgreSQLMySQLMSSQLOracleSnowflake
Column-level✓✓✓✓✓
Table-level✓✓✓✓✓
Multi-column✓✓✓✓✓
Explicitly named (CONSTRAINT name)✓✓◐✓◐
UNIQUE KEY/UNIQUE INDEX syntax—✓———

CHECK

FeaturePostgreSQLMySQLMSSQLOracleSnowflake
Column-level✓✓✓✓✗
Table-level✓✓✓✓✗
Explicitly named (CONSTRAINT name)✓✓✓✓✗

DEFAULT

FeaturePostgreSQLMySQLMSSQLOracleSnowflake
Column-level✓✓✓✓✓
Function as default✓✓✓✓✓
Explicitly named (CONSTRAINT name)——◐—◐

NOT NULL

FeaturePostgreSQLMySQLMSSQLOracleSnowflake
Column-level NOT NULL✓✓✓✓✓
Explicit column-level NULL✓✓✓✓✓

Auto-Increment Columns

FeaturePostgreSQLMySQLMSSQLOracleSnowflake
SERIAL (pseudo-type)✓————
BIGSERIAL (pseudo-type)✓————
AUTO_INCREMENT (column attribute)—✓———
IDENTITY(seed, increment) (column property)——✓—✓
GENERATED AS IDENTITY (column property)✓—✗✓✗
GENERATED ALWAYS AS IDENTITY✓——✓—
GENERATED BY DEFAULT AS IDENTITY✓——✓—

Inline Indexes

FeaturePostgreSQLMySQLMSSQLOracleSnowflake
Column-level indexes—✗———
Table-level INDEX/KEY—✓—✓—
Named indexes—✓—✓—
Multi-column indexes—✓—✓—
USING BTREE/HASH—✓———
FULLTEXT/SPATIAL—◐———

CREATE INDEX

FeaturePostgreSQLMySQLMSSQLOracleSnowflake
Basic CREATE INDEX✓✓✓✓—
Multi-column index✓✓✓✓—
UNIQUE index✓✓✓✓—
Function-based index✓✓—✓—
BTREE✓✓✗——
HASH✓✓———
GIST✓————
BRIN✓————
GIN✓————
Partial/Filtered index (WHERE)◐✗◐◐—
FULLTEXT—◐✗——
SPATIAL—◐✗——

Notes:

  • MSSQL: Function-based indexes use computed columns instead

INSERT Statements

FeaturePostgreSQLMySQLMSSQLOracleSnowflake
Basic INSERT ... VALUES✓✓✓✓✗
Multi-row INSERT✓✓✓✓✓
INSERT ... SELECT✗✗✗✗✗
INSERT ... with returned rows (RETURNING, OUTPUT)◐—◐◐—
INSERT ... ON CONFLICT/DUPLICATE KEY◐◐———

Notes:

  • Oracle: Multi-row inserts use INSERT ALL ... SELECT * FROM dual syntax, which is fully supported.

ALTER TABLE

FeaturePostgreSQLMySQLMSSQLOracleSnowflake
ADD COLUMN✗✗✗✗✗
DROP COLUMN✗✗✗✗✗
ALTER/MODIFY COLUMN✗✗✗✗✗
RENAME COLUMN✗✗✗✗✗
ADD CONSTRAINT
- DEFAULT✗✗✓✓✗
- NOT NULL✗✗✗✓✗
- CHECK✓✓✓✓—
- UNIQUE✓✗✓✓✓
- PRIMARY KEY✓✓✓✓✗
- FOREIGN KEY✓✓✓✓✓
DROP CONSTRAINT✗✗✗✗✗

Comments

FeaturePostgreSQLMySQLMSSQLOracleSnowflake
Table comments✓✓◐✓✓
Column comments✓✓◐✓✗
Comment syntaxCOMMENT ONInline COMMENTsp_addextendedpropertyCOMMENT ONInline COMMENT

Notes:

  • MSSQL: Comments via sp_addextendedproperty have unreliable parsing

Other DDL Statements

FeaturePostgreSQLMySQLMSSQLOracleSnowflake
DROP TABLE✗✗✗✗✗
DROP INDEX✗✗✗✗—
ALTER INDEX✗—✗✗—
CREATE VIEW✗✗✗✗✗

版本与发布记录

@dbml/core 共发布 273 个版本,首次发布于 2019/08/19;过去 12 个月发布了 164 个版本。

版本发布日期距今
12.0.0latest2026/11/092 天前
11.1.02026/11/065 天前
11.0.2-metadata-ref.2alpha2026/11/065 天前
11.0.2-metadata-ref.12026/11/065 天前
11.0.2-arch.0.42026/11/056 天前
11.0.2-arch.0.32026/11/056 天前

关于 @dbml/core 的常见问题

@dbml/core 是什么?

TODO: description

如何安装 @dbml/core?

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

@dbml/core 支持 TypeScript 吗?

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

@dbml/core 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dbml/core 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dbml/core 可以商用吗?

@dbml/core 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@dbml/core 的下载量有多少?

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

@dbml/core 还在维护吗?

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