@@ -588,6 +588,17 @@ PostgreSQL.prototype.buildWhere = function(model, where) {
588
588
return whereClause ;
589
589
} ;
590
590
591
+ PostgreSQL . prototype . getEncryptionFields = function ( modelDefinition ) {
592
+ if ( modelDefinition
593
+ && modelDefinition . settings
594
+ && modelDefinition . settings . mixins
595
+ && modelDefinition . settings . mixins . Encryption
596
+ && modelDefinition . settings . mixins . Encryption . fields ) {
597
+ return modelDefinition . settings . mixins . Encryption . fields
598
+ }
599
+ return [ ]
600
+ }
601
+
591
602
/**
592
603
* @private
593
604
* @param model
@@ -606,6 +617,7 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
606
617
const self = this ;
607
618
const props = self . getModelDefinition ( model ) . properties ;
608
619
620
+ const encryptedFields = this . getEncryptionFields ( this . getModelDefinition ( model ) )
609
621
const whereStmts = [ ] ;
610
622
for ( const key in where ) {
611
623
const stmt = new ParameterizedSQL ( '' , [ ] ) ;
@@ -646,7 +658,18 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
646
658
}
647
659
// eslint-disable one-var
648
660
let expression = where [ key ] ;
649
- const columnName = self . columnEscaped ( model , key ) ;
661
+ let columnName = self . columnEscaped ( model , key ) ;
662
+ if ( encryptedFields . includes ( key ) ) {
663
+ columnName = `convert_from(
664
+ decrypt_iv(
665
+ DECODE(${ key } ,'hex')::bytea,
666
+ decode('${ process . env . ENCRYPTION_HEX_KEY } ','hex')::bytea,
667
+ decode('${ process . env . ENCRYPTION_HEX_IV } ','hex')::bytea,
668
+ 'aes'
669
+ ),
670
+ 'utf8'
671
+ )`
672
+ }
650
673
// eslint-enable one-var
651
674
if ( expression === null || expression === undefined ) {
652
675
stmt . merge ( columnName + ' IS NULL' ) ;
0 commit comments