Skip to content
Brian edited this page May 15, 2016 · 3 revisions
 transaction([options])

Creates a transaction to perform multiple JSQL queries in a batch.

Table of Contents

Parameters

options (optional)

See options for additional information.

The Transaction object does not make use of any options itself, but it will pass the options on to the execute function of each query in the transaction.

Returns

The transaction function returns a Transaction object, which is a subclass of cls.Cloneable. This object has the following functions you can use:

rollback()

Clears the queue of queries to perform in the transaction, and restores the database to what it ought to be barring any interference from queries in the transaction.

reset()

Clears the queue of queries to perform in the transaction, and opens the transaction so that it can be used again. (If you call commit, you cannot call it a second time until you call reset.)

addAction(action)

Adds an action to the transaction queue. This is not necessary for client code use, as passing the transaction as the value of options.useTransaction to your various query methods (or setting it in cls.DefaultOptions) will accomplish this already.

That said, you can chain Transaction functions together until you call commit, so you could potentially write code in a manner such as:

 jsql.transaction()
     .addAction(jsql.insert('table1').sub(jsql.select('table2')...))
     .addAction(jsql.delete('table2')...)
     .commit();

commit([options])

Perform each JSQL query in the transaction queue in order. options can override the same options specified in transaction and cls.DefaultOptions. The options will be passed to the execute function of each query in the queue.

This function will return true if all queries in the queue completed successfully. If any query throws an error, the transaction will be rolled back and the function will return false.

Clone this wiki locally