Drizzle Team

DT

Drizzle Team

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

Join

I tried date format in the where clause it showing me an error.

this is the query im converting SELECT , (SELECT COUNT() from daily_check WHERE (daily_checks.qid = question.id) AND (daily_check.is_completed = 1) AND (DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(daily_check.date),'+00:00','+5:30'), '%d-%m-%Y') = '30-07-2023')) AS is_checked FROM question WHERE (restaurant_id=1) AND (status=1) AND (trash=0) AND (category=1) HAVING is_checked = 0 ...

groupby multiple things

the SQL query I want to convert ends with:
GROUP BY
u.user_id,
e.ExerciseID;
GROUP BY
u.user_id,
e.ExerciseID;
I see no where in the docs for multiple groupBy however would expect this would work: ``` .groupBy([ users.user_id, exercises.ExerciseID...

Unwrap the return type of a Subquery, native jsonAgg support or RQ Join Names?

Hi There, I am currently investigating Drizzle ORM and seeing if I can bend it to do everything I need 😅 I quickly got into making queries that both return nested JSON properties (User Including Posts Including Comments etc) but also wanting to use the power of SQL to do some summations / transform values etc. ...

Unform methods for result access

Is there a set of uniform methods for accessing the results of a query? Could be good to have something like the ones available in sqlite adapters - .get() to get the first result Promise<T | null> - .all() to get Promise<Array<T>> - .iter() - can have a default implementation based on iterating over an array of all the elements, but could also support a memory-saving AsyncIterable for adapters that can do streaming...

Cannot query DB table get `COALESCE types smallint and text cannot be matched`

When i run the following query ```javascript let tc = await db.query.ATable.findFirst({ where: and(...

Cannot Access Primary Key on Table

Hello, I am trying to access the primary key named id on the following table: ```ts export const invites = mysqlTable( "invites",...

Typescript build fails, pointing to internal types.

My typescript build fails with 4 errors, all of them pointing to internal type declarations. Is there anything I can do to prevent this? My tsconfig: ```json { "compilerOptions": { "module": "ESNext",...

onConflictDoNothing does not exist on planetscale client

i am getting an "Property onConflictDoNothing does not exist on type" on the following script.... ```ts export async function lookupNationalitySeed(client: DbClient) { await client.insert(lookupNationality).values(...

Are relational queries supported on mysql?

I'm new to this ORM and I'm having trouble getting relational queries to work. Normal db.select().from(exTable) works fine, but when I try db.query.exTable.findMany() I get a warning on VSCode: Property 'exTable' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?">'.ts(2339)...

Is there a way to write a query that orders and filters based on an array of possible options?

I'm trying to do some server-side filtering and sorting for a table, and I ended up writing this for the sorting: ```ts const tickets = dbDrizzle.query.ticket.findMany({ orderBy(fields, operators) { const firstSort = fields[sortBy.data[0]];...

cannot set alias for composite primary key, getting (errno 1059) (sqlstate 42000) errors

My table has the following schema -> ```ts export const emergencyContactPhoneNumber = mysqlTable( "emergency_contact_phone_number",...

Help with query writing

Hi, I'm hoping someone will help me with this query. I have the following query in one of my service files: `const results = await this.db .select() .from(team_projects)...

MySql NOW() in Drizzle

Hi! I might be struggling because this is hard to search for, but I'm wondering if it's possible to use mysql's NOW() function with Drizzle, rather than creating a new ts Date object and using that? Not that it matters much, but it would be good to keep everything in the db layer if possible. Apologies if I've missed this, I searched here, the reference docs site, and some READMEs on GitHub.

Postgres: install plugin during migration

So, I'm using Drizzle with Postgres and am using uuid for the id fields. For that, i need to run the command: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; after creating the database. ...

Introspect failing no pg_hba.conf entry for host

I'm trying to introspect an existing postgres db. It's hosted on heroku and I'm facing no pg_hba.conf entry for host error. I am able to connect with TablePlus to the same db without issues. As I'm attempting to also use ?ssl={"rejectUnauthorized":false} to work around this I'm getting Cannot use 'in' operator to search for 'key' in {"rejectUnauthorized":false}. Any hints on how I might get this one connected?...

Is there a way I can use relational types?

I'm currently trying to make a helper function that essentially wraps a database call, but I can't seem to find nor hack myself into getting a type for the with parameter in the relational queries. I've tried things like ```ts type T = NonNullable<Parameters<typeof db.query.projects.findFirst>[0]>["with"];...

Difference in using unique() on the column definition vs the index?

What is the different between using something like name: varchar('name', { length: 256 }).unique() vs `...

Relational query problem

My goal is to get object of this shape: ```js product: { ... images: [{...}, {...}, {...}]...

Error: relation "offers_details" does not exist

Hey, I'm not really familiar with a lot of backend. When I'm running this code it just saying the following:
Error: relation "offers_details" does not exist
Error: relation "offers_details" does not exist
...