@@ -100,6 +100,7 @@ PostgreSQL.prototype.connect = function(callback) {
100100 self . client = client ;
101101 process . nextTick ( releaseCb ) ;
102102 callback && callback ( err , client ) ;
103+ if ( ! err ) self . execute ( 'CREATE EXTENSION IF NOT EXISTS pgcrypto' , function ( createExtensionError ) { } ) ;
103104 } ) ;
104105} ;
105106
@@ -574,15 +575,15 @@ PostgreSQL.prototype.buildWhere = function(model, where) {
574575} ;
575576
576577PostgreSQL . 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+ } ;
586587
587588/**
588589 * @private
@@ -602,7 +603,7 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
602603 const self = this ;
603604 const props = self . getModelDefinition ( model ) . properties ;
604605
605- const encryptedFields = this . getEncryptionFields ( this . getModelDefinition ( model ) )
606+ const encryptedFields = this . getEncryptionFields ( this . getModelDefinition ( model ) ) ;
606607 const whereStmts = [ ] ;
607608 for ( const key in where ) {
608609 const stmt = new ParameterizedSQL ( '' , [ ] ) ;
@@ -644,16 +645,16 @@ PostgreSQL.prototype._buildWhere = function(model, where) {
644645 // eslint-disable one-var
645646 let expression = where [ key ] ;
646647 let columnName = self . columnEscaped ( model , key ) ;
647- if ( encryptedFields . includes ( key ) ) {
648+ if ( encryptedFields . includes ( key ) ) {
648649 columnName = `convert_from(
649650 decrypt_iv(
650651 DECODE(${ key } ,'hex')::bytea,
651652 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,
653654 'aes'
654655 ),
655656 'utf8'
656- )`
657+ )` ;
657658 }
658659 // eslint-enable one-var
659660 if ( expression === null || expression === undefined ) {
0 commit comments