|
| 1 | +# sql-simple-parser |
| 2 | +sql ddl parser to support extensions for drawio |
| 3 | + |
| 4 | +## Getting started |
| 5 | +* how to use: |
| 6 | +```typescript |
| 7 | +import {SqlSimpleParser} from "@funktechno/sqlsimpleparser" |
| 8 | + |
| 9 | +var sample = `CREATE TABLE "humanresources_department" ( |
| 10 | + "departmentid" serial NOT NULL, |
| 11 | + "name" Name NOT NULL, |
| 12 | + "groupname" Name NOT NULL, |
| 13 | + "modifieddate" timestamp NOT NULL, |
| 14 | + PRIMARY KEY("departmentid") |
| 15 | +);` |
| 16 | + |
| 17 | +// run parser |
| 18 | +const parser = new SqlSimpleParser('postgres') |
| 19 | + |
| 20 | +// get models |
| 21 | +const models = parser |
| 22 | + .feed(sql) |
| 23 | + .ToModel(); |
| 24 | +``` |
| 25 | +* outputs |
| 26 | +```json |
| 27 | +{ |
| 28 | + "TableList": [ |
| 29 | + { |
| 30 | + "Name": "humanresources_department", |
| 31 | + "Properties": [ |
| 32 | + { |
| 33 | + "Name": "departmentid", |
| 34 | + "ColumnProperties": "serial NOT NULL", |
| 35 | + "TableName": "humanresources_department", |
| 36 | + "ForeignKey": [], |
| 37 | + "IsForeignKey": false, |
| 38 | + "IsPrimaryKey": true |
| 39 | + }, |
| 40 | + { |
| 41 | + "Name": "name", |
| 42 | + "ColumnProperties": "Name NOT NULL", |
| 43 | + "TableName": "humanresources_department", |
| 44 | + "ForeignKey": [], |
| 45 | + "IsForeignKey": false, |
| 46 | + "IsPrimaryKey": false |
| 47 | + }, |
| 48 | + { |
| 49 | + "Name": "groupname", |
| 50 | + "ColumnProperties": "Name NOT NULL", |
| 51 | + "TableName": "humanresources_department", |
| 52 | + "ForeignKey": [], |
| 53 | + "IsForeignKey": false, |
| 54 | + "IsPrimaryKey": false |
| 55 | + }, |
| 56 | + { |
| 57 | + "Name": "modifieddate", |
| 58 | + "ColumnProperties": "timestamp NOT NULL", |
| 59 | + "TableName": "humanresources_department", |
| 60 | + "ForeignKey": [], |
| 61 | + "IsForeignKey": false, |
| 62 | + "IsPrimaryKey": false |
| 63 | + } |
| 64 | + ] |
| 65 | + } |
| 66 | + ], |
| 67 | + "Dialect": "sqlserver", |
| 68 | + "ForeignKeyList": [], |
| 69 | + "PrimaryKeyList": [ |
| 70 | + { |
| 71 | + "PrimaryKeyTableName": "humanresources_department", |
| 72 | + "PrimaryKeyName": "departmentid" |
| 73 | + } |
| 74 | + ] |
| 75 | +} |
| 76 | +``` |
| 77 | +* there are some [example](./examples) sql files |
| 78 | +* see test `examples_models.spec` for more use cases |
| 79 | + |
| 80 | +## Supported |
| 81 | +* Databases: sqlite, postgres, sqlserver, mysql |
| 82 | +* table names, primary keys, foreign keys, column names with extended column information |
| 83 | + |
| 84 | +## Development |
| 85 | +* `npm install` |
| 86 | +* `npm test` or use vscode debugger **Jest single run** |
0 commit comments