mobilexag / sql-promise-helper

0 stars 0 forks source link

.abort()? #1

Closed screendriver closed 7 years ago

screendriver commented 7 years ago

Is it possible to abort an transaction? Like

if (foo) {
  tx.commit().then(() => {
    // ...
  });
} else {
  tx.abort().then(() => {
    // ...
  });
}

I didn't just tried it out because it's a little bit difficult at the moment to provoke an error.

brodycj commented 7 years ago

Assuming tx is the object returned by helper.newBatchTransaction(), you can abort a transaction with something like this:

tx.abort();

In the current "API" tx.abort() does not return a promise. In this library tx.abort() would basically drop the SQL statement list from the internal state and then return control to the caller.

screendriver commented 7 years ago

Ok. As I said in https://github.com/mobilexag/win-uwp-frame/issues/7 please add this if possible for consistency.

brodycj commented 7 years ago

I just updated both this version and the original @brodybits version so that tx.abort() will return a promise that is already resolved after clearing the internal state. This would properly support the case in your original question. This is now published to npm. Please let me know if this works as desired or not.