Skip to content

Commit d8346fa

Browse files
check table and column directives misspelling
1 parent adb6843 commit d8346fa

17 files changed

+1008
-851
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,9 @@ Error diagnostic fixes
5252
#62
5353
#63
5454

55+
## [1.2.12] - 2024-4-2
56+
57+
Misindented error diagnostics, one more time
58+
Table and column directive syntax check
59+
5560

dist/quick-erd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class T {
365365
});
366366
}
367367
}
368-
const _ = "1.2.11", R = {
368+
const _ = "1.2.12", R = {
369369
Diagram: T,
370370
version: _
371371
};

dist/quick-erd.umd.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/quick-sql.js

Lines changed: 783 additions & 714 deletions
Large diffs are not rendered by default.

dist/quick-sql.umd.cjs

Lines changed: 89 additions & 89 deletions
Large diffs are not rendered by default.

doc/user/quick-sql-grammar.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ and is usually omitted from QSQL schema definition.
124124
| /references, /reference, /fk | Foreign key references e.g. /references table_name. Note you can reference tables that are not part of your model. |
125125
| /cascade | on delete cascade |
126126
| /setnull | on delete set null |
127-
| /references, /reference, /fk | Foreign key references e.g. /references table_name. Note you can reference tables that are not part of your model. |
128127
| /pk | Identifies column as the primary key of the table. It is recommended not manually specify primary keys and let this app create primary key columns automatically. |
129128
| --, [comments] | Enclose comments using square brackets or using dash dash syntax |
130129
<!-- markdownlint-enable MD013 -->
@@ -467,6 +466,8 @@ tableDirective::= '/'
467466
|'rest'
468467
|'unique' | 'uk'
469468
|'pk'
469+
|'check'
470+
|'cascade'
470471
)
471472
472473
columnDirective::= '/'
@@ -482,6 +483,7 @@ columnDirective::= '/'
482483
|'between'
483484
|'hidden'|'invisible'
484485
|'references'|'reference'
486+
|'cascade'|'setnull'
485487
|'fk'
486488
|'pk'
487489
)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@oracle/quicksql",
3-
"version": "1.2.11",
3+
"version": "1.2.12",
44
"description": "Quick SQL to DDL and ERD translator",
55
"main": "./dist/quick-sql.umd.cjs",
66
"module": "./dist/quick-sql.js",

src/errorMsgs.js

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ const findErrors = (function () {
2626

2727
const lines = input.split("\n");
2828

29-
ret = ret.concat(line_mismatch(parsed.forest[0].descendants()));
29+
let branches = []
30+
for( var i = 0; i < parsed.forest.length; i++ ) {
31+
if( parsed.forest[i].parseType() == 'table' )
32+
branches = branches.concat(parsed.forest[i].descendants());
33+
}
34+
ret = ret.concat(line_mismatch(branches));
3035
const descendants = ddl.descendants();
3136

3237
for( let i = 0; i < descendants.length; i++ ) {
@@ -51,11 +56,45 @@ const findErrors = (function () {
5156

5257
ret = ret.concat(ref_error_in_view(ddl,node));
5358
ret = ret.concat(fk_ref_error(ddl,node));
59+
ret = ret.concat(directive_typo(ddl,node));
5460
}
5561

5662
return ret;
5763
}
5864

65+
function directive_typo( ddl, node ) {
66+
const isTable = node.parseType() == 'table';
67+
var ret = [];
68+
69+
var chunks = node.src;
70+
var sawSlash = false;
71+
for( var j = 1; j < chunks.length; j++ ) {
72+
if( chunks[j].value == '/' ) {
73+
sawSlash = true;
74+
continue;
75+
}
76+
if( sawSlash ) {
77+
sawSlash = false;
78+
if( isTable && tableDirectives.indexOf(chunks[j].value.toLowerCase()) < 0 )
79+
ret.push( new SyntaxError(
80+
messages.tableDirectiveTypo,
81+
new Offset(node.line, chunks[j].begin),
82+
new Offset(node.line, chunks[j].begin+chunks[j].value.length)
83+
));
84+
if( !isTable && columnDirectives.indexOf(chunks[j].value.toLowerCase()) < 0 )
85+
ret.push( new SyntaxError(
86+
messages.columnDirectiveTypo,
87+
new Offset(node.line, chunks[j].begin),
88+
new Offset(node.line, chunks[j].begin+chunks[j].value.length)
89+
));
90+
91+
continue;
92+
}
93+
}
94+
return ret;
95+
}
96+
97+
5998
function ref_error_in_view( ddl, node ) {
6099
var ret = [];
61100

@@ -105,19 +144,14 @@ const findErrors = (function () {
105144
var indent = guessIndent( lines )
106145

107146
for( var i = 1; i < lines.length; i++ ) {
108-
var priorline = lines[i-1];
109147
var line = lines[i];
110148

111-
var priorIndent = depth(priorline);
112149
var lineIndent = depth(line);
113-
114-
if( lineIndent == 0 )
115-
continue;
116-
117-
if( priorIndent < lineIndent && lineIndent < priorIndent+indent )
150+
151+
if( lineIndent%indent != 0 )
118152
ret.push(new SyntaxError(
119153
messages.misalignedAttribute+indent,
120-
new Offset(i, lineIndent)
154+
new Offset(line.line, lineIndent)
121155
)
122156
);
123157
}
@@ -127,7 +161,37 @@ const findErrors = (function () {
127161
return checkSyntax;
128162
}());
129163

130-
164+
const tableDirectives = [
165+
'api'
166+
,'audit','auditcols',//'audit cols','audit columns'
167+
,'check'
168+
,'colprefix'
169+
,'compress','compressed'
170+
,'insert'
171+
,'rest'
172+
,'select'
173+
,'unique' , 'uk'
174+
,'pk'
175+
,'cascade','setnull' //'set null'
176+
];
177+
178+
const columnDirectives = [
179+
'idx','index','indexed'
180+
,'unique','uk'
181+
,'check'
182+
,'constant'
183+
,'default'
184+
,'values'
185+
,'upper'
186+
,'lower'
187+
,'nn','not'//,'not null'
188+
,'between'
189+
,'hidden','invisible'
190+
,'references','reference'
191+
,'cascade','setnull' //'set null'
192+
,'fk'
193+
,'pk'
194+
];
131195

132196
function guessIndent( lines ) {
133197
let depths = [];
@@ -174,6 +238,8 @@ const messages = {
174238
invalidDatatype: 'Invalid Datatype',
175239
undefinedObject: 'Undefined Object: ',
176240
misalignedAttribute: 'Misaligned Table or Column; apparent indent = ',
241+
tableDirectiveTypo: 'Unknown Table directive',
242+
columnDirectiveTypo: 'Unknown Column directive',
177243
}
178244

179245
export default {findErrors, messages};

test/apex/departments_employees_skills.quicksql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ departments /insert 2
88
job vc255
99
hiredate
1010
skills /insert 6
11-
skill vc255 /values C++, Java, APEX, JSON, Javascript, Python, CSS
12-
proficiency num /check 1, 2, 3, 4, 5 [with 1 being a novice and 5 being a guru]
11+
skill vc255 /values C++, Java, APEX, JSON, Javascript, Python, CSS
12+
proficiency num /check 1, 2, 3, 4, 5 [with 1 being a novice and 5 being a guru]
1313

1414
# "schema": null
1515
# "semantics": "char"

test/apex/forrestclinic.quicksql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ patients
2626
registration_date date
2727

2828
patient_procedures
29-
patient_id num /fk patients
30-
doctor vc30
31-
medical_procedure vc30
32-
procedure_date date
33-
status vc30
34-
amount_due num
29+
patient_id num /fk patients
30+
doctor vc30
31+
medical_procedure vc30
32+
procedure_date date
33+
status vc30
34+
amount_due num
3535

3636
doctor_procedures
3737
doctor vc30

0 commit comments

Comments
 (0)