Are (async) transactions supposed to work in expo-sqlite?
I'm using drizzle with expo-sqlite in an expo/react-native project. The database works as expected except for transactions. As shown below, when an error happens inside a transaction the transaction is not rolled back and the error is not caught in any way.
With manual
tx.rollback()
tx.rollback()
, I get
[DrizzleError: Rollback]
[DrizzleError: Rollback]
as expected, but it also is not caught and no rollback happens.
Am I doing something wrong or are transactions even supposed to work in expo-sqlite? I couldn't find anything explicit in the docs about this. There's also this open issue (https://github.com/drizzle-team/drizzle-orm/issues/1723) where expo-sqlite was also mentioned at some point.
import { drizzle } from "drizzle-orm/expo-sqlite";import { openDatabaseSync } from "expo-sqlite/next";import { dbOrders } from "./schema";import { eq } from "drizzle-orm";const expo = openDatabaseSync("db.db");const db = drizzle(expo);try { // Create transaction await db.transaction(async (tx) => { // Insert test order await tx .insert(dbOrders) .values([{ id: "test", value: { test: "test" } }]); throw new Error("Should cause rollback"); });} catch (e) { console.log("Should have been caught, causing rollback."); console.log(e);}// Should not existconst testOrder = await db .select() .from(dbOrders) .where(eq(dbOrders.id, "test"));
import { drizzle } from "drizzle-orm/expo-sqlite";import { openDatabaseSync } from "expo-sqlite/next";import { dbOrders } from "./schema";import { eq } from "drizzle-orm";const expo = openDatabaseSync("db.db");const db = drizzle(expo);try { // Create transaction await db.transaction(async (tx) => { // Insert test order await tx .insert(dbOrders) .values([{ id: "test", value: { test: "test" } }]); throw new Error("Should cause rollback"); });} catch (e) { console.log("Should have been caught, causing rollback."); console.log(e);}// Should not existconst testOrder = await db .select() .from(dbOrders) .where(eq(dbOrders.id, "test"));
What version of drizzle-orm are you using? 0.29.2 What version of drizzle-kit are you using? 0.20.9 Describe the Bug I wrote a pretty simple transaction but when the error appears rollback doesn...