Drizzle Team

DT

Drizzle Team

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

Join

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})`,
),
...

Time Mysql Formatting

The Time format come formatted like hh:mm:ss.mmmmmm ( unsure if the last part is ms. Just like in the following query result: ```Js { id: 2,...

Many to Many to Many

I mean a relationship where a user can belong to many groups and in a particular group can have many roles. I am counting on quick help. Thanks in advance for your help.

Subquery within same table not working as expected

I have this table that list employees: ``` export const workersTable = pgTable('workers', { workerId: integer('worker_id').notNull().primaryKey(),...

How to store Uint8Array in postgresql

```ts const users: pgTable("user", { recovery_code: // what to use here? })...

npx drizzle-kit pull: pg driver but getting a `'./gel-core' is not defined by "exports"` error

g'day from Aus, I'm using drizzle for the first time. I have followed along with the doco: in as much that i have copy n' pasted my way through it. I tried to use pull to generate my schema definitions...but get an error about the gel-core subpackage not being exported. here is my config. ```import { defineConfig } from "drizzle-kit";...