drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
22.14k stars 514 forks source link

[BUG]: Missing db.execute for SQLite #1364

Open kwando opened 9 months ago

kwando commented 9 months ago

What version of drizzle-orm are you using?

0.28.6

What version of drizzle-kit are you using?

0.19.13

Describe the Bug

The db.execute method mentioned in the docs is not implemented, I would expect to find it here drizzle-orm/drizzle-orm/src/sqlite-core/db.ts https://orm.drizzle.team/docs/sql

Expected behavior

I would expect the execute method to be implemented or if it is not planned/possible at least mention it in the docs :)

Environment & setup

No response

TurtleIdiot commented 9 months ago

This is a big pain point for me as I'm using lucia auth which expects db.exec() as a function. I'm having to implement a wrapper just for this one function and it'd be much better to have this as built-in

TinsFox commented 8 months ago

I also encountered this problem, will it be repaired in the near future?

Angelelz commented 8 months ago

In SQLite there's run, values, get and all methods available depending on what type of response you're expecting if any.

TinsFox commented 8 months ago

In SQLite there's run, values, get and all methods available depending on what type of response you're expecting if any.

hey, @Angelelz

I'm not sure I understand what you mean, but as I understand it, Drizzle is supposed to be a wrapper around an ORM, which wipes out the differences between databases and makes it possible to implement the same syntax to achieve the same thing to a certain extent.

The problem described here is that when using SQLite, there is no way to execute SQL statements through drizzle. But my friend's test works in MySQL.

This is the error I encountered. The execute method is not implemented in the SQLite driver.

telegram-cloud-photo-size-1-5073395698988330208-y

TinsFox commented 8 months ago

I found that the excute method is implemented in both MySQL and PostgreSQL, but not in SQLite

https://github.com/drizzle-team/drizzle-orm/blob/0d833d1ca78735e29b124e2a672bda2c85738f48/drizzle-orm/src/pg-core/db.ts#L163-L167

https://github.com/drizzle-team/drizzle-orm/blob/0d833d1ca78735e29b124e2a672bda2c85738f48/drizzle-orm/src/mysql-core/db.ts#L162-L166

Angelelz commented 8 months ago

You can use db.run() to run queries. db.get() to run a query for which you only expect one result, db.all() to run a query where you expect an array of rows.

Edit: and this is common among all the SQLite drivers.

kwando commented 8 months ago

Didn't think about testing db.all() and friends even though I'm also using the driver extensively 😅

I got confused since all the examples is using the db.execute method :)