joostschuur
DTDrizzle Team
•Created by joostschuur on 5/15/2024 in #help
Defining types for default values in createSelectSchema
In my users table schema for a Turso DB, I've got a field of
settings: text('settings', { mode: 'json' })
. I'd like to define the defaults outside of the schema definition, so this doesn't potentially change the database and require a migration when I need new setting values, but I also want to type this field in my app.
So I have a userSettingsSchema and want to set the default via createSelectSchema's options:
However, under UserData, settings is still null or my UserSettings type. Wouldn't my userDataSchemaOptions
have narrowed that down?
It looks like I can force it more explicitly like this:
1 replies
DTDrizzle Team
•Created by joostschuur on 4/26/2024 in #help
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])
:
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:
I'm using drizzle-orm": v0.30.9 and Turso/libsql.1 replies
DTDrizzle Team
•Created by joostschuur on 3/14/2024 in #help
Error: Cannot find module '@libsql/darwin-arm64' when using Drizzle/SST
I'm using SST in a monorepo with Drizzle, and my Drizzle setup is in a separate workspace package.
When I try calling code that invokes the Drizzle client I get this error about missing a platform specific module:
This from this API handler in
apps/backend
:
With db
being exported from packages/database
here:
packages/database
has @libsql/client
as a dependency, nothing platform specific.
If I explicitly add @libsql/darwin-arm64
as a dependency to apps/backend
, then that works for local dev. When I deploy it, it complains about @libsql/linux-x64-gnu
of course, but this should just work without a hack like that, right?
I have a Next.js app running on Vercel (for now) also importing the database package and that works just fine.3 replies
DTDrizzle Team
•Created by joostschuur on 2/13/2024 in #help
Using Drizzle SQLite in a Next.js server component gives error that suggests client side execution
I attempted to do a basic implementation in a Next.js 14.1 app using Drizzle (v0.29.3) and @libsql/client (v0.4.3) based on https://orm.drizzle.team/docs/get-started-sqlite#turso and get the following error on my local machine when I start
next dev
.
26 replies
DTDrizzle Team
•Created by joostschuur on 9/9/2023 in #help
Updating with a subquery
Can I do this in Drizzle without the raw SQL?
34 replies
DTDrizzle Team
•Created by joostschuur on 5/6/2023 in #help
Using Vercel Postgres and developing locally
To confirm, if I want to use Vercel Postgres in production and a local Postgres DB for development, is the best way to just conditionally import
drizzle
(and other platform specific stuff like sql
) from drizzle-orm/vercel-postgres
or drizzle-orm/node-postgres
based on NODE_ENV
?
I see the sample Next.js project has been updated for Vercel Postgres: https://github.com/vercel/examples/blob/main/storage/postgres-drizzle/lib/drizzle.ts65 replies