Skip to content

Commit 69bc249

Browse files
committed
update example
1 parent 43024b0 commit 69bc249

File tree

3 files changed

+205
-6
lines changed

3 files changed

+205
-6
lines changed

README.md

Lines changed: 104 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@ var sql = `CREATE TABLE "humanresources_department" (
1313
"groupname" Name NOT NULL,
1414
"modifieddate" timestamp NOT NULL,
1515
PRIMARY KEY("departmentid")
16-
);`
16+
);
17+
18+
CREATE TABLE "humanresources_employeedepartmenthistory" (
19+
"businessentityid" int(4) NOT NULL,
20+
"departmentid" int(2) NOT NULL,
21+
"shiftid" int(2) NOT NULL,
22+
"startdate" date NOT NULL,
23+
"enddate" date,
24+
"modifieddate" timestamp NOT NULL,
25+
PRIMARY KEY("businessentityid","departmentid","shiftid","startdate"),
26+
FOREIGN KEY ("departmentid") REFERENCES "humanresources_department"("departmentid")
27+
);
28+
`
1729

1830
// run parser
1931
const parser = new SqlSimpleParser('postgres')
@@ -34,7 +46,15 @@ const models = parser
3446
"Name": "departmentid",
3547
"ColumnProperties": "serial NOT NULL",
3648
"TableName": "humanresources_department",
37-
"ForeignKey": [],
49+
"ForeignKey": [
50+
{
51+
"PrimaryKeyTableName": "humanresources_employeedepartmenthistory",
52+
"PrimaryKeyName": "departmentid",
53+
"ReferencesPropertyName": "departmentid",
54+
"ReferencesTableName": "humanresources_department",
55+
"IsDestination": true
56+
}
57+
],
3858
"IsForeignKey": false,
3959
"IsPrimaryKey": true
4060
},
@@ -63,14 +83,94 @@ const models = parser
6383
"IsPrimaryKey": false
6484
}
6585
]
86+
},
87+
{
88+
"Name": "humanresources_employeedepartmenthistory",
89+
"Properties": [
90+
{
91+
"Name": "businessentityid",
92+
"ColumnProperties": "int(4) NOT NULL",
93+
"TableName": "humanresources_employeedepartmenthistory",
94+
"ForeignKey": [],
95+
"IsForeignKey": false,
96+
"IsPrimaryKey": false
97+
},
98+
{
99+
"Name": "departmentid",
100+
"ColumnProperties": "int(2) NOT NULL",
101+
"TableName": "humanresources_employeedepartmenthistory",
102+
"ForeignKey": [
103+
{
104+
"PrimaryKeyTableName": "humanresources_department",
105+
"PrimaryKeyName": "departmentid",
106+
"ReferencesPropertyName": "departmentid",
107+
"ReferencesTableName": "humanresources_employeedepartmenthistory",
108+
"IsDestination": false
109+
}
110+
],
111+
"IsForeignKey": true,
112+
"IsPrimaryKey": false
113+
},
114+
{
115+
"Name": "shiftid",
116+
"ColumnProperties": "int(2) NOT NULL",
117+
"TableName": "humanresources_employeedepartmenthistory",
118+
"ForeignKey": [],
119+
"IsForeignKey": false,
120+
"IsPrimaryKey": false
121+
},
122+
{
123+
"Name": "startdate",
124+
"ColumnProperties": "date NOT NULL",
125+
"TableName": "humanresources_employeedepartmenthistory",
126+
"ForeignKey": [],
127+
"IsForeignKey": false,
128+
"IsPrimaryKey": false
129+
},
130+
{
131+
"Name": "enddate",
132+
"ColumnProperties": "date",
133+
"TableName": "humanresources_employeedepartmenthistory",
134+
"ForeignKey": [],
135+
"IsForeignKey": false,
136+
"IsPrimaryKey": false
137+
},
138+
{
139+
"Name": "modifieddate",
140+
"ColumnProperties": "timestamp NOT NULL",
141+
"TableName": "humanresources_employeedepartmenthistory",
142+
"ForeignKey": [],
143+
"IsForeignKey": false,
144+
"IsPrimaryKey": false
145+
}
146+
]
147+
}
148+
],
149+
"Dialect": "postgres",
150+
"ForeignKeyList": [
151+
{
152+
"PrimaryKeyTableName": "humanresources_employeedepartmenthistory",
153+
"PrimaryKeyName": "departmentid",
154+
"ReferencesPropertyName": "departmentid",
155+
"ReferencesTableName": "humanresources_department",
156+
"IsDestination": true
157+
},
158+
{
159+
"PrimaryKeyTableName": "humanresources_department",
160+
"PrimaryKeyName": "departmentid",
161+
"ReferencesPropertyName": "departmentid",
162+
"ReferencesTableName": "humanresources_employeedepartmenthistory",
163+
"IsDestination": false
66164
}
67165
],
68-
"Dialect": "sqlserver",
69-
"ForeignKeyList": [],
70166
"PrimaryKeyList": [
71167
{
72168
"PrimaryKeyTableName": "humanresources_department",
73169
"PrimaryKeyName": "departmentid"
170+
},
171+
{
172+
"PrimaryKeyTableName": "humanresources_employeedepartmenthistory",
173+
"PrimaryKeyName": "businessentityid,departmentid,shiftid,startdate"
74174
}
75175
]
76176
}

tests/SqlSimpleParser/examples_models.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,17 @@ describe("Example Sql Parsing", () => {
181181
"groupname" Name NOT NULL,
182182
"modifieddate" timestamp NOT NULL,
183183
PRIMARY KEY("departmentid")
184+
);
185+
186+
CREATE TABLE "humanresources_employeedepartmenthistory" (
187+
"businessentityid" int(4) NOT NULL,
188+
"departmentid" int(2) NOT NULL,
189+
"shiftid" int(2) NOT NULL,
190+
"startdate" date NOT NULL,
191+
"enddate" date,
192+
"modifieddate" timestamp NOT NULL,
193+
PRIMARY KEY("businessentityid","departmentid","shiftid","startdate"),
194+
FOREIGN KEY ("departmentid") REFERENCES "humanresources_department"("departmentid")
184195
);`;
185196
// console.log(sql);
186197

tests/data/results/ToModel.json

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20479,7 +20479,15 @@
2047920479
"Name": "departmentid",
2048020480
"ColumnProperties": "serial NOT NULL",
2048120481
"TableName": "humanresources_department",
20482-
"ForeignKey": [],
20482+
"ForeignKey": [
20483+
{
20484+
"PrimaryKeyTableName": "humanresources_employeedepartmenthistory",
20485+
"PrimaryKeyName": "departmentid",
20486+
"ReferencesPropertyName": "departmentid",
20487+
"ReferencesTableName": "humanresources_department",
20488+
"IsDestination": true
20489+
}
20490+
],
2048320491
"IsForeignKey": false,
2048420492
"IsPrimaryKey": true
2048520493
},
@@ -20508,14 +20516,94 @@
2050820516
"IsPrimaryKey": false
2050920517
}
2051020518
]
20519+
},
20520+
{
20521+
"Name": "humanresources_employeedepartmenthistory",
20522+
"Properties": [
20523+
{
20524+
"Name": "businessentityid",
20525+
"ColumnProperties": "int(4) NOT NULL",
20526+
"TableName": "humanresources_employeedepartmenthistory",
20527+
"ForeignKey": [],
20528+
"IsForeignKey": false,
20529+
"IsPrimaryKey": false
20530+
},
20531+
{
20532+
"Name": "departmentid",
20533+
"ColumnProperties": "int(2) NOT NULL",
20534+
"TableName": "humanresources_employeedepartmenthistory",
20535+
"ForeignKey": [
20536+
{
20537+
"PrimaryKeyTableName": "humanresources_department",
20538+
"PrimaryKeyName": "departmentid",
20539+
"ReferencesPropertyName": "departmentid",
20540+
"ReferencesTableName": "humanresources_employeedepartmenthistory",
20541+
"IsDestination": false
20542+
}
20543+
],
20544+
"IsForeignKey": true,
20545+
"IsPrimaryKey": false
20546+
},
20547+
{
20548+
"Name": "shiftid",
20549+
"ColumnProperties": "int(2) NOT NULL",
20550+
"TableName": "humanresources_employeedepartmenthistory",
20551+
"ForeignKey": [],
20552+
"IsForeignKey": false,
20553+
"IsPrimaryKey": false
20554+
},
20555+
{
20556+
"Name": "startdate",
20557+
"ColumnProperties": "date NOT NULL",
20558+
"TableName": "humanresources_employeedepartmenthistory",
20559+
"ForeignKey": [],
20560+
"IsForeignKey": false,
20561+
"IsPrimaryKey": false
20562+
},
20563+
{
20564+
"Name": "enddate",
20565+
"ColumnProperties": "date",
20566+
"TableName": "humanresources_employeedepartmenthistory",
20567+
"ForeignKey": [],
20568+
"IsForeignKey": false,
20569+
"IsPrimaryKey": false
20570+
},
20571+
{
20572+
"Name": "modifieddate",
20573+
"ColumnProperties": "timestamp NOT NULL",
20574+
"TableName": "humanresources_employeedepartmenthistory",
20575+
"ForeignKey": [],
20576+
"IsForeignKey": false,
20577+
"IsPrimaryKey": false
20578+
}
20579+
]
2051120580
}
2051220581
],
2051320582
"Dialect": "postgres",
20514-
"ForeignKeyList": [],
20583+
"ForeignKeyList": [
20584+
{
20585+
"PrimaryKeyTableName": "humanresources_employeedepartmenthistory",
20586+
"PrimaryKeyName": "departmentid",
20587+
"ReferencesPropertyName": "departmentid",
20588+
"ReferencesTableName": "humanresources_department",
20589+
"IsDestination": true
20590+
},
20591+
{
20592+
"PrimaryKeyTableName": "humanresources_department",
20593+
"PrimaryKeyName": "departmentid",
20594+
"ReferencesPropertyName": "departmentid",
20595+
"ReferencesTableName": "humanresources_employeedepartmenthistory",
20596+
"IsDestination": false
20597+
}
20598+
],
2051520599
"PrimaryKeyList": [
2051620600
{
2051720601
"PrimaryKeyTableName": "humanresources_department",
2051820602
"PrimaryKeyName": "departmentid"
20603+
},
20604+
{
20605+
"PrimaryKeyTableName": "humanresources_employeedepartmenthistory",
20606+
"PrimaryKeyName": "businessentityid,departmentid,shiftid,startdate"
2051920607
}
2052020608
]
2052120609
},

0 commit comments

Comments
 (0)