Closed afg419 closed 6 months ago
That is, both of these work:
await kysely.insertInto('myTable').values({ address: { street: '111 First Ave', zip: '00000', state: 'MA' }}).executeTakeFirst()
await kysely.insertInto('myTable').values({ address: JSON.stringify({ street: '111 First Ave', zip: '00000', state: 'MA' })}).executeTakeFirst()
I came here to post this exact issue. I changed the generated types and it works flawlessly (at least for insertion).
In fact, it works better than inserting a string because (at least in JS/TS) stringifying an object escapes the double quotes, therefore taking up significantly more space than needed. I wouldn't be surprised if that also causes us to lose the SQL optimizations and indexing abilities.
In essence, I echo the OP
Pushed a PR, I'm expecting that to work. @RobinBlomberg would love a 👍🏼!
If I'm not mistaken, the generated json type
type Json = ColumnType<JsonValue, string, string>
seems to be overly restrictive for Postgres, as I can use kysely to insert and updateJsonValue
values, in addition to strings. SinceJsonValue | string
is justJsonValue
, the whole thing can be collapsedtype Json = JsonValue
.Upvote & Fund