drizzle-team / drizzle-team/drizzle-orm
[BUG]:OPSQLiteTransaction does not use opsqlite.transaction() therefor not triggering reactiveExecute
- 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.44.4
### What version of `drizzle-kit` are you using?
0.31.4
### Other packages
_No response_
### Describe the Bug
Opsqllite has a subscription for when queries change - reactiveExecute. **It is only triggered on transactions though.**
### What is the undesired behavior?
`drizzleDb.transaction(tx => ...)` does not trigger callback in` opsqliteClient.reactiveExecute(..., callback)`
### What are the steps to reproduce it?
In a react-native app using:
```ts
import {open} from '@op-engineering/op-sqlite';
import {drizzle} from 'drizzle-orm/op-sqlite';
```
Setup a opsqlite reactive Query e.g.
```ts
export const useReactiveQuery = (
query,
reactiveOptions,
callback,
) => {
const {sql, params} = useMemo(() => query.toSQL(), [query]);
const promise = useStablePromise([sql, params], async () => {
const result = (await query);
return processData(result, callback);
});
const initialData = use(promise);
const [data, setData] = useState(initialData);
useEffect(() => {
const unsubscribe = opsqliteClient.reactiveExecute({
query: sql,
arguments: params,
fireOn: reactiveOptions,
callback: async result => {
const resultData = result.rows;
const _data = await processData(resultData, callback);
setData(_data);
},
});
return () => {
unsubscribe();
};
}, [sql, params, reactiveOptions, callback]);
return data;
};
/// In a component:
const query = drizzleDb.select().from(tableName);
///....
useReactiveQuery(query, [{table: 'table_name'}], result => {
console.log(result);
});
```
Now when using `drizzleDb.transation(...)` to do an insert, nothing will update.
However when running the insert with `opsqliteClient.transaction()` it will.
### What is the desired result?
`drizzleDb.transaction(...)` should trigger an update on `opsqliteClient.reactiveQuery(...)`
Using opsqlite client transaction method in OPSQLiteTransaction (drizzle-orm/src/op-sqlite/session.ts) instead of raw sql for creating the transaction should fix the bug.
**Thanks for the great work!**
Contributor guide
Assessment
This issue has not been assessed yet.