No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Sqlite3 in Electron wrapper

    Help
    3
    6
    2781
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Michele Angioni
      Michele Angioni last edited by Michele Angioni

      Hi all,
      after having solved some problems with the initial Electron configuration , I am now stuck into making Sqlite work.
      I managed to install it and recompile it, it even works in the main Process but it doesn’t in the Renderer process files (i.e. the Vue Components).

      I first tried simply installing Sqllite with:

      1. npm install electron-rebuild --save-dev
      2. npm install sqlite3 --save-dev
      3. electron-rebuild -f -w sqlite3

      then I tried with the steps described here and the following postinstall script
      cd node_modules/sqlite3 && npm install nan && npm run prepublish && node-gyp configure --module_name=node_sqlite3 --module_path=../lib/binding/node-v48-linux-x64 && node-gyp rebuild --target=1.6.2 --arch=x64 --target_platform=linux --dist-url=https://atom.io/download/atom-shell --module_name=node_sqlite3 --module_path=../lib/binding/electron-v1.6-linux-x64

      but the result is always the same: it works in the main Process, but when I try to require Sqlite through const sqlite3 = require('sqlite3').verbose() in the Rendered process I get

      ERROR in ./~/sqlite3/lib/sqlite3.js
      Module not found: Error: Can't resolve 'node-pre-gyp' in '/home/....../node_modules/sqlite3/lib'
       @ ./~/sqlite3/lib/sqlite3.js 1:13-36
      

      but node-pre-gyp is correctly installed under the node_modules/sqlite3/node_modules folder . Furthermore manually installing it does not help.

      Any suggestion?

      EDIT:
      There is this minimal working boilerplate but I fear it does not help us.

      EDIT2:
      Another useful guide that I in vain followed

      gvorster 1 Reply Last reply Reply Quote 1
      • F
        ffreitas last edited by

        Hi @Michele-Angioni , did you get to run sqlite with electron?

        1 Reply Last reply Reply Quote 1
        • gvorster
          gvorster @Michele Angioni last edited by

          @Michele-Angioni @ffreitas It’s almost 2021, anyone found a solution to this?

          I also tried the mentioned solutions and get the same error.

          gvorster 1 Reply Last reply Reply Quote 0
          • gvorster
            gvorster @gvorster last edited by

            @gvorster said in Sqlite3 in Electron wrapper:

            @Michele-Angioni @ffreitas It’s almost 2021, anyone found a solution to this?

            I also tried the mentioned solutions and get the same error.

            I tried this with Vue and Electron, so without Quasar, and got the same error.

            After creating the file vue.config.js

            module.exports = {
                configureWebpack: {
                    externals: {
                        sqlite3: "commonjs sqlite3"
                    },
                },
                pluginOptions: {
                    electronBuilder: {
                        externals: ['sqlite3'],
                    }
                },
            };
            

            I can run the electron app and use sqlite3.

            Is there a place in quasar.conf.js or other file where these settings should fix this error?

            1 Reply Last reply Reply Quote 0
            • gvorster
              gvorster last edited by

              I got sqlite3 running now with Quasar and Electron without errors and can create a database/table!
              Will post a step by step instruction tomorrow,

              gvorster 1 Reply Last reply Reply Quote 0
              • gvorster
                gvorster @gvorster last edited by gvorster

                Using these steps I can use sqlite3 with Quasar/Electron app

                quasar create hello
                cd hello
                quasar mode add electron
                yarn add sqlite3
                yarn add electron-builder
                ./node_modules/.bin/electron-builder install-app-deps
                quasar new b sqlite
                

                edit boot/sqlite.js

                import sqlite3 from 'sqlite3'
                
                console.log(sqlite3)
                
                const db = new sqlite3.Database('persons.db', (err) => {
                  if (err) {
                    console.log(err)
                  } else {
                    console.log('db opened')
                  }
                })
                
                db.on("error", function(error) {
                  console.log(error);
                }); 
                
                db.serialize(() => {
                  db.run('CREATE TABLE if not exists persons (id int primary key, name varchar(64))')
                  .run('delete from persons')
                  .run(`insert into persons(id, name) values(1, 'a')`)
                  .run(`insert into persons(id, name) values(2, 'b')`)
                  .run(`insert into persons(id, name) values(3, 'c')`)
                  .all('select * from persons order by id', [], (err, rows) => {
                    rows.forEach((row) => {
                      console.log(`${row.id} / ${row.name}`);
                    });
                  });
                })
                
                db.close()
                
                export default async (/* { app, router, Vue ... } */) => {
                }
                
                

                in quasar.conf.js add boot file and webpack configuration

                    boot: [
                      'sqlite'
                    ],
                
                    build: {
                      vueRouterMode: 'hash', // available values: 'hash', 'history'
                
                      extendWebpack(cfg) {
                        // externals property does not exist yet, so must be created, 
                        // otherwise 'push' new item
                        cfg.externals = {sqlite3: 'commonjs sqlite3'}
                
                        // without this an error occurs !!!
                        // -->>> * aws-sdk in ./node_modules/node-pre-gyp/lib/info.js, 
                        //./node_modules/node-pre-gyp/lib/publish.js and 1 other
                      },
                    },
                

                output from dev console

                quasar dev -m electron
                

                Selection_001.png

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post