【问题标题】:Datamapper TEXT limited to 65k characters by default — how to raise the limit?Datamapper TEXT 默认限制为 65k 个字符 - 如何提高限​​制?
【发布时间】:2012-09-03 17:46:09
【问题描述】:

我有一个类需要包含最多约 300k 个字符的 TEXT,并且它存储在 PostgreSQL 数据库中。

Postgres 本身对兆字节 blob 没有问题,(最终我会将它们存储在 S3 中),但 Datamapper 对 TEXT 有“65k 个字符”的默认限制:

默认情况下,DataMapper 支持以下原始类型:

  • TrueClass,布尔值
  • 字符串
  • 文本(默认限制为 65k 个字符)

我想做类似的事情

property :id,                     Serial
property :name,                   String, :index => true         
property :posted,                 DateTime
property :info,                   DataMapper::Types::Text, :lazy => false
property :data,                   DataMapper::Types::Text, :limit => 500000 # needs to be big is :limit correct?5

我知道惰性部分没问题,因为我是从http://datamapper.rubyforge.org/dm-core/DataMapper/Property.html 得到的——但是用于覆盖 TEXT 字段限制的关键字是什么:

  • :length?
  • :maximum?
  • :limit?

还是别的什么?

【问题讨论】:

  • 可能默认最大值就是最大最大值;你只能降低限制?试试:length => 32768看看有没有效果...
  • 我一开始以为 :length 不起作用,但它确实起作用了。

标签: ruby postgresql heroku sinatra datamapper


【解决方案1】:

好的,

原来 :length 确实有效。

class SomeClass
  include DataMapper::Resource

  property :id,                     Serial
  property :name,                   String, :index => true         # strings are actively loaded 
  property :posted,                 DateTime
  property :info,                   Text, :lazy => false # This is short stuff a hundred or so bytes long that I want loaded 
  property :data,                   Text, :length => 500000 # Text is lazy loaded by default, but I also need to override the default length limit which is 65536 chars in DM

【讨论】:

  • 但是:length => nil 能完全摆脱限制吗?
  • length: nil 不适用于 DataMapper。你得到错误ArgumentError: +options[:length]+ should be Range or Integer, but was NilClassgithub.com/datamapper/dm-types/issues/29
猜你喜欢
  • 2015-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-29
  • 2023-03-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多