Drizzle Team

DT

Drizzle Team

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

Join
SSKDown4/28/2024

SQLite update at column

How do you guys would write the created and updated at column schemas when using sqlite? ```ts createdAt: text("createdAt") .notNull()...
DDellgenius4/28/2024

db.select returning [], but a directly executed neon sql statement returns data.

Hi, here is my code. export const getData = async () => { console.log("neon", await sql_neonSELECT * FROM todo WHERE id = ${1}`); console.log("drizzle", await db.select().from(todo));...
AAzzam4/28/2024

How to add multiple tables in a single export object

So for example I have these tables ``` export const orderssection = mysqlTable('orderssection', { firstName: varchar('first_name', { length: 30 }).notNull(),...
DDellgenius4/28/2024

Error: No database connection string was provided to `neon()`.

Hi. Here is my code: `import { neon } from "@neondatabase/serverless";...
DDio4/28/2024

Schema for that links user > friends

Hello, I am trying to do a schema that links users and friends (https://gist.github.com/imaginamundo/d990e63f0aaba7244a173d8fe28f06bb). But I am probaly messing something up, because I get an error that says there is not enought information between those tables. The literal error is:...
DDerock4/28/2024

cannot migrate database: PostgresError: unterminated /* comment at or near "/*

logs: ``` Tasks: 10 successful, 10 total Cached: 2 cached, 10 total Time: 6.717s ...
No description
Eethan<34/28/2024

Issue with JSON + TypScript

Here's my code:
.findFirst({ where: eq(globalBans.offender.id, userID) });
.findFirst({ where: eq(globalBans.offender.id, userID) });
Here's my schema:...
Cc.4/28/2024

how to get auto increment to work sqlite

have attached the relevant snippets for dissection. cannot get the auto-increment function to work. im sure its something simple im overlooking but if someone could help get ai to work it would be greatly appreciated.
No description
QQuark4/27/2024

Node-API function "napi_type_tag_object" is not implemented yet.

I am getting this error when using drizzle + turso libsql, bun and typescript. ``` warning: Node-API function "napi_type_tag_object" is not implemented yet. Track the status of Node-API in Bun: https://github.com/oven-sh/bun/issues/158 thread '<unnamed>' panicked at /cargo/registry/src/index.crates.io-6f17d22bba15001f/neon-1.0.0/src/sys/tag.rs:120:5:...
DCDan Claroni4/27/2024

using unions with "with" clause

I am trying to do something like the following, but cant figure out how to do this with drizzle syntax. ```sql WITH common_subquery AS ( SELECT user_id, column1, column2...
DDerock4/27/2024

ts: Object literal may only specify known properties except the property is known

No overload matches this call.
Overload 2 of 2, '(values: { role: string | SQL<unknown> | Placeholder<string, any>; channelId: string | SQL<unknown> | Placeholder<string, any>; webhookId: string | SQL<unknown> | Placeholder<...>; webhookToken: string | ... 1 more ... | Placeholder<...>; region: string | ... 1 more ... | Placeholder<...>; }[]): PgInsertBase<...>', gave the following error.
Object literal may only specify known properties, and 'channelId' does not exist in type '{ role: string | SQL<unknown> | Placeholder<string, any>; channelId: string | SQL<unknown> | Placeholder<string, any>; webhookId: string | SQL<unknown> | Placeholder<...>; webhookToken: string | ... 1 more ... | Placeholder<...>; region: string | ... 1 more ... | Placeholder<...>; }[]'.
No overload matches this call.
Overload 2 of 2, '(values: { role: string | SQL<unknown> | Placeholder<string, any>; channelId: string | SQL<unknown> | Placeholder<string, any>; webhookId: string | SQL<unknown> | Placeholder<...>; webhookToken: string | ... 1 more ... | Placeholder<...>; region: string | ... 1 more ... | Placeholder<...>; }[]): PgInsertBase<...>', gave the following error.
Object literal may only specify known properties, and 'channelId' does not exist in type '{ role: string | SQL<unknown> | Placeholder<string, any>; channelId: string | SQL<unknown> | Placeholder<string, any>; webhookId: string | SQL<unknown> | Placeholder<...>; webhookToken: string | ... 1 more ... | Placeholder<...>; region: string | ... 1 more ... | Placeholder<...>; }[]'.
...
No description
Ssivaraman4/27/2024

error: no schema has been selected to create in while running push command

trying to setup drizzle with local postgres database, DB_CONN_STRING is 'postgres://postgres:password@localhost:5432/test?schema=public' drizzle config: import 'dotenv/config';...
Ddeclspecl4/27/2024

Navigating through multiple many-to-many relationships in a single query?

Hi all! I've been racking my brain unsuccessfuly on how to accomplish my desired behavior with a query using drizzle. I don't even know how to do it in SQL honestly, and I've searched everywhere on the internet but nothing seems to do exactly what I want. This is a stripped version of my schema just showing the relations, as the rest is pretty simple to deduce. The hierarchy is primarily meal combinations -> many food items -> many traits```ts export const foodItemsRelations = relations(foodItems, ({ many, one }) => ({ foodItemsTraits: many(foodItemsTraits),...
JJustKira4/27/2024

Circular Reference Error when Using Self-Reference in Table Definition with Drizzle-ORM

I encountered an error while defining a PostgreSQL table using Drizzle-ORM. The issue arises when attempting to create a self-referencing array column that references the primary key of its own table. The error message suggests that there is an issue with type inference possibly due to the self-reference. ```ts import { createId } from "@paralleldrive/cuid2"; import { createInsertSchema, createSelectSchema } from "drizzle-zod";...
Hhirefrank4/26/2024

SQL many statements?

Any ideas on how to debug this? ```Task migrations deno run -A src/lib/db/migrations.ts error: Uncaught (in promise) LibsqlError: SQL_MANY_STATEMENTS: SQL string contains more than one statement at mapHranaError (file:///Users/fharris/Projects/jobasaurus-crawler/node_modules/.deno/@libsql+client@0.4.3/node_modules/@libsql/client/lib-esm/hrana.js:257:16)...
Ppax4/26/2024

Querying a materialized view: relation does not exist

I define a materialized view as such: ``` export const usersMv = pgMaterializedView("users_mv").as( (qb) => { return qb...
Jjoostschuur4/26/2024

default to empty object for sqlite text field with JSON mode

How can I default a mode: 'json' text type to an empty object in sqlite? The following in a sqliteTable definition results in a literal string of ([object Object]): ```...
Ddmb4/26/2024

Converting a field from X type to Serial causes errors

I'm attempting to convert a field from type text to type serial. Here's the error I'm seeing: ``` error: type "serial" does not exist...
TTitan4/26/2024

Return type is only "with" types, ignores "columns" types

Not sure if I'm using it wrong but the return type of a relational query is just the columns from the "with" clause, and doesn't merge with the "columns" object like I'd expect
MJIMd Jahidul Islam milon4/26/2024

onUpdate

updatedAt: timestamp('updated_at', { mode: 'date', precision: 3 }) .defaultNow() .$onUpdate(() => sql(now() AT TIME ZONE 'UTC')) .notNull(), ...
Next