Drizzle Team

DT

Drizzle Team

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

Join

[x: string]: never

I can not find the issue in my code, I would be glad if someone could take a quick look Drizzle return type: ```ts let res: {...

Best practises for handling postresql errors?

Hi, I was wondering which is the recommended way to handle postresql errors in drizzle. Until now I was making sure all introduced data wasn't triggering any error, so for example when I introduce a new Item I manually check if there is already another item with the same name. However I was thinking whether might be a good idea to let postgresql throw an error and just catch it in my drizzle query. One option I've seen is this https://github.com/drizzle-team/drizzle-orm/discussions/916#discussioncomment-11929987 So I have 2 questions...

Unexpected behaviour of drizzle-zod createInsertSchema

I have this postgres schema: ``` export const contractsTable = pgTable('contracts_table', { id: integer().primaryKey().generatedByDefaultAsIdentity(),...

Querybuilder only Drizzle instance

Sorry if this is obvious and if I've missed it in the docs but I didn't see anything. Is there a way to create a drizzle instance for a given dialect (SQLite in my case) that doesn't require an actual DB instance to connect to? I'll still want to initialize it with a schema. My particular use case is being able to pass it into the drizzle-graphql so I can build a GraphQL schema but I don't want the actual resolvers to be implemented in this layer. ...

wrapping of queries

I want to wrap all/some of my queries to instrument them for observability ``` import { type SQLWrapper } from "drizzle-orm"; type DrizzleQuery<T> = SQLWrapper & Promise<T>;...

How should I refactor my transactions?

Hi, I wondering how I should refactor my code. Right now I have forms in which data affects multiple tables and its relations and I use a transaction to make sure data consistency when adding or updating. I'd like to split the transaction into different functions and even different files. I was thinking I could simply send my transaction object to the function but I don't like this approach since the query function then is dependent on receiving the transaction object. In case I don't need the query to be in a transaction I could send the transaction object (tx) as optional and then check and execute tx.query or db.query, but I don't like this approach. So I am asking, is there a more elegant solution to split my transaction queries into different files and functions?...

Query typing is suddenly empty

This was working for the longest time, but all of a sudden the typing on "query" stopped returning anything. I've tried removing almost all schemas to identify what's causing the error, but it's not making a difference.
No description

No way for TypeScript to infer if a column is unique

Currently, there is no way for TypeScript to know if a column is unique, in the same way it is possible to infer if a column is a primary key, or not null, or has default etc. I am trying to create some Types in my project that will allow me to pass the schema for some tables into a type, and infer the columns that are primary keys or are unique. I have outlined all the relevant details including code snippets In this GitHub Issue: https://github.com/drizzle-team/drizzle-orm/issues/4206...

Crash not fixed by restarting

Attached error context - The whole module broke when vscode crashed and restarted, which has made it so drizzle can't recover without a full reboot

$count

this is a bug?
No description

Migration defaulting to neon driver

hey, I run into an issue where i'm not using neon but when migrating it does try to use neon driver even tho I'm running my postgres db locally. I'm using next js Could anyone help?...
No description

insert without passing schema

if you pass schema to drizzle like, ``` drizzle({ schema, connection: process.env.DB_FILE_NAME!...

How to make function that takes in a table as parameter with correct types?

e.g. if we have the following function, which takes in an arbitrary table and executes a where clause on it: ``` typescript import db from '../db' import { type Table, type SQL, } from 'drizzle-orm'...

Postgres insert returning expecting zero arguments

I'm trying to specify columns to return during a Postgres insert using the Neon serverless driver. But .returning() is telling me it doesn't accept any arguments. However the docs show it's possible to specify an object?
No description

Drizzle-Seed null values

Hello there, how can I seed null values with drizzle-seed? I want something like: ```js...

Migration failed, and can't add new migration

Hello, I've tried to add a change to a table ```ts import { pgTable, serial, text } from 'drizzle-orm/pg-core'; ...

Turso drizzle-kit CLI: Passing dbCredentials via CLI options

Hi, I'm building a multi-tenant database and trying to configure drizzle-kit using CLI options. However, I’m unsure whether it's possible to pass the dbCredentials part of the config via CLI, and if so, how to do it. ``` dbCredentials: { url: process.env.TURSO_DATABASE_URL,...

Knowing when drizzle finished Migration/Pushed.

Hi, I'm new to DrizzleORM and backend development as a whole. I'm using Drizzle BetterSQLite3 with SvelteKit. I'm trying to execute raw SQL commands to create some triggers for backups. Currently, I'm doing it like this `` await db.transaction(async (tx) => { tx.run(sql CREATE TRIGGER IF NOT EXISTS TRG_CT_INSERT_BACKUP...

arrayOverlaps case insensitive

is it possible to make arrayOverlaps case insensitive in drizzle ? ```ts const fetchFromDb = async (names : string[]) => {...

Use DB functions to format data on update e.g. DATE()

Is there a way to use database functions like DATE in SQLite to format a value on update to ensure it is formatted correctly? I have a text field where I store a person's date of birth and want it formatted as YYYY-MM-DD (which DATE does) and doing it on the client side with no verification on the server / db side seems error prone. As with schemas in general it is best to constrain data as much as possible and this data should never be in any other form. Is there a way to make it so? I already have a check that it is a valid date with
check(
"date_of_birth_check",
sql`(LENGTH(${table.date_of_birth}) <= 10 AND DATE(${table.date_of_birth}, '+0 days') IS ${table.date_of_birth})`,
),
check(
"date_of_birth_check",
sql`(LENGTH(${table.date_of_birth}) <= 10 AND DATE(${table.date_of_birth}, '+0 days') IS ${table.date_of_birth})`,
),
...