Drizzle Team

DT

Drizzle Team

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

Join

error creating relationship

I'm having trouble creating a relationship in MySQL using drizzle-orm, I'm running npx drizzle-kit push:mysql but the I'm trying running the code inside my MySQL database but I'm getting this error Referencing column 'user_id' and referenced column 'id' in foreign key constraint 'anime_user_id_users_id_fk' are incompatible. here is the schema and the generated SQL migration code. ```javascript export const users = mysqlTable( "users",...

define default value for array

I work with a PostgreSQL database. Here is my Schema: export const user = pgTable( 'auth_user',...

TS query types dont match + no return types

I'm trying to query data from my db after importing the Item table from my schema. const data = await db.select().from(Item) As you can see in the screenshot and the error message below typescript seems to have trouble with that. Item table definition is being imported from another typescript project within the repo which might have to do with it? ...

Can't generate migrations because of top level await

This only recently started happening.Here is my drizzle.config.json :
```{ "out": "./migrations", "schema": "./src/*/.sql.ts" }...

Error types with custom schema

Hi, I'm trying to do a general function to paginate my querys, but I'm having some problems with the types. I'm trying to use the types of the library, but I'm not sure if I'm doing it right. All my tables have the same columns, so I created a function to create the base table, and I'm trying to use it to create the pagination function, and definitly i'm doing it wrong but I'm not shure how to do it, could you point me in the right direction? to know if it's possible to do it. ...

Trying to write next-auth adapter

blahblahblahrober AKA @Dan Kochetov helped me get most of the way to having a next-auth adapter done but, in the couple weeks I waited for a review, I came back and now the SQLite migration is betraying me. See video. Starting from a clean slate, it's saying nothing to migrate and, when I run tests against my db.sqlite, I get back errors for no tables, kiddo. Pretty confused; seems like I'm not pushing any schema somehow? Pull request if you want to look at code: https://github.com/nextauthjs/next-auth/pull/7165...

Been getting this error while using the libsql client. The code works though. Any ideas. Thanks! 🙂

I get the error from the screenshot every time I access my db client, but the code works fine though. How can I get rid of the error? 🙂

Select wildcard

I'm sure someone's asked this before but I can't find it. Is there not a way to do a .select() wildcard so that I can do something like: ```ts db.select((defaultFields) => ({...

RangeError: Maximum call stack size exceeded - When I try to INSERT

Hi, I am getting RangeError: Maximum call stack size exceeded when I try to INSERT something in the DB, SELECT queries works with no issues. I am using "drizzle-orm": "^0.25.3" and "@remix-run/react": "^1.15.0"....

Tables are not being generated

Hey 👋 I'm probably missing something obvious but with the setup I have (shown in the image) drizzle doesnt seem to apply the things inside the migration folder. It does generate the drizzle schema in the db + the __drizzle_migrations table so something is running for sure, but it doesnt seem to pick up on the migrations I did. Appreciate the help!...

Inserting records into related tables

I have a few of tables that are related. I just need to know if there's a better approach when inserting records into these. I'm using PlanetScale so no FK constraints. Here's my approach. ``` export const product = mysqlTable('product', { id: serial('id').primaryKey(),...

inArray

For what i've seen pass an empty array to inArray is not supported, how to you handle this cases? using "with" queries and adding it conditonally? or how?

Invalid default value when using defaultNow()

Receiving error:
Invalid default value for 'updated_at' (errno 1067) (sqlstate 42000) (CallerID: 2ga5bxx7mhtso265npy7): Sql: "alter table menus add UNIQUE INDEX menus_public_id_idx (public_id)", BindVars: {REDACTED}`
Invalid default value for 'updated_at' (errno 1067) (sqlstate 42000) (CallerID: 2ga5bxx7mhtso265npy7): Sql: "alter table menus add UNIQUE INDEX menus_public_id_idx (public_id)", BindVars: {REDACTED}`
...

Typesafe floats ?

I'm trying to create a column called "weight". It needs to have values like "33.33" as floats. I'm using PostgreSQL - and I've created a column with the following settings; numeric('weight', { precision: 10, scale: 2 }) ...

TS Errors in Custom Type citext example

I want to include citext data type in my postgres schemas. I was delighted to see there's a complete example in the docs (https://github.com/drizzle-team/drizzle-orm/blob/main/docs/custom-types.md#citext-data-type-example) However, it seems to be broken - see screenshot - because I'm getting a bunch of TS errors. Something on my side or is it outdated? Edit: to give a bit more context, the errors all seem to be originating, for now at least, from this error on PgColumnBuilder:...

Does Drizzle support MySQL's LAST_INSERT_ID function?

I'm wanting to return a newly created record in the db immediately after a POST. MySQL doesn't support returning so it seems the alternative is a separate request in the same transaction that fetches the new record. It appears that the easiest way to do this is with MySQL's LAST_INSERT_ID function. Does Drizzle support this or does this have to be done with raw SQL?

Check for empty string in postgres

Hi. First post. 🙂 Started looking into migrating our project to drizzle today and am loving it so far. I want to add a not-empty check and from what I gathered from the docs and this example https://github.com/drizzle-team/drizzle-orm/blob/b003e523c637c81e2c522003db03d3d9bd98b723/drizzle-orm/type-tests/pg/tables.ts#L76 (which is the only one I could find) this code should work: ```ts...

How do I set a column to be unique in drizzle syntax for mySQL?

Would something like this be correct? ```js export const authUsers = mysqlTable( 'auth_users',...

Sharing zod schema between api and front-end

Im looking to build an app using nextjs and drizzle orm. I was wondering if I could use the zod schemas generated from drizzle-zod. My main concern was the "pollution" of the front-end bundle with back-end stuff. I wouldn't like people looking at my database schema or something unintended

How to use JSON field in query

I've already made an issue on GitHub kind of pertaining to this issue, but I don't know if its actually a bug or if I'm just not using it correctly. Reference: https://github.com/drizzle-team/drizzle-orm/issues/463 ...