unjs / db0

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

Drizzle ORM and schema #70

Open nasyrov opened 3 months ago

nasyrov commented 3 months ago

Environment

Latest Nuxt

Reproduction

n/a

Describe the bug

Hi there,

Two things related to Drizzle integration.

Say I have a user schema/table:

const users = sqliteTable('users', {
  id: integer('id').primaryKey({ autoIncrement: true }),
  name: text('name').notNull(),
  email: text('email').notNull().unique(),
  password: text('password').notNull(),
  createdAt: integer('created_at', { mode: 'timestamp' }).notNull().default(sql`(unixepoch())`),
})

Now, I want to query it:

const orm = drizzle<typeof schema>(useDatabase())

const user = orm.query.users.findFirst() // 'users' is undefined here

Let's use query builder then to query user

const [user] = orm
 .select
 .from(tables.user)
 .limit(1)

user.createdAt // typescript says it exists, but in reality it doesn't and returns 'created_at' as an integer only

So whether you would like to use ORM or query builder it's not working unfortunately.

pi0 commented 3 months ago

Can you please make a runnable project? 🙏🏼 (if you can make it with db0 alone that's perfect, with nitro, you can make new issue in nitro repo)

nasyrov commented 3 months ago

I'll try to scaffold a reproduction, in a meantime I think it's related to this line - https://github.com/unjs/db0/blob/main/src/integrations/drizzle/index.ts#L16