generalpiston / typeorm-encrypted

Encrypted field for typeorm.
MIT License
74 stars 19 forks source link

Exception occurres when use FindOperator. #42

Closed takezoux2 closed 2 years ago

takezoux2 commented 2 years ago

To use 'where in' clause, I execute next code. But TypeError is thrown. Are there any way to avoid this?

import { In } from "typeorm"

const repo = getRepository<XXX>()

await repo.find({
  where: {
    encryptedField: In(["aaa"])
  }
})

Error

TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of FindOperator

      at EncryptionTransformer.Object.<anonymous>.EncryptionTransformer.to (node_modules/typeorm-encrypted/src/transformer.ts:28:4)
      at Function.Object.<anonymous>.ApplyValueTransformers.transformTo (src/util/ApplyValueTransformers.ts:19:28)
      at ColumnMetadata.Object.<anonymous>.ColumnMetadata.getEntityValue (src/metadata/ColumnMetadata.ts:658:44)
      at SelectQueryBuilder.<anonymous> (src/query-builder/QueryBuilder.ts:1088:51)
      at step (node_modules/typeorm/node_modules/tslib/tslib.js:143:27)
      at Object.next (node_modules/typeorm/node_modules/tslib/tslib.js:124:57)
      at SelectQueryBuilder.Object.<anonymous>.QueryBuilder.getWhereCondition (src/query-builder/QueryBuilder.ts:1208:80)
      at SelectQueryBuilder.Object.<anonymous>.SelectQueryBuilder.where (src/query-builder/SelectQueryBuilder.ts:721:32)
generalpiston commented 2 years ago

IIRC the encryptedField can't be used in a complex query (including where clauses). The predicate is pushed down to the database. The field is encrypted in the database and will not be decrypted when evaluating the where clause.

You may want to use full database encryption.

generalpiston commented 2 years ago

https://github.com/generalpiston/typeorm-encrypted#why-wont-complex-queries-work

generalpiston commented 2 years ago

Thanks @takezoux2

generalpiston commented 2 years ago

Released in 0.6.0.