Serverless MySQL: v1.1.0 Released

Serverless MySQL v1.1.0 adds additional transaction support capabilities to allow users to retrieve interim query results for use with future queries.

Serverless MySQL v1.1.0 adds additional transaction support to allow users to get interim query results. This is useful for getting the insertId from previous queries when performing transactions.

Transactions are extremely simple with Serverless MySQL. You just need to start a transaction, chain your queries, and then use the commit() method to execute them.

javascript
let results = await mysql.transaction() .query('INSERT INTO table (x) VALUES(?)', [1]) .query('UPDATE table SET x = 1') .rollback(e => { /* do something with the error */ }) // optional .commit() // execute the queries

Now, with the new interim query results support, you can retrieve the results of the previous query by wrapping your query in a function and returning an array containing your new query's attributes:

javascript
let results = await mysql.transaction() .query('INSERT INTO table (x) VALUES(?)', [1]) .query((r) => ['UPDATE table SET x = 1 WHERE id = ?', r.insertId]) .rollback(e => { /* do something with the error */ }) // optional .commit() // execute the queries

If you need to get the value of multiple queries, you can use the second argument instead:

javascript
let results = await mysql.transaction() .query('INSERT INTO table (x) VALUES(?)', [1]) .query('INSERT INTO otherTable (y) VALUES(?)', [2]) .query((r,results) => [ 'UPDATE table SET x = ? WHERE id = ?', [ results[1].insertId, results[0].insertId ] ]) .rollback(e => { /* do something with the error */ }) // optional .commit() // execute the queries

Easy peasy 🍋! Check out the Serverless MySQL NPM module to see how simple it is to manage MySQL at Serverless Scale.

NPM: https://www.npmjs.com/package/serverless-mysql

GitHub: https://github.com/jeremydaly/serverless-mysql

Comments are currently disabled, but they'll be back soon.