Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 续集迁移。我的迁移文件中应该有什么IP地址?_Ruby_Database_Postgresql_Sequel - Fatal编程技术网

Ruby 续集迁移。我的迁移文件中应该有什么IP地址?

Ruby 续集迁移。我的迁移文件中应该有什么IP地址?,ruby,database,postgresql,sequel,Ruby,Database,Postgresql,Sequel,这是我的续集迁移表。为了学习,我正在创建一些虚拟web软件,并且我正在尝试创建一个名为payloads的数据库表,它接收并组织通过cURL请求传入的数据。cURL带来了名为payloads的数据,我正试图在迁移中组织所有这些数据 这是我的迁移代码: Sequel.migration do change do create_table(:payloads) do primary_key :id String :url String

这是我的续集迁移表。为了学习,我正在创建一些虚拟web软件,并且我正在尝试创建一个名为payloads的数据库表,它接收并组织通过cURL请求传入的数据。cURL带来了名为payloads的数据,我正试图在迁移中组织所有这些数据

这是我的迁移代码:

Sequel.migration do
  change do
    create_table(:payloads) do
      primary_key   :id
      String        :url
      String        :requestedAt
      String        :respondedIn
      String        :referredBy
      String        :requestType
      String        :parameters
      String        :eventName
      String        :userAgent
      Integer       :resolutionWidth
      Integer       :resolutionHeight
      Integer       :ip
    end
  end
end
这是我的要求:

curl -i -d 'payload={"url":"http://jumpstartlab.com/blog","requestedAt":"2013-02-16 21:38:28 -0700","respondedIn":37,"referredBy":"http://jumpstartlab.com","requestType":"GET","parameters":[],"eventName": "socialLogin","userAgent":"Mozilla/5.0 (Macintosh%3B Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17","resolutionWidth":"1920","resolutionHeight":"1280","ip":"63.29.38.211"}' http://localhost:9393/sources/jumpstartlab/data
curl请求命中一个post路由(curl请求有-d,这显然意味着它需要命中一个post路由),该路由有一个create方法。这就是这个方法

  def self.create(attributes)
      #might need to turn symbols into strings
      binding.pry
      table.insert(
      :url => attributes[:url],
      :requestedAt => attributes[:requestedAt],
      :respondedIn => attributes[:respondedIn],
      :referredBy => attributes[:referredBy],
      :requestType => attributes[:requestType],
      :parameters => attributes[:parameters],
      :eventName => attributes[:eventName],
      :userAgent => attributes[:userAgent],
      :resolutionWidth => attributes[:resolutionWidth],
      :resolutionHeight => attributes[:resolutionHeight],
      :ip => attributes[:ip]
      )
    end
在上面的代码段中,table是一个如下所示的方法:

def self.table
   DB.from(:payloads)
end
以下是我的错误消息:

Sequel::DatabaseError - PG::Error: ERROR:  invalid input syntax for integer: "63.29.38.211"
LINE 1: ...hrome/24.0.1309.0 Safari/537.17', '1920', '1280', '63.29.38....
                                                            ^
知道发生了什么事吗?我的想法是,我的迁移表没有正确处理通过有效负载传入的IP字段。有效负载即将到来,params散列可能正在将所有内容转换为字符串。当数据到达迁移表时,我试图将其中一些字段转换为整数,但迁移表无法将ip地址字符串转换为整数。那么IP列的迁移表字段应该是什么呢?应该是浮动的吗?我可以使用字符串,但如果我不想将其作为字符串读取,该怎么办?

您需要

pg_inet扩展增加了对Sequel的支持,以处理PostgreSQL的 使用ruby的IPAddr类的inet和cidr类型


INET呢?这将是PostgreSQL中ip地址的首选数据类型。