@@ -100,6 +100,7 @@ PostgreSQL.prototype.connect = function(callback) {
100
100
self . client = client ;
101
101
process . nextTick ( releaseCb ) ;
102
102
callback && callback ( err , client ) ;
103
+ if ( ! err ) self . execute ( 'CREATE EXTENSION IF NOT EXISTS pgcrypto' , function ( createExtensionError ) { } ) ;
103
104
} ) ;
104
105
} ;
105
106
@@ -574,15 +575,15 @@ PostgreSQL.prototype.buildWhere = function(model, where) {
574
575
} ;
575
576
576
577
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
- }
578
+ if ( modelDefinition
579
+ && modelDefinition . settings
580
+ && modelDefinition . settings . mixins
581
+ && modelDefinition . settings . mixins . Encryption
582
+ && modelDefinition . settings . mixins . Encryption . fields ) {
583
+ return modelDefinition . settings . mixins . Encryption . fields ;
584
+ }
585
+ return [ ] ;
586
+ } ;
586
587
587
588
/**
588
589
* @private
@@ -602,7 +603,7 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
602
603
const self = this ;
603
604
const props = self . getModelDefinition ( model ) . properties ;
604
605
605
- const encryptedFields = this . getEncryptionFields ( this . getModelDefinition ( model ) )
606
+ const encryptedFields = this . getEncryptionFields ( this . getModelDefinition ( model ) ) ;
606
607
const whereStmts = [ ] ;
607
608
for ( const key in where ) {
608
609
const stmt = new ParameterizedSQL ( '' , [ ] ) ;
@@ -644,16 +645,16 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
644
645
// eslint-disable one-var
645
646
let expression = where [ key ] ;
646
647
let columnName = self . columnEscaped ( model , key ) ;
647
- if ( encryptedFields . includes ( key ) ) {
648
+ if ( encryptedFields . includes ( key ) ) {
648
649
columnName = `convert_from(
649
650
decrypt_iv(
650
651
DECODE(${ key } ,'hex')::bytea,
651
652
decode('${ process . env . ENCRYPTION_HEX_KEY } ','hex')::bytea,
652
- decode('${ process . env . ENCRYPTION_HEX_IV } ','hex')::bytea,
653
+ decode('${ process . env . ENCRYPTION_HEX_IV } ','hex')::bytea,
653
654
'aes'
654
655
),
655
656
'utf8'
656
- )`
657
+ )` ;
657
658
}
658
659
// eslint-enable one-var
659
660
if ( expression === null || expression === undefined ) {
0 commit comments