Code Monkey home page Code Monkey logo

Comments (3)

neoxpert avatar neoxpert commented on June 10, 2024 1

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.

neoxpert avatar neoxpert commented on June 10, 2024

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.

impactcolor avatar impactcolor commented on June 10, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.