tusken
tusken copied to clipboard
Add `pg.json_to_record` support
Allow providing a schema object like so…
pg.json_to_record({ a: 1, b: '' }, { a: t.int, b: t.text }).as('row')
…that creates the following SQL…
json_to_record('{"a":1,"b":""}'::json) as row(a int, b text)
Would it make more sense to have .as be required and make the schema object as its 2nd argument?
pg.json_to_record({ a: 1, b: '' }).as('row', { a: t.int, b: t.text })
And of course, json_to_record should accept a string too. If passed an object, JSON.stringify is used implicitly.
pg.json_to_record('{ "a": 1, "b": "" }').as('row', { a: t.int, b: t.text })
Similarly, do the same for json_to_recordset.
pg.json_to_recordset([{ a: 1, b: '' }, ...]).as('row', { a: t.int, b: t.text })
…and the jsonb variants