Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drizzle ORM and schema #70

Open
nasyrov opened this issue Mar 25, 2024 · 2 comments
Open

Drizzle ORM and schema #70

nasyrov opened this issue Mar 25, 2024 · 2 comments

Comments

@nasyrov
Copy link

nasyrov commented Mar 25, 2024

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
Copy link
Member

pi0 commented Mar 25, 2024

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
Copy link
Author

nasyrov commented Mar 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants