sqlite DEFAULT is not JSON-encoded

When using text("...", { mode: "json" }) with .default(), the default value is not JSON encoded leading to invalid SQL generation by drizzle-kit.
import { sqliteTable, text } from "drizzle-orm/sqlite-core";

export const table = sqliteTable("table", {
row: text("row", { mode: "json" }).$type<string>().default("")
})
import { sqliteTable, text } from "drizzle-orm/sqlite-core";

export const table = sqliteTable("table", {
row: text("row", { mode: "json" }).$type<string>().default("")
})
generates:
CREATE TABLE `table` (
`row` text DEFAULT ''
);
CREATE TABLE `table` (
`row` text DEFAULT ''
);
(should be '""' instead) Using an empty array .$type<string[]>().default([]) generates nothing:
CREATE TABLE `table` (
`row` text DEFAULT
);
CREATE TABLE `table` (
`row` text DEFAULT
);
(should be '[]')
3 Replies
Angelelz
Angelelz11mo ago
We need to improve the interface of the .default function. You can't use a JavaScript array there, you are suppose to use SQL.
ShiroDev
ShiroDevOP11mo ago
The types disagree a bit there, .$type<string[]>().default("[]") is a type error The sql templating function is required here for typescript to not scream at me
Angelelz
Angelelz11mo ago
Yes, you would need the sql operator
Want results from more Discord servers?
Add your server