![]() ![]() I modified your example to use always insertData wrapper. I am trying to find if a user exists in a table given an email and password but I can't get the function to return the right value (currently returns 'false'), while the alert inside the function does (alerts 'true'). As I understand SQLite, you have no control of different parallel "connections" as you have in PostgreSQL, so you probably need to wrap all your communication with DB. The biggest problem with your code IMHO is that you try to write to DB from different locations. My answer is based on quick study of node-sqlite3. Is there a better approach? How do you deal with this problem?Īt first, I would like to state that I have no experience with SQLite. All attempts to start a transaction when one is already running will also get queued.īut it sounds like too complicated solution.All the extra queries are queued and executed after the current transaction is finished.When transaction is running only queries which belong to the transaction are executed.Only one transaction is running at the same time.I thought about this issue and I think that one solution is to create a wrapper class that will make sure that: Hoops we've just unpredictably lost data without any error message. But if the transaction is rolled back the change made by this extra query is also rolled back. This is not a problem when the transaction is committed. Then this extra query is run in the transaction. Portions of this page are modifications based on work. Setelah itu, jalankan perintah berikut untuk menginstal modul sqlite3. Perintah ini akan membuat folder baru bernama nodejs-sqlie dan di dalamnya akan terdapat file pacakge.json. The problem is that some other code with insert or update query can be launched during the async pause after begin or insert. Returns true if the current thread has a transaction pending. Ketik perintah berikut: mkdir nodejs-sqlite cd nodejs-sqlite npm init -y. function insertData(arrayWithData, callback) , A transaction generally represents any change in a database (learn more). I have discovered a bug in my code with mixing transactions and async code. SQLite, and even NoSQL databases like MongoDB. I am using node-sqlite3, but I am sure this problem appears in another database libraries too.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |