@@ -573,6 +573,17 @@ PostgreSQL.prototype.buildWhere = function(model, where) {
573
573
return whereClause ;
574
574
} ;
575
575
576
+ PostgreSQL . prototype . getEncryptionFields = function ( modelDefinition ) {
577
+ if ( modelDefinition
578
+ && modelDefinition . settings
579
+ && modelDefinition . settings . mixins
580
+ && modelDefinition . settings . mixins . Encryption
581
+ && modelDefinition . settings . mixins . Encryption . fields ) {
582
+ return modelDefinition . settings . mixins . Encryption . fields
583
+ }
584
+ return [ ]
585
+ }
586
+
576
587
/**
577
588
* @private
578
589
* @param model
@@ -591,6 +602,7 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
591
602
const self = this ;
592
603
const props = self . getModelDefinition ( model ) . properties ;
593
604
605
+ const encryptedFields = this . getEncryptionFields ( this . getModelDefinition ( model ) )
594
606
const whereStmts = [ ] ;
595
607
for ( const key in where ) {
596
608
const stmt = new ParameterizedSQL ( '' , [ ] ) ;
@@ -631,7 +643,18 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
631
643
}
632
644
// eslint-disable one-var
633
645
let expression = where [ key ] ;
634
- const columnName = self . columnEscaped ( model , key ) ;
646
+ let columnName = self . columnEscaped ( model , key ) ;
647
+ if ( encryptedFields . includes ( key ) ) {
648
+ columnName = `convert_from(
649
+ decrypt_iv(
650
+ DECODE(${ key } ,'hex')::bytea,
651
+ decode('${ process . env . ENCRYPTION_HEX_KEY } ','hex')::bytea,
652
+ decode('${ process . env . ENCRYPTION_HEX_IV } ','hex')::bytea,
653
+ 'aes'
654
+ ),
655
+ 'utf8'
656
+ )`
657
+ }
635
658
// eslint-enable one-var
636
659
if ( expression === null || expression === undefined ) {
637
660
stmt . merge ( columnName + ' IS NULL' ) ;
0 commit comments