Comments (3)
And how does "db" end up in selectDB? While I am firm with it, I do not use TypeScript in any of my projects ..
A minimal, plain NodeJS / Electron compatible, working example might be:
const Database = require('better-sqlite3');
const db = new Database(':memory:');
db.exec('CREATE TABLE test(num bigint)')
db.exec('INSERT INTO test(num) VALUES(5)');
function selectDB(db) {
const i = db.prepare('SELECT * FROM test').get();
console.log(i); // This should output "{num: 5}"
return i;
}
selectDB(db);
I would not blame the initialization of the database, but handling the reference to the created instance might be the issue,
from better-sqlite3.
Well, how do you "run" the selectDB function? Do you pass the correct db object into it? Also, neither prepare nor get do return a Promise. Await is not required here.
I would guess your problem is located somewhere on the JavaScript level, if you can share more information we might be able to give a better hint.
from better-sqlite3.
I believe you are correct. I moved the initialization of the db to main.ts (in an Electron app).
import Database from 'better-sqlite3'; const dbPath = path.join(app.getPath("userData"), "posty.db"); const db = new Database(dbPath);
This crashes my electron app. Am I incorrectly initializing the database? @neoxpert
from better-sqlite3.
Related Issues (20)
- fix for build failure: electron 29.0.0-alpha.7 HOT 7
- node-sqlite is faster? HOT 1
- better_sqlite3 was compiled against a different Node.js version using NODE_MODULE_VERSION 115 HOT 10
- Question mark placeholder not replace in drop index sql HOT 2
- File is not a database. HOT 1
- Change the threading mode with worker threads? HOT 2
- Slowness in the Event Loop HOT 8
- Error while rebuilding for arm HOT 5
- Unable to install better-sqlite3 under node 20.10.0, unknown error HOT 3
- Alter the type of RunResult (typescript) HOT 1
- How to insert INTEGER? String vs Number HOT 1
- MSBuild.exe` failed with exit code: 1 HOT 5
- `no such table: main.object Object` when preparing a DELETE statement HOT 3
- segfault when loading extension spatialite HOT 2
- TypeError: db.get is not a function HOT 4
- Unable to install when using Python 3.12.2 | ModuleNotFoundError: No module named 'distutils' HOT 2
- SqliteError: database is locked error in Next.js + Docker HOT 6
- How can I fully release all of its memory HOT 2
- Support sql`` JS template strings that create cached prepared statements HOT 5
- better-sqlite3 conflicts with jest isolation HOT 8
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 better-sqlite3.