略過內容 略過搜尋

自動擴充加密引數,以支援查詢已加密及未加密的資料

Active Record Encryption 支援使用決定性屬性查詢資料庫。例如

Contact.find_by(email_address: "jorge@hey.com")

值「jorge@hey.com」會自動加密,以執行查詢。但在資料加密的過程中,會產生一個問題。這無法運作。這時,你需要執行以下查詢:

Contact.find_by(email_address: [ "jorge@hey.com", "<encrypted jorge@hey.com>" ])

這個補丁套件針對 ActiveRecord 進行修改,以自動化支援此問題。這個補丁套件涵蓋了以下部分

如果「config.active_record.encryption.extend_queries」為 `true`,則包含此模組。

命名空間
方法
I

類別公共方法

install_support()

# File activerecord/lib/active_record/encryption/extended_deterministic_queries.rb, line 24
def self.install_support
  # ActiveRecord::Base relies on ActiveRecord::Relation (ActiveRecord::QueryMethods) but it does
  # some prepared statements caching. That's why we need to intercept +ActiveRecord::Base+ as soon
  # as it's invoked (so that the proper prepared statement is cached).
  ActiveRecord::Relation.prepend(RelationQueries)
  ActiveRecord::Base.include(CoreQueries)
  ActiveRecord::Encryption::EncryptedAttributeType.prepend(ExtendedEncryptableType)
end