Can't convert microsoft sql server script to dbml
- Dominant language
- JavaScript
- Stars
- 3.7k
- Forks
- 233
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 4
Description
I try to use js module to convert sql script to dbml.
Here is my sql script
```sql
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
```javascript
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. (/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. [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
Contributor guide
Assessment
This issue has not been assessed yet.