#How do I make an Astro DB transaction?

1 messages · Page 1 of 1 (latest)

desert widget
manic geyser
desert widget
#

so how do I rollback after a batch query ?

desert widget
manic geyser
#

@wheat hound Sorry about the ping, but would you happen to have any insight on batch transaction(rollbacks)? i know you had used them in the past for your projects as you were the one who pointed them out to me when i asked.

#

"With the libSQL client library, a batch is one or more SQL statements executed in order in an implicit transaction. The transaction is controlled by the libSQL backend. If all of the statements are successful, the transaction is committed. If any of the statements fail, the entire transaction is rolled back and no changes are made."
This is from the Drizzle Docs linked at the bottom of the batch transaction section on the page you just linked... I think this is what the error meant by automatic rollback

wheat hound
#

Batch transactions are rolled back automatically if one of the statements fail

#

It's all or nothing

manic geyser
#

Oh and just in time for the wizard XD

desert widget
#

all right, it's perfect, thank you

ember tendon
#

@desert widget Have you been able to use batch with no problems? Because Im getting an error while im trying to make a conditional array of db.updates into the batch

wheat hound
#

Are you seeing the error at runtime or on your IDE / astro check?

ember tendon
desert widget
ornate delta
#

what if I need to create a record in table A and a record in table B that references it? with batch I cannot save an intermediate var.. isnt it?

wheat hound
# ornate delta what if I need to create a record in table A and a record in table B that refere...

Yeah, that's where an interactive transaction is needed. Batch transactions can't reference information generated from a previous operation in the batch.

Currently interactive transactions are blocked on Astro DB as an artifact from Astro Studio days. It will be available once we drop compatibility with Studio.

You can use it currently with a LibSQL backend by setting an env var, but you won't get proper typing for it sadly

minor wadi
wheat hound
#

You no longer need a separate env var. By using a libSQL backend, transactions will be enabled.

#

It's a normal Drizzle transaction.

#

It just won't be typed

#

So db.transaction as usual in Drizzle

minor wadi
#

Got you, do you think removing that Omit type declaration would seamlessly resolve the issue with types? I could try setting up a pr for that.

wheat hound
#

Sure. Now that Astro Studio is not an option that can be removed.