Skip to content

Commit 611dc21

Browse files
issue 47 complete
1 parent a53a65d commit 611dc21

File tree

7 files changed

+185
-184
lines changed

7 files changed

+185
-184
lines changed

dist/quick-sql.js

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

dist/quick-sql.umd.cjs

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

src/ddl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ export const quicksql = (function () {
325325
if( pkNode == null )
326326
continue;
327327
let pk = 'id';
328-
if( pkNode.getExplicitPkNode() != null )
329-
pk = pkNode.getExplicitPkNode().parseName();
328+
if( pkNode.getExplicitPkName() != null )
329+
pk = pkNode.getExplicitPkName();
330330

331331
output.links.push({source: this.objPrefix() +parent, source_id: pk,
332332
target: this.objPrefix() + descendants[i].parseName(''), target_id: fk

src/tree.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ let tree = (function(){
131131

132132
this.isOption = function( token, token2 ) {
133133
for( let i = 2; i < this.src.length; i++ ) {
134-
if( token == this.src[i].value )
135-
if( token2 == null || i < this.src.length-1 && token2 ==this.src[i+1].value)
134+
if( token == this.src[i].value.toLowerCase() )
135+
if( token2 == null || i < this.src.length-1 && token2 ==this.src[i+1].value.toLowerCase() )
136136
return this.src[i-1].value == '/';
137137
}
138138
return false;
@@ -146,7 +146,7 @@ let tree = (function(){
146146
return null;
147147

148148
let ret = '';
149-
for( let i = pos+1; i < this.src.length && this.src[i] != '/'; i++ )
149+
for( let i = pos+1; i < this.src.length && this.src[i].value != '/'; i++ )
150150
ret += this.src[i].value;
151151

152152
return ret;
@@ -192,7 +192,7 @@ let tree = (function(){
192192
if( this.src[0].value == 'view' ) {
193193
return this.src[1].value;
194194
}
195-
if( 1 < this.src.length && this.src[0].value == '=' ) {
195+
if( 1 < this.src.length && this.src[1].value == '=' ) {
196196
return this.src[0].value;
197197
}
198198
rEt = replaceTrailing(rEt,' d');
@@ -655,9 +655,13 @@ let tree = (function(){
655655

656656

657657
if( !this.isMany2One() ) {
658-
if( this.parent != null && this.parseType() == 'table' )
659-
//this.fks[singular(this.parent.parseName())+'_id']=this.parent.parseName();
660-
this.fks[singular(this.parent.getPkName())]=this.parent.parseName();
658+
if( this.parent != null && this.parseType() == 'table' ) {
659+
const pkn = this.parent.getPkName();
660+
if( pkn.indexOf(',') < 0 )
661+
this.fks[singular(this.parent.parseName())+'_id']=this.parent.parseName();
662+
else
663+
this.fks[singular(this.parent.getPkName())]=this.parent.parseName();
664+
}
661665
for( let i = 0; i < this.children.length; i++ )
662666
if( this.children[i].refId() != null ) {
663667
this.fks[this.children[i].parseName()]=this.children[i].refId();
@@ -724,10 +728,11 @@ let tree = (function(){
724728
type = attr.parseType('fk');
725729
let refNode = ddl.find(parent);
726730
let _id = '';
727-
const rname = refNode.getExplicitPkName();
728-
if( refNode != null && rname != null && rname.indexOf(',') < 0 )
729-
type = refNode.getPkType();
730-
else if( refNode == null ) {
731+
if( refNode != null ) {
732+
const rname = refNode.getExplicitPkName();
733+
if( rname != null && rname.indexOf(',') < 0 )
734+
type = refNode.getPkType();
735+
} else {
731736
refNode = ddl.find(fk);
732737
if( refNode.isMany2One() & !fk.endsWith('_id') ) {
733738
parent = fk;

test/apex/medipay.quicksql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ user_claims
4444
receipt_from_id number /nn /fk user_sources
4545
receipt_date date /nn
4646
receipt_amount number /nn
47-
claimant number /FK users
47+
claimant number /fk users
4848
status vc80
4949
payment_txn_id number
5050
reimburse_percentage number

test/single_test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import fs from "fs";
55
try {
66
let file = '//bugs/Bug35669377.quicksql';
77
//file = '//experimental/food_product.json';
8+
//file = '//JSON/car_racing/1.qsql';
9+
file = '//bugs/Bug35637603.quicksql';
810

911
let args = process.argv.slice(2);
1012
if( 0 < args.length )

test/small_tests.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ students
593593
first_name
594594
last_name `).getDDL();
595595

596-
assert( "0 < output.indexOf(\"alter table employee add constraint employee_uk unique (first_name, last_name);\")" );
596+
assert( "0 < output.indexOf(\"alter table employee add constraint employee_uk unique (first_name,last_name);\")" );
597597

598598
// https://github.com/oracle/quicksql/issues/47
599599
output = new quicksql( `employee /pk first_name, last_name
@@ -610,24 +610,14 @@ students
610610
assert( "0 < output.indexOf(\"constraint employee_job_history_fk foreign key (first_name,last_name) references employee;\")" );
611611
}
612612

613-
// https://github.com/oracle/quicksql/issues/31
614-
output = new quicksql( `departments /audit cols
615-
name
616-
employees /audit columns
617-
name
618-
`).getDDL();
619-
620-
console.log(output);
621-
assert( "output.indexOf('audit all') < 0 " );
622-
assert( "output.indexOf('created date not null') < output.lastIndexOf('created date not null,')" );
623613

624614

625-
//small_tests();
615+
small_tests();
626616

627617
console.log(assertionCnt);
628618

629619
// metatest that watches tests
630-
const minimalTestCnt = 100;
620+
const minimalTestCnt = 110;
631621
if( assertionCnt < minimalTestCnt ) {
632622
console.error("assertionCnt < "+minimalTestCnt);
633623
throw new Error('Test failed');

0 commit comments

Comments
 (0)