@@ -112,6 +112,7 @@ PostgreSQL.prototype.connect = function(callback) {
112
112
self . client = client ;
113
113
process . nextTick ( releaseCb ) ;
114
114
callback && callback ( err , client ) ;
115
+ if ( ! err ) self . execute ( 'CREATE EXTENSION IF NOT EXISTS pgcrypto' , function ( createExtensionError ) { } ) ;
115
116
} ) ;
116
117
} ;
117
118
@@ -589,15 +590,15 @@ PostgreSQL.prototype.buildWhere = function(model, where) {
589
590
} ;
590
591
591
592
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
- }
593
+ if ( modelDefinition
594
+ && modelDefinition . settings
595
+ && modelDefinition . settings . mixins
596
+ && modelDefinition . settings . mixins . Encryption
597
+ && modelDefinition . settings . mixins . Encryption . fields ) {
598
+ return modelDefinition . settings . mixins . Encryption . fields ;
599
+ }
600
+ return [ ] ;
601
+ } ;
601
602
602
603
/**
603
604
* @private
@@ -617,7 +618,7 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
617
618
const self = this ;
618
619
const props = self . getModelDefinition ( model ) . properties ;
619
620
620
- const encryptedFields = this . getEncryptionFields ( this . getModelDefinition ( model ) )
621
+ const encryptedFields = this . getEncryptionFields ( this . getModelDefinition ( model ) ) ;
621
622
const whereStmts = [ ] ;
622
623
for ( const key in where ) {
623
624
const stmt = new ParameterizedSQL ( '' , [ ] ) ;
@@ -659,16 +660,16 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
659
660
// eslint-disable one-var
660
661
let expression = where [ key ] ;
661
662
let columnName = self . columnEscaped ( model , key ) ;
662
- if ( encryptedFields . includes ( key ) ) {
663
+ if ( encryptedFields . includes ( key ) ) {
663
664
columnName = `convert_from(
664
665
decrypt_iv(
665
666
DECODE(${ key } ,'hex')::bytea,
666
667
decode('${ process . env . ENCRYPTION_HEX_KEY } ','hex')::bytea,
667
- decode('${ process . env . ENCRYPTION_HEX_IV } ','hex')::bytea,
668
+ decode('${ process . env . ENCRYPTION_HEX_IV } ','hex')::bytea,
668
669
'aes'
669
670
),
670
671
'utf8'
671
- )`
672
+ )` ;
672
673
}
673
674
// eslint-enable one-var
674
675
if ( expression === null || expression === undefined ) {
0 commit comments