Drizzle Team

DT

Drizzle Team

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

Join

Many to many relationship using Turso

Hello I'm new to sql in general and I just followed and copy some codes through the documentation of turso and drizzle. I'm trying to make a many-to-many relation between drinks and ingredients. I want to know this is the correct way to do it?
No description

why does it work by sorting by false but not by true?

i am certain i have one of each and it works when on false but i dont get anything back when its on true even though i have 2 rows in the table with it true ```ts const results = await db.query.workouts.findMany({ orderBy: [desc(weights.id)],...

How to include all fields in partial select syntax

Hi, I'm trying to append the organization field using a leftjoin to the existing fields in contact like this: ``` const response = (await db .select({...

Multiple Schema | is not assignable to type 'PostgresJsDatabase'.

So guys, im trying to move to Drizzle so, i already have my database on postgres, and pull it to make its migration and schema using drizzle-kit here's my drizzle.config.ts...

dynamically insert either single object or array of objects breaking types

So here's 3 renditions of the same fn ```ts const insertFighterSolo = async (fighterInsertData: FighterInsert) => { return db.insert(fighters).values(fighterInsertData); }; ...

How to set a default value for column based on another column?

For example, if I had this schema: ```ts export const posts = sqliteTable({ id: integer("id").primaryKey(), title: text("title"),...

Help with proper types (values)

I've been working to try to get a dynamic method to related/unrelate records together on a join table ```ts async linkEntities<TJoinTable extends Table>(...
No description

Am I doing it right ?

1) I wanted to get the native sql query result typed. I used the following code. ```ts type LimitedBoardDataVO = Pick<typeof noticeBoard.$inferSelect, 'id' | 'title' | 'content'>...

Type cannot be inferred when using returning on insert

I have this function and it is causing typescript errors ``` export async function inviteUsers(data: z.infer<typeof sendInvitesValidator>) { const res = await db...

get drizzle to correctly infer type with limit 1

If you do something simple like this: ```ts const user = await db .select() .from(users)...

How to use drizzle as a sql builder?

I want to use drizzle with planet scale. Sadly for mysql drizzle does not support the returning function (although databasejs returns e.g the insertedId after an insert statement). Anyways I would be more than happy to just use drizzle as a SQL builder so I can pass the SQL to planet scale through databasejs. Any ideas how to achieve that? Awesome library by far, keep up the great work!

How to make sql.placeholder() type safe

I have the following prepared statement: ``` export const listDeployments = db .select()...

drizzle-kit tsconfig.json paths alias

Not a drizzle issue per-se, but running into an issue trying to make drizzle-kit work again by changing target to esnext. The database schema file references some other files using an alias defined in the tsconfig.json. Any advice on getting drizzle-kit to recognize this setting? ```json "compilerOptions": { "target": "esnext",...

how to set default null to an int column

I want the parentId to have the default Null, how to do that ``` export const comments = mysqlTable( 'comments',...

Can't run drizzle-kit push:pg - error: column is in a primary key

Hi,
I get this error every time i run push:pg error: column "userId" is in a primary key at Parser.parseErrorMessage (/Users/victormesquita/Documents/Projects/MobiData/node_modules/drizzle-kit/index.cjs:40722:98)...

Best way to get raw SQL for a SQLite insert statement (with inline parameters)?

I tried doing this: ``` class InlineSQLiteSyncDialect extends SQLiteSyncDialect { public inlineParams = true; }...

id on transaction conflict

hey all, using mysql (planetscale). when a transaction conflict happens over an insert with the same 'serial' id i believe that mysql will resolve this by changing one of the inserts to the next available. my concern is that within a transaction i want to reference the returned id to use as a reference. will this id match the 'new' id after the conflict has resolved, or will it reference the original? here is some code to better explain maybe: ```ts...

Select Entry in db with relational tables

Hi, i'm using this request to get a store corresponding to the cuid, an di want to get also all his related categories from store_categories tabe ```js const result = await db.select() .from(stores) .where(eq(stores.cuid_store, cuid_store))...
No description

environment variables undefined in drizzle.config.ts

I have my config set up like this: ```ts import { type Config } from "drizzle-kit"; if (!process.env.DATABASE_URL) {...