erleans / pgo

Erlang Postgres client and connection pool
Apache License 2.0
80 stars 16 forks source link

Insert json string into JSONB column #71

Closed lpil closed 1 year ago

lpil commented 1 year ago

Hello!

I have a JSON string that I wish to insert into a JSONB column directly rather than parse into a map to then be serialized again by pgo. Is this possible?

Thanks, Louis

tsloughter commented 1 year ago

That should work. The default is to just take whatever the user passes and assume it is json: https://github.com/tsloughter/pg_types/blob/master/src/pg_jsonb.erl#L21-L22

Only if you supply a json_config does it try to encode it, like application:set_env(pg_types, json_config, {jsone, [], [{keys, atom}]}),

lpil commented 1 year ago

Oh! I wonder what I did wrong. I'll have to try again and get back to you.

tsloughter commented 1 year ago

I noticed there is no test for this.. It only tests that encoding with jsone in pgo works, so I do need to add a test and maybe there is an issue :)

tsloughter commented 1 year ago

@lpil were you able to test this?

lpil commented 1 year ago

Not yet, sorry. My inbox is overloaded atm

lpil commented 1 year ago

It works! I don't know what my error was. I'll have to dig in and re-open if I work out the issue.