Drizzle Team

DT

Drizzle Team

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

Join

Studio when using Turso `Error: Cannot find module 'better-sqlite3'`

Error when trying to start Studio and push Error: Cannot find module 'better-sqlite3'...

[BUG]: React Hook Form doesn't submit when using drizzle-zod to create schemes to use in zodResolver

When using drizzle-zod to generate schemas from database schemas and using them in the useForm resolvers the onSubmit won't fire at all for some reason, So for example: ```ts...

Appending SQL chunks to a query

Hey everyone, I'm trying to see if there is a way where I can build SQL queries conditionally (based on some search params I get)

Postgresjs with Neon giving connnection refusal error

I am unable to connect to my neon database. I tried using postgresjs and the neon serverless drivers. Still no luck 🙂...
No description

error: column "id" cannot be cast automatically to type uuid

im using drizzle, and this is my schema: ```typescript export const tags = pgTable("tags", { id: uuid("id").defaultRandom().primaryKey(), tag: text("tag").notNull(),...
No description

inArray() using sql`` operator in JS and Postgres

Hey, how do I use sql operator with arrays in JS?
const array = [1,2,3];
const sqlQuery = sql`${users.id} IN ???`;
const array = [1,2,3];
const sqlQuery = sql`${users.id} IN ???`;
...

Unable to infer relation

I have the following tables and relations: ```javascript export const platforms = pgTable('platforms', { id: serial('id').primaryKey(), name: text('name').notNull().unique(),...

migrate with node-postgres

I had migration working well with postgresjs but need to switch to node-postgres for other reasons. But I can't get migration to work and it just hangs. The code I have is: ``` import { drizzle } from "drizzle-orm/node-postgres"; import { migrate } from "drizzle-orm/node-postgres/migrator"; import * as schema from "~/db/schema";...

.all() API not available

I have two tables that I want to join, and I want to join them to get the following result: ```javascript type Result = { platform: Platform founders Founder[]...

Get subquery columns in a way similar to `getTableColumns`

Keeping track manually of all subquery fields can quickly become annoying, and I'm looking for a simple helper to allow specifying fields with a pattern similar to what getTableColumns enables. Has anyone implemented a small helper that's somewhat "battle-tested"? Here's what I have at the moment, but I'm not trusting it that much due to how naive it is and due to the necessary typecasting. ```ts export function getSubqueryColumns<S extends ColumnsSelection, A extends string>( query: WithSubqueryWithSelection<S, A> | SubqueryWithSelection<S, A>...

Slow queries with relationships

Hi all, I recently moved from querying 4 tables concurrently, to using drizzle relations and using db.query. I really like using the query, but I've seen a massive increase in query latency on my planetscale dashboard. Is this to be expected? Side note, while I haven't done much profiling, I haven't noticed much of a change in my server response time (I'm using this query inside a nextjs server component). Here is my new query: ``` return db.query.usersTable.findFirst({...
No description

Cannot read properties of undefined (reading 'referencedTable')

const result = await db.query.ads.findMany({ with: { owner: true, }, })...

How do I load sqlite extensions for drizzle-kit?

In my code, when I want to use drizzle I am doing the following: ```ts const sqlite = new SQLite3(env.DATABASE_PATH); // enable WAL mode...

Has anyone implemented transactions with Cloudflare D1 and Drizzle?

Hi guys! As stated in the title, I’m trying to use Drizzle and D1 to build my app, and it requires transactions. I’m also using tRPC. I was surprised when I saw that my queries didn’t work in prod because of transactions. After reading Cloudflare’s blog, I learned that you need to create a procedure and use it within your API....

drizzle studio doesnt work with default link

i get a blank page if i do drizzle-kit studio on http://0.0.0.0:4983/ only works if i use drizzle-kit studio --host 127.0.0.1 thought i should share that...

How to Access an array of strings in jsonb format

I am trying to find records where slug (predefined variable) is found in an array in my jsonb players column. The value looks like this: ['John', 'James', 'Joe', 'Jack'] If slug = John then this should return the record....

magical operator sql`` is faster than query/select?

im not sure, that i did it correct, but i deice to fetch with different ways specific talbes, and make kinda banchmarks with console.time/timeEnd and saw a lot of different in this sql``:0.361ms average query: 1.532ms average select:0.981ms average ...

Unable to run migrations

I have this small script I'm running to perform the db migrations: ```ts import { migrate } from "drizzle-orm/vercel-postgres/migrator";...

Does throwing an error in a TX automatically rollback?

From what I read in a similar post, it seems that a failed query within a transaction will automatically rollback the entire transaction. I am curious if this applies to any error that causes the transaction to return a rejected promise? For instance, I am using drizzle-valibot to ensure the values inserted within a transaction match the schema. If it doesn't match, can I just throw new Error() causing a rollback for the entire transaction?

How to combine queries from 2 tables?

I feel dumb asking this question... So I have 2 queries which looks like this: ```js // guranteed to have 1 entry const result1 = await db.select().from(Table1).where(condition1);...