Drizzle Team

DT

Drizzle Team

Join the community to ask questions about Drizzle Team and get answers from other members.

Join Server
BB33fb0n34/9/2024

types for database/transaction

Hey, I have this function: ```tsx export const userRelationExists = async ( ...,...
BVBooboo v(=∩_∩=)フ4/9/2024

Wipe Neon Database

I need to know how to wipe it, and how to remove registerd tables. Because I am in my testing phase and I need to wipe and add tables, along with register new columns in said tables. But I am not able to, Help is much appreciated.
DDiamondDragon4/9/2024

toSQL() escapes quotes?

The verbose logger does not escape quotes, so you can copy this into a query editor. When you use toSQL() it doesn't, which if i'm not mistaken you can't copy directly?
No description
LBCLeonardo Barbosa - Creatus4/9/2024

Invalid drizzle query

I'm trying to run a search for tests using drizzle studio, but I'm getting this error: invalid drizzle query.
db.query.users.findMany();
db.query.users.findMany();
Schema...
Rreinaldyrfl4/9/2024

How do I execute raw query (with params already separated) with Drizzle?

Okay, so I've made my own query builder beforehand and I'm migrating away my code from raw postgres-js nature to Drizzle ORM (since I don't really want to parse stuff around anymore like what I would need to be doing with just raw postgres-js. On usual postgres-js, what I'd do is just:
await this.database.unsafe(query, params as never[]);
await this.database.unsafe(query, params as never[]);
In which query is a string and params is a unknown[]. I wanted to execute this with Drizzle, but I haven't find the right way to do so. Even using the sql template literals or even building my own implementation for SQLWrapper interface (source) doesn't seem right to me. Is there any other way for me to execute the code directly without drifting away from the drizzle db instance (that's wrapping the original postgres-js instance)?...
TtextYash4/9/2024

How to change schema without losing data?

I want to change my schema & add a new field hidden: boolean("hidden").notNull().default(false), My current schema looks like: ```ts id: serial('id').primaryKey(),...
MCMartin Carlsson4/9/2024

Is relationships only for .findMany() and .findFirst()

Is it correctly understood that relationships only works with .findMany() and .findFirst() and not with select, insert, update, and delete? In the documentation, that is the only examples I can find https://orm.drizzle.team/docs/rqb#declaring-relations...
VVinny4/8/2024

Using sql.placeholder with limit in creating a prepared query

I am attempting to create a prepared query like this... ``` const findByNamePrepared = this.database .select()...
HHeadless4/8/2024

Issues with NextJS + Turso + DrizzleORM + LuciaAuth

Hello! I am having issues. I recently have been using the planetscale related libs but since they are sunsetting their hobby tier I switched to turso. I changed all the schemas to match the correct types and whatnot. This is where I connect to my db ```ts...
Ttsuki4/8/2024

trying to create a trigger on supabase to calculate a winrate based on two other columns

hi all, tsuki here. i'm trying to create a trigger that fires before updates, that should calculate a win percentage based on my wins column and my losses column. the trigger is firing correctly, but it seems like it isn't correctly calculating the win percentage? i expected the attached image to have winrate as 60.00 or 60 given the calculation of 6 / (6 + 4) * 100....
Solution:
you are dividing two ints - you get an int as a result(rounded down). 6 / (6 + 4) * 100 -> 6 / 10 * 100 -> 0 * 100 multiply new.wins by 1.0 (not just 1) - should help. or do a coalesce to float on one of columns new.winrate = ((1.0 * new.wins) / (new.wins + new.losses)) * 100;...
No description
NNull4/8/2024

Using drizzle in docker gives [i] No changes detected

Hello I have this drizzle.config.ts file, I tried running bun push but I get the [i] No changes detected prompt ```js import type {Config} from 'drizzle-kit'; export default {...
TTitan4/8/2024

Insert returning api to match select columns

I have the following helpers to select the right columns and ensure I don't leak sensitive data: ``` export const userSelectPublicColumns = { id: true, firstName: true, lastName: true } export const userSelectSensitiveColumns = {...
No description
BB33fb0n34/8/2024

No overload matches this call

When inserting data into an table inside a transaction I get this error: (see attached). When I then infer the model like this: (see attached) the error is gone. Any other idea, how to solve that correctly? It seems to be wrong......
No description
LLucifer.TheDeviL4/8/2024

transactions options resulting in syntax error of mysql.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`set transaction `' at line 1, stack: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`set transaction `' at line 1
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`set transaction `' at line 1, stack: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`set transaction `' at line 1
Here's the code: ```{ isolationLevel: 'read committed',...
Rrsrahul4/8/2024

Messed up my migrations - Need help

Hello, I am new to Drizzle (in general new to SQL world). Using drizzle with turso db. I had few tables and recently added one new table (say T10) and updated existing table (say T9). ...
DDiamondDragon4/7/2024

Missing nested where clause

If you see here i'm missing the ability to do a where filter on the nested rawDetails table The docs say you can do so ```ts...
No description
AAuroPick4/7/2024

Query API relation null type

Hi I am using query API to fetch data. I defined my schema. My schema is something like that ```ts...
No description
AAndréLB4/7/2024

Best way to use select in a function that is returning a specific type

```ts export type UserID = { userID: number } type UserPassword = { userPassword: string } type UserFirstName = { userFirstName: string } type UserLastName = { userLastName: string }...
Ccapaj4/7/2024

query builder AND returns undefined

as per this tweet https://twitter.com/capajj/status/1776858100131074333 also can anyone explain why would it return undefined?...
Ttzezar4/6/2024

Default isolation level for transaction

Is it possible to globally set default isolation level?