Drizzle Team

DT

Drizzle Team

The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!

Join

Dropping tables using Drizzle studio extension on planet scale

Can I drop tables by accident on production branches on PlanetScale while using the studio extension? I am afraid to test it.. for obvious reasons 😄 - https://chromewebstore.google.com/detail/mjkojjodijpaneehkgmeckeljgkimnmd...

How to use findMany() with distinct column values?

Hi Everyone 🙂 I’m using the findMany() query in my project to retrieve the latest records from an SQLite (libsql) database: ```ts export const getLatestRecords = db.query.Record.findMany({...

Drizzle Studio "unknown is not defined"

Is drizzle studio broken at the moment? None of the queries in drizzle runner work. I keep getting: { "status": "error", "error": "unknown is not defined"...

Parsing Postgres array

Trying to parse a Postgres array coming back like this: {ditchrider,ditchrider,ditchrider}. This is my query: ```ts db .select({ userRole: user.role,...

How to convert filters (e.g. eq(), ne(), lte(), like()) into SQL string, for use in sql.raw()

I'm trying to use LEFT JOIN LATERAL, but I have a lot of filters already created with drizzle. I would like to use them in my SQL: ``typescript const query = sql.raw(SELECT user.id, message.received_at FROM user LEFT JOIN LATERAL (SELECT message.user_id, message.received_at FROM message WHERE message.user_id = user.id ORDER BY message.received_at LIMIT 1) message on user.id=message.user_id); // TODO use other filters too: AND ${filtersExceptTime?.getSQL()}` doesn't work ...

How to test the connection & cleanup on shutdown

I'm using drizzle in an express server, I have cleanup code listening for SIGTERM and SIGINT that will close the server, how can I tell drizzle to close all the connections to the database? And while I'm at it I would like to test the connection as soon as the server starts, because we are using AWS managed database. I would like to know if I can connect from this server to the database, if not then there is no point in running the server.

allow passing undefined to limit

The 0.32.1 release (https://github.com/drizzle-team/drizzle-orm/releases/tag/0.32.1) added support for limit 0 in all dialects... However, in some cases i used "0" as a fallback for "do not apply limit" (as if limit was undefined, which is not allowed currently) Pointed out as workaround in this issue: https://github.com/drizzle-team/drizzle-orm/issues/728#issuecomment-1581806431 Is there some other way to define the .limit(limitNum) where limit is only applied if limit is defined?...

Drizzle Query Returns Different Result Than Select

Made a issue over on github for this, and wanted to see if anyone has ran into anything similar. Thanks! https://github.com/drizzle-team/drizzle-orm/issues/2703...

How can we get all tables names

So i want to get all tables names i have in my schema.ts found this https://orm.drizzle.team/docs/goodies#get-table-information but it doesnt fit my use case...

Is it possible to create table during runtime?

I'm are trying to create a multi tenant application for my service. However, i'm unable to find relevant information on whether or not creating table during runtime is possible or not. The goal here would be to simply create new tables for a newly added tenant. The tables always have the same schema. My strategy is to simply suffix the newly created tables with a tenantId string...

filter basesd query not working

Like I am trying to make a base query and than on that I want to apply filter asked by the request. Now for some reason the rating related filter gives me error. And generally is the way how I am doing it correct or is there way for filter or queries because thats just simple example and this will become much complexer
No description

Database won't update

Hi. I made some changes to my schema and run commands drizzle-kit generate and migrate. There were no errors, but schema (in studio at least) did not change. I tried with push command, which did ask me some question what fields I want to keep etc. But there is still old schema in studio (and also my new columns are not recognized by vs code). What should I do?...

error: relation "session" does not exist

I am getting this below error, also, I'm not getting anything generated in the migrations folder! ```tsx error: relation "session" does not exist...
No description

Getting 'error: write CONNECTION_CLOSED' when trying to seed with stream-json from a 100MB file

I've run into a problem when trying to utilize a stream to load my data to my DB. All of my other seeds are working but this one encounters the connection error. I'm leveraging the stream-json package with drizzle-orm and postgres-js to stream single json objects in an effort to handle a larger than 100 MB JSON file. The seed function I wrote is as follows:...

Getting SQLITE Constraint error with `foreign_keys off`

All I'm doing is dropping default fields from the tables. I had recently learned about PRAGMA foreign_key=off thing and had previously been manually moving over children tables every migration 💀 . But this non-cursed way seems to not work as expected as I'm running into foreign key constraint check. Any help would be greatly appreciated. Below is the generated sql file and I'm using Turso. ```sql PRAGMA foreign_keys=off; --> statement-breakpoint...

Confused about onConflictDoUpdate when having a constraint

I have a table that looks like ```ts export const weeklyFinalRankings = pgTable( 'weekly_final_rankings', {...

drizzle-kit should use `peerDependencies` instead of bundling dependencies

In addition to the .env loading issue for local development, I see that drizzle-kit has bundled a bunch of drivers into its own executable instead of using peerDependencies. This makes it impossible to override neonConfig settings so I can use a local wsproxy for local development since drizzle-kit is using an entirely separate and unexported copy of @vercel/postgres and @neondatabase/serverless. There should either be a way to configure settings on the bundled copy @neondatabase/serverless or a way to use peerDependencies to dedupe drivers so that we can override settings on the same instance that drizzle-kit uses....

drizzle-kit overriding `process.env` before `@next/env` can load values

I'm trying to use drizzle-kit push using the setup recommended by the Drizzle and Vercel docs, but I am finding that the drizzle-kit command is performing its own dotenv loading before my config file can import and use loadEnvConfig from @next/env. This is causing issues if I have an empty value for POSTGRES_URL in .env (for documentation purposes) and the actual value in .env.local (for local development) because drizzle-kit is unaware of how @next/env loads environment variables. I've worked around this issue by setting by setting DOTENV_CONFIG_PATH=/dev/null, but there should a way to turn this automatic behavior off (or more ideally, make it opt-in instead of opt-out) so it is easier to load environment variables correctly using @next/env or another .env loader of choice....

sqlite create new db file push programatically

Hi, I'm using better-sqlite3 with drizzle in my electron project and for my use case, I have some binary format data that my app can read, and I'd like to make an export to a new sqlite .db file. I have the schemas and everything set up but I want to take the db file path from user input and just create new one on the spot and fill it with data. Is there a way to push my schema to this db file programatically just like drizzle-kit push does normally?

withPagination type inference

Looking for help as to why my types on this withPagination function are not getting inferred correctly. Data does on the PaginatedResult does not get full inferred at the top level. pagination.ts ```typescript import type { PgSelect } from 'drizzle-orm/pg-core'...