Can't convert microsoft sql server script to dbml

未关闭
#263 0 条评论 2 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@huydo862003 已经在做这个了。

开始于 2025年11月6日。

评估

这个 Issue 还没有评估数据。

描述

bug

I try to use js module to convert sql script to dbml.
Here is my sql script

CREATE TABLE dbo.hello (
	id int IDENTITY(1,1) NOT NULL,
	created_at datetime2(3) DEFAULT getdate() NOT NULL,
	updated_at datetime2(3) DEFAULT getdate() NOT NULL,
	deleted_at datetime2(3) NULL,
	[key] nvarchar(225) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[value] int NOT NULL,
	[w_id] int NOT NULL,
	CONSTRAINT PK_8a11c3956fec7db6df1a0244e5f PRIMARY KEY (id)
);
CREATE UNIQUE NONCLUSTERED INDEX UQ_393c557e09ac67c724f8ec7334f ON dbo.hello ([key]);
CREATE  UNIQUE NONCLUSTERED INDEX REL_4a6194b005c383df6539faa3f3 ON dbo.hello (  w_id ASC  )
	WHERE  ([w_id] IS NOT NULL)
	WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
	ON [PRIMARY ] ;

Here is my js script

const ddl = fs.readFileSync('./dbdocs/database.ddl', 'utf-8')
fs.writeFileSync('./dbdocs/database.dbml', importer.import(ddl, 'mssql'))

And I got an error message:

Error: 
-- PARSING FAILED --------------------------------------------------

  11 | CREATE UNIQUE NONCLUSTERED INDEX UQ_393c557e09ac67c724f8ec7334f ON dbo.hello ([key]);
  12 | CREATE  UNIQUE NONCLUSTERED INDEX REL_4a6194b005c383df6539faa3f3 ON dbo.hello (  w_id ASC  )
> 13 |  WHERE  ([w_id] IS NOT NULL)
     |         ^
  14 |  WITH (  PAD_INDEX = OFF ,FILLFACTOR = 100  ,SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , STATISTICS_NORECOMPUTE = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON  )
  15 |  ON [PRIMARY ] ;

Expected one of the following: 

comments, identifier, whitespaces

    at Parsimmon._.tryParse (/Users/eugene/code/sto/sto-dapp/node_modules/parsimmon/src/parsimmon.js:928:15)
    at Parsimmon.mssqlParser.parseWithPegError (/Users/eugene/code/sto/sto-dapp/node_modules/@dbml/core/lib/parse/mssql/index.js:7:24)
    at Function.parseMSSQLToJSON (/Users/eugene/code/sto/sto-dapp/node_modules/@dbml/core/lib/parse/Parser.js:64:38)
    at Function.parse (/Users/eugene/code/sto/sto-dapp/node_modules/@dbml/core/lib/parse/Parser.js:89:32)
    at Object._import [as import] (/Users/eugene/code/sto/sto-dapp/node_modules/@dbml/core/lib/import/index.js:15:37)
    at Object.<anonymous> (/Users/eugene/code/sto/sto-dapp/dbdocs/convert.ts:6:59)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module.m._compile (/Users/eugene/code/sto/sto-dapp/node_modules/ts-node/src/index.ts:1455:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/eugene/code/sto/sto-dapp/node_modules/ts-node/src/index.ts:1458:12) {
  type: 'ParsimmonError',
  result: {
    status: false,
    index: { offset: 557, line: 13, column: 9 },
    expected: [ 'comments', 'identifier', 'whitespaces' ]
  }
}
{
  name: 'SyntaxError',
  location: { start: { offset: 557, line: 13, column: 9 } },
  found: '(',
  message: 'Expected comments, identifier, or whitespaces but "(" found.'
}

I have tried to run this sql script on sql server, and it can success create table and index

主要语言
JavaScript
星标
3.7k
派生
233
平均合并
2 天 4 小时
30 天内合并 PR
23

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

holistics/dbml 的其他 Issue

查看 holistics/dbml 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。