Thks now works great:
changed the Sequel.pg_json to pg_jsonb
but also was converting hash with .to_json but Sequel does that
automagically so just passing in the pure ruby hash as data worked fine
Sinatra + Postgres jsonb + Sequel => For The Win
On Tuesday, June 16, 2015 at 9:39:12 AM UTC-6, Jeremy Evans wrote:
>
> On Tuesday, June 16, 2015 at 8:16:49 AM UTC-7, Tiger Nassau wrote:
>>
>> not sure we have right syntax or understand how to use extension
>> table was created fine, but insert failed
>>
>> db.extension :pg_json
>> # added this after defining db
>>
>> db.run(" create table " + table +
>> "(id serial primary key, data jsonb)")
>> => works fine
>> Table "public.signups"
>> Column | Type | Modifiers
>> | Storage | Stats target | Description
>>
>> --------+---------+------------------------------------------------------+----------+--------------+-------------
>> id | integer | not null default nextval('signups_id_seq'::regclass)
>> | plain | |
>> data | jsonb |
>> | extended | |
>> Indexes:
>> "signups_pkey" PRIMARY KEY, btree (id)
>>
>>
>> puts data
>> db[:signups].insert(:data=>Sequel.pg_json(data))
>> {"full_name":"Jack Staff","organization":"Tiger
>> Nassau","product":"ibi","email":"[email protected] <javascript:>
>> ","postal_code":"59912","status":"1","created_at":"2015-06-12","updated_at":"2015-06-12"}
>> => correct input hash converted to json
>>
>> /var/lib/gems/2.1.0/gems/sequel-4.23.0/lib/sequel/extensions/pg_json.rb:281:in
>>
>> `pg_json': undefined method `pg_json_op' for Sequel:Module (NoMethodError)
>>
>> any ideas ?
>>
>
> What is data here? It looks like a Hash, but if it was a Hash, this should
> have worked. Is it an instance of some DelegateClass of Hash?
>
> The reason you get the error is if you pass an unsupported object to
> pg_json (not a Hash or Array or Sequel::Postgres::JSON* object), it assumes
> you want to create a JSONOp object, but that requires loading the
> pg_json_ops extension, which you haven't done, so you get the undefined
> method.
>
> Also, if you are dealing with jsonb columns, you should probably use
> Sequel.pg_jsonb instead of Sequel.pg_json.
>
> Thanks,
> Jeremy
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.