How to declare postgresql json/jsonb field with sequel?

你离开我真会死。 提交于 2019-12-13 08:40:08

问题


I'm stuck with that. Can't find anywhere in docs how to declare such spatial data types as inet and jsonb or json.

ruby 2.4.1, sequel 4.47

Plain ruby script with require 'sequel'.

Declaration such as

DB.create_table :requests do
  primary_key :id
  foreign_key :client_id, :clients
  foreign_key :service_id, :services
  DateTime :created_at, null: false
  DateTime :answered_at, null: false
  JsonBType :request, null: false
end

回答1:


You can use the alternative way of defining columns by using the column method - details can be found here. In your example this becomes:

DB.create_table :requests do
  primary_key :id
  foreign_key :client_id, :clients
  foreign_key :service_id, :services
  DateTime :created_at, null: false
  DateTime :answered_at, null: false
  column :request, :jsonb, null: false
end


来源:https://stackoverflow.com/questions/44784259/how-to-declare-postgresql-json-jsonb-field-with-sequel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!