In some cases you may prefer to create transaction but only execute statements in it later. A transaction generally represents any change in a database (learn more). Note that Amazon Redshift does not support savepoints in transactions. SQLite, and even NoSQL databases like MongoDB. If you don't pass any argument to trx.rollback, a generic Error object will be created and passed in to ensure the Promise always rejects with something. The sqlite3.Database () call can take one, two, or three arguments. Notice that if a promise is not returned within the handler, it is up to you to ensure trx.commit, or trx.rollback are called, otherwise the transaction connection will hang.Ĭalling trx.rollback will return a rejected Promise. First, create a file called sample.js and import the sqlite3 module into Node.js: File: sample.js 1 var sqlite3 require('sqlite3') The following line creates a database, mcu.db, in the current working directory. The function returns the Database object to allow for function chaining. Throwing an error directly from the transaction handler function automatically rolls back the transaction, same as returning a rejected promise. Supports MySQL / MariaDB / Postgres / CockroachDB / SQLite / Microsoft SQL Server / Oracle / SAP Hana / sql.js. Runs all SQL queries in the supplied string.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |