![]() Basic knowledge to request an API endpoint (with Postman).Basic knowledge of writing JavaScript for Node.js.Prerequisitesīefore you can jump into this content, you need to have a basic understanding of the following. We’ll learn how to write queries for custom routes in Strapi with Database Transaction. If you start to write code to implement custom routes in Strapi, this tutorial is for you. It supports PostgreSQL, SQLite, MySQL, and MariaDB. Strapi is a headless content management system (CMS) built with React.js and Node.js. That’s including Knex, which is used by Strapi through Bookshelf. Most database libraries provide a way to use database transactions. If we had used a database transaction in our problem above, the changes would only have happened in memory and not be committed, which makes users’ deposits untouched. When a transaction has started, all execution will happen in the memory and not yet be written until it is fully committed. A transaction will either execute completely ( committed) or not at all ( rolled back). ![]() This would be a disaster, how much of the users' balance would be gone missing, simply because of technical problems? This is why we have to learn to use Database Transactions.Ī database transaction is a concept to merge several database queries such that we want to treat them as “a whole”. The server first decreases user A’s balance, but before the server can increase user B’s balance it crashes. Imagine user A wants to deposit some amount of his balance to user B. Let's say you’re creating a website with a payment system. That is easy to implement, but what happens if it comes to a halt while it's in the middle of writing something in the database? When software goes wrong, it will halt the code execution and returns an error message immediately. So this is why, when we write software, we have to prepare for the worst when things go wrong. While we always strive for it hard enough, sometimes bugs still can appear in a production system. When we write software, we always want to make it as flawless as possible.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |