drizzle-team / drizzle-team/drizzle-orm

[BUG]: op-sqlite 17 breaks drizzle integration

Open
#5,928 1 comment 1 reaction 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

0.45.2

### What version of `drizzle-kit` are you using?

0.31.10

### Other packages

_No response_

### Describe the Bug

I've just switched from `expo-sqlite` to `op-sqlite` and now whenever I run a select query I get the error: `TypeError: undefined is not a function` with the following call stack:

```
Call Stack
OPSQLitePreparedQuery#all (node_modules/drizzle-orm/op-sqlite/session.js:95:20)
next ()
anonymous (address at (InternalBytecode.js:1:8765)
step (address at (InternalBytecode.js:1:6505)
anonymous (address at (InternalBytecode.js:1:7664)
tryCallOne (address at (InternalBytecode.js:1:1274)
anonymous (address at (InternalBytecode.js:1:4865)
```

On further inspection, this is being caused by the `rows.map` call [here](https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/op-sqlite/session.ts#L159). It seems the code is expecting an array, but it's not an array -- it's an object: The `rows` variable is the result of calling `this.values`, which ultimately calls [`this.client.executeRawAsync`](https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/op-sqlite/session.ts#L191). Switching to the op-sqlite client code, this actually returns a [`RawQueryResult`](https://github.com/OP-Engineering/op-sqlite/blob/main/node/src/types.ts#L14) object, which is not an array at all and has no `map` method. And that's exactly what I'm seeing when I break in the `session.ts` code where the original error is being thrown from.

A little more digging, and it seems [this change](https://github.com/OP-Engineering/op-sqlite/commit/83e6d260b0dc9b5d0fad42e82dffac431f80a61a) on the `op-sqlite` side of things is the culprit, which adds this to the docs:

```
## Breaking change notice

Starting on version `17.0.0`, `executeRaw()` and `executeRawSync()` return an object instead of a bare array of rows.
```

I guess I'll downgrade op-sqlite for now... what's the play here? Add some code that checks if the return value from `executeRawAsync` is a `RawQueryResult`, and pass along `rawRows` instead, in that case? I can throw up a PR if that seems reasonable.

Contributor guide

Open the contributing guide

Research direction

Start in drizzle-orm/src/op-sqlite/session.ts around the rows.map call and the executeRawAsync use. Compare the returned value with op-sqlite 17's RawQueryResult documentation and trace how select queries reach OPSQLitePreparedQuery#all. Done means select queries work with op-sqlite 17 while preserving compatibility with the existing integration.

Written by the indexing model from the issue text.

Assessment

Tech stack
sqlite, typescript
Domain
database, mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.