Sqlite JSON
Hello,
I'm a new user to Kysely and I'm having trouble using the JSON interface. I would normally just
stringify
and parse
JSON myself when using Kysely, but it looks like I can addColumn("myColumn", "json")
. However, when I try to insert values as JSON, I get TypeError: SQLite3 can only bind numbers, strings, bigints, buffers, and null
.
If I strigify
my JSON first, it adds to the database properly, but the Kysely gives me type errors. Should I have my Database
table column of type string
when I am passing type "json" to Kysely?4 Replies
Right now, I have
Also, having a similar issue with dates... I am telling Kysely that the column is to be of type "date", so I expect it to parse my dates before and after database retreival. But, it appears that I must stringify and parse them myself.
Solution
Hey 👋🏻
Try using:
https://kyse.link/?p=s&i=yHizR2sNwRixkL6M2Fxc
---
Kysely can support different types for select, insert and update queries.
JSONColumnType<T>
is a shorthand for ColumnType<T, string, string>
Thanks! That works.
Is there a similar date column type or must I use
ColumnType<Date, string, never>
?There isn't one, you should use what's available and make sure it's aligned with the underlying driver output.