我有一个使用Lockbox的加密列:amount
,我需要在控制器中对其求和。
目前,我有-
transaction_controller.rb
@one_month_transactions_sum = transactions.where(transaction_date: 1.month.ago..Date.today).sum(:amount).abs()
这给出了error - PG::UndefinedColumn: ERROR: column "amount" does not exist LINE 1: SELECT SUM(amount) FROM "transactions" WHERE "transactions"....
,这是有意义的,因为我要求rails对我更改为密文的列使用PG SUM函数。
如何将控制器级别的事务与加密列相加?
发布于 2021-10-11 06:40:58
如果您将数据作为不透明的二进制blobs发送到数据库,您(自然)将失去在数据库中直接操作这些字段的能力。看起来你唯一的选择就是将加密值提取到应用程序中,解密,然后用ruby (慢慢地)求和。我还没有尝试过这个特定的库,但我猜这样的库应该可以工作:
transactions.where(...).map(&:amount).sum
https://stackoverflow.com/questions/69527592
复制相似问题