我有这样的事情:
x = OpenSSL::Digest::SHA512.new('test').digest
# "\xEE&\xB0\xDDJ\xF7\xE7I\xAA\x1A\x8E\xE3\xC1\n\xE9\x92?a\x89\x80w.G?\x88\x19\xA5\xD4\x94\x0E\r\xB2z\xC1\x85\xF8\xA0\xE1\xD5\xF8O\x88\xBC\x88\x7F\xD6{\x1472\xC3\x04\xCC_\xA9\xAD\x8EoW\xF5\x00(\xA8\xFF"
如何将 x 转换为 BigDecimal,或更具体的 DataMapper::Property::Decimal?所以我可以搜索它
class MyRecord
include DataMapper::Resource
property :id, Serial
property :amount, Decimal, precision: 156
end
DataMapper.finalize
DataMapper.auto_migrate!
x = OpenSSL::Digest::SHA512.new('test').digest
x = # convert to BigDecimal or DataMapper::Property::Decimal
y = MyRecord.new
y.amount = x
y.save
z = MyRecord.first(amount: x)
或者,如果没有捷径,存储这些值的正确类型是什么?因为 PostgreSQL 的字符串不能存储 NULL 字符