db0
db0 copied to clipboard
Drizzle ORM and schema
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.