Connection to SQL destroyed (after idle). Do I need to manually handle open + close for each query?
i deployed my SQL server and nodejs server on railway. The server is up and running, for some reason my SQL connection disconnected? I was wondering if I am missing something fundamental or what?
```database.ts
import dotenv from "dotenv";
import { drizzle } from "drizzle-orm/mysql2";...
I can't create a simple table..
What am I doing wrong?
```
import { pgTable, serial, text, varchar } from "drizzle-orm/pg-core";
...

Prepared statements with TRPC
Hi,
I just read that to use prepare statements properly with a serverless environment I need to put my statements outside the scope of the handler.
However I use TRPC with NextJS so all my queries are in the router of TRPC which end up in the handle, my question is:
Where should I put my prepared statements considering I'm using the db connection from the context of TRPC ?...
Conditional insert
Hi,
Is there a way to do an
insert
only if the result of an exists
statement is true
?
I would like to do it in one query instead of having to check with another query before the insert.
...DB connections hangs after successful execution in Lambda locally
I'm testing my lambda functions locally with
sls invoke local -f hello
.
after returning a success response, my execution doesnt end
attached a video that shows the behaviour
if i remove the db query then it works fine...Polymorphic Associations?
Hey all - I'm coming to drizzle-orm + SvelteKit from the Rails world.
I want to have polymorphic associations, as documented here: https://guides.rubyonrails.org/association_basics.html#polymorphic-associations
This is what I have in my schema.ts:...

Nextjs edge middleware: Cannot import node:crypto
Vercel Github discussion with other users having the same problem using Drizzle: https://github.com/vercel/next.js/discussions/47314
Hello, it seems that Drizzle is attempting to import node/crypto and failing inside nextjs edge middleware functions.
However, using the crypto global in edge functions/middleware is supported 👍 ...
Instantiate a connection with PlanetScale in Cloudflare Workers
Hey,
What would be the right way to instantiate a database connection with PlanetScale in Cloudflare workers and reuse it across different handlers?
We cannot instantiate it outside the handler because we have no access to the environment variables : ...
select count(*) returns a string not a number? mysql
When running SELECT count(*) it returns a string.
Attached is an image of the query and the output. Can someone help me make sense of this....

Shared Table Behavior
I have a bunch shared metadata (and thus shared logic) across all my tables - things like ID generation, when to mark a row as updated, and by whom...
Using drizzle, what's the recommended way to share logic like this across tables/models?...
Using query builder with views
How do you use the query builder with views? typescripts yells at me saying that db.query.nameOfView is not defined.
Thank you in advance...
How to use "onConflictDoUpdate" with composite key?
If a user sends a friend request while one exists it should update to pending. But the "friends" table is using a composite key.
Table looks like this
```...
Error when pushing to the db
I am trying to do a one-to-many relationship, but I get an error that is
column "twitchSubscription" cannot be automatically cast to type integer
. According to what I read in the documentation I'm doing everything right but the error says something else, maybe I misses something.
- Schema:
```ts
export const GuildSubscriptionTable = pgTable(...Nested where clauses in relational queries
I have this query:
const asset = await db.query.assets.findFirst({
with: {
assetImages : true,...
Default values to integer timestamps in sqlite
I would like to set a default timestamp on record create in mysql.
My schema look like this:
export const users = sqliteTable("user", {
...
createdAt: integer("createdAt", { mode: "timestamp_ms" }) .default(new Date())...
Is it possible to use nanoid for uuid?
Hi,
I want to see if I can customize the uuid generation but I have no idea how to do it.
Is there a code sample that I can follow?
Thank you...
findMany without additional options
When using
const results = await db.query.habits.findMany()
in my project, results
is []
.
If add any option like
```ts
const results = await db.query.habits.findMany({...