unjs / db0

📚 Lightweight SQL Connector
https://db0.unjs.io
MIT License
125 stars 10 forks source link

PostgreSQL + drizzle-orm #58

Open kingyue737 opened 4 months ago

kingyue737 commented 4 months ago

Describe the feature

It seems that only sqlite is supported when using drizzle integrator from db0. https://github.com/unjs/db0/blob/fde26b536dcaa0f40af8646d66b62266f4a57f2f/src/integrations/drizzle/index.ts#L2

Is there a plan to support other databases?

I also have some questions. Since the discussion tab is not enabled, I post them here by the way.

What's the recommended way to integrate drizzle in nuxt server routes? Like following?

// server/utils/db.ts
import { drizzle } from 'db0/integrations/drizzle/index'

export function useDb(name?: string) {
  return drizzle(useDatabase(name))
}

and then call useDb in every event handler?

I'm already using drizzle and pg in my nuxt project. What extra benefits does db0 bring? Moving config from a utils module to nuxt/nitro config? Seamless switching from one database to another as now we have a uniform config interface?

Thanks in advance

Additional information

amandesai01 commented 4 months ago

For usage with Postgres, it is already supported. It may seem like it works only with SQLite, but I believe only dialects or something were used. I just wrote a passing test case for postgres to verify myself and it works like a charm.

https://github.com/unjs/db0/pull/55/commits/b59e7dbf4e43ad2c09e9a9b6a55fbb5eb62dd1b1

kingyue737 commented 4 months ago

It seems that type is not correct. Type PgColumn is not asignable to SQLiteColumn

kingyue737 commented 3 months ago

Sorry I forgot the reproduction:

https://stackblitz.com/edit/nuxt-starter-uxpj3c