KyselyK
Kysely3y ago
7 replies
marshymallow

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?
Solution
Hey 👋🏻

Try using:

import { JSONColumnType } from 'kysely'

interface MyTable {
  myColumn: JSONColumnType<Array<string>>,
}

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>
Was this page helpful?