default to empty object for sqlite text field with JSON mode

How can I default a mode: 'json' text type to an empty object in sqlite? The following in a sqliteTable definition results in a literal string of ([object Object]):
data: text('data', { mode: 'json' }).notNull().default({}),
data: text('data', { mode: 'json' }).notNull().default({}),
Empty arrays are discussed here, but not empty objects: https://orm.drizzle.team/learn/guides/empty-array-default-value#sqlite Using default(sql'{}') (with backticks around the single quotes, I can't get the to show up in Discord markdown) or default('{}') defaults it to a literal '{}', and querying that gives an error:
SyntaxError: Unexpected token ''', "'{}'" is not valid JSON
at JSON.parse (<anonymous>)
at SQLiteTextJson.mapFromDriverValue
SyntaxError: Unexpected token ''', "'{}'" is not valid JSON
at JSON.parse (<anonymous>)
at SQLiteTextJson.mapFromDriverValue
I'm using drizzle-orm": v0.30.9 and Turso/libsql.
Drizzle ORM - Empty array as a default value
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server