Search code examples
rubypostgresqlsequel

How to declare postgresql json/jsonb field with sequel?


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

Solution

  • 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