Comments (11)
If this library is used with ES2015+ async/await
(via sqlite
), how can you make sure that some extraneous queries are not being injected into the transaction?
await db.run('BEGIN');
try {
await db.exec(sql);
await db.run('COMMIT');
} catch (err) {
await db.run('ROLLBACK');
throw err;
}
from node-sqlite3.
Yes, that would be awesome +1
from node-sqlite3.
@Pita: Please note that transactions are already possible with node-sqlite3
, there's just no specific interface for it. Nothing stops you from running db.run("BEGIN"); /* some queries inside the transaction */ db.run("COMMIT")
. You only have to pay attention that no other code holding the database handle injects queries inside the transaction that shouldn't be there.
from node-sqlite3.
I know that it's possible. I'm already doing it like this. But it's a ugly way cause I have to build a huge sql string manually.
var sql = "BEGIN TRANSACTION;\n"; for(var i in bulk) { if(bulk[i].type == "set") { sql+="REPLACE INTO store VALUES (" + escape(bulk[i].key) + ", " + escape(bulk[i].value) + ");\n"; } else if(bulk[i].type == "remove") { sql+="DELETE FROM store WHERE key = " + escape(bulk[i].key) + ";\n"; } } sql += "END TRANSACTION;"; this.db.exec(sql, function(err){ ...
from node-sqlite3.
You don't have to build a single string; you can just use the regular APIs between db.run("BEGIN")
and db.run("COMMIT")
from node-sqlite3.
I'd also really love to see this API implemented. I'm refactoring https://github.com/developmentseed/couch-sqlite to work with long lived connections and it would be great to use this, rather than a pool of one connection.
/cc @gundersen
from node-sqlite3.
2 eggrolls.
from node-sqlite3.
You only have to pay attention that no other code holding the database handle injects queries inside the transaction that shouldn't be there.
What's the best way to do this? Is it sufficient to put the transaction inside db.serialize? Will that block other non-db things like http server events?
from node-sqlite3.
You only have to pay attention that no other code holding the database handle injects queries inside the transaction that shouldn't be there.
What's the best way to do this? Is it sufficient to put the transaction inside db.serialize? Will that block other non-db things like http server events?
I'd like an answer to ghost's question, please. It's not clear in the docs.
from node-sqlite3.
I would like to know under which condition a ROLLBACK should be issues? It is not clear to me if this is done automatically by the engine. In other words, I would assume that upon any failure, the entire transaction is being rolled back to the state before. Otherwise, what would be the motivation to use a transaction in the first place?
from node-sqlite3.
Clsoing in favor of #304
from node-sqlite3.
Related Issues (20)
- npm install sqlite3 fail if prebuilt unreachable and Python v3.12 is installed HOT 2
- sqlite3 crash on require with nw.js node.js app
- How to install sqlite for Linux and Windows in the same project?
- [ERROR] Unable to load sqlite3 module. See https://github.com/mapbox/node-sqlite3/wiki/Binaries
- SQLite 3 installation error message post-deployment
- Bundled build error on Windows HOT 4
- Being able to connect to a database that is located in a Buffer variable HOT 1
- Not safe for use concurrently from multiple async scopes HOT 4
- @npmcli/move-file is deprecated, use @npmcli/fs instead HOT 2
- finalize is necessary
- Bug creating foreign key
- when i run test my extension get error in init use sqlite
- Running Sequelize on Bun using sqlite3 produces undefined symbol: uv_close error HOT 1
- How to obtain the fragmented size of a sqlite database
- v5.1.7 changes the usage of a binary mirror (incompatibly)
- Too many non-runtime dependencies after installation
- Add character offset to error message
- How install sqlite3 package manually after electron-packager on linux for windows
- electron v30.0.1 install error
- Getting "Could not locate the bindings file" when trying to open DB in Angular 17 SSR project (ExpressJs)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-sqlite3.