@@ -47,6 +47,10 @@ export class MysqlDialect implements Dialect {
4747 //Recommended quote character
4848 public readonly q = q ;
4949
50+ //used for json notation
51+ public separator : string = '.' ;
52+ public splitter : string = ':' ;
53+
5054 /**
5155 * Converts alter builder to query and values
5256 */
@@ -485,6 +489,7 @@ export class MysqlDialect implements Dialect {
485489 } ) ;
486490
487491 query . push ( `SELECT ${ columns . join ( ', ' ) } ` ) ;
492+
488493 const table = `${ this . q } ${ build . from . name } ${ this . q } ` ;
489494 if ( build . from . alias ) {
490495 const alias = `${ this . q } ${ build . from . alias } ${ this . q } ` ;
@@ -514,17 +519,34 @@ export class MysqlDialect implements Dialect {
514519 if ( build . where . length > 0 || build . json . length > 0 ) {
515520 const filters : string [ ] = [ ] ;
516521 if ( build . where . length ) {
517- filters . push ( ...build . where . map ( filter => {
518- values . push ( ...filter . values ) ;
519- return filter . clause ;
520- } ) ) ;
522+ //find json phrases
523+ // - ex. data:info.name
524+ // - ex. profile.data:info
525+ // - ex. profile.data:info.name
526+ const jsonSelector = new RegExp (
527+ `([a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+){0,1}\\${ this . splitter } `
528+ + `[a-zA-Z0-9_]+(\\${ this . separator } [a-zA-Z0-9_]+)*)` ,
529+ 'g'
530+ ) ;
531+ filters . push ( ...build . where . map ( filter => {
532+ values . push ( ...filter . values ) ;
533+ //then replace with XJsonDialect.parse().extract
534+ return filter . clause . replace ( jsonSelector , match => {
535+ const json = MysqlJsonDialect . parse (
536+ match ,
537+ this . splitter ,
538+ this . separator
539+ ) ;
540+ return json ? json . extract : match ;
541+ } ) ;
542+ } ) ) ;
521543 }
522544 build . json . forEach ( filter => {
523545 const { query, replace } = filter ;
524546 const json = MysqlJsonDialect . parse (
525547 filter . selector ,
526- build . selector ,
527- build . separator
548+ this . splitter ,
549+ this . separator
528550 ) ;
529551 //if invalid JSON selector, skip it
530552 if ( ! json ) return ;
@@ -563,11 +585,11 @@ export class MysqlDialect implements Dialect {
563585 if ( build . sort . length ) {
564586 const sort = build . sort . map ( sort => {
565587 //if the sort column is using the selector ":" notation
566- if ( sort . column . name . includes ( build . selector ) ) {
588+ if ( sort . column . name . includes ( this . splitter ) ) {
567589 const json = MysqlJsonDialect . parse (
568590 sort . column . name ,
569- build . selector ,
570- build . separator
591+ this . splitter ,
592+ this . separator
571593 ) ;
572594 //if invalid JSON selector, skip it
573595 if ( ! json ) return '' ;
0 commit comments