Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite3 db-file is not found within app.asar #1474

Closed
wende60 opened this issue Apr 17, 2017 · 12 comments
Closed

sqlite3 db-file is not found within app.asar #1474

wende60 opened this issue Apr 17, 2017 · 12 comments

Comments

@wende60
Copy link

wende60 commented Apr 17, 2017

happy easter,

Trying to create a build for mac osx, also working on a mac.
This is a part of my package.json to show what i use (based on electron-boilerplate-sqlite):

"dependencies": {
    "sqlite3": "^3.1.8"
  },
  "devDependencies": {
    "electron": "^1.6.2",
    "electron-builder": "^10.17.3"
  }

This is how i set the path to the db-file
const dbFile = path.join(__dirname, '/appData.db');

In the build the path is like this:
/Users/[USERNAME]/[PATH-TO-CONTENT]/Contents/Resources/app.asar/app/appData.db

... and I end up with an error:
SQLITE_CANTOPEN: unable to open database file

Now setting asar to false in the build-options. The path is now like this:
/Users/[USERNAME]/[PATH-TO-CONTENT]/Contents/Resources/app/app/appData.db

The app works fine.
How can i solve this problem?

regards, jo

@develar
Copy link
Member

develar commented Apr 17, 2017

@wende60
Copy link
Author

wende60 commented Apr 17, 2017

thanks for the hint, but it seems to be not very handy... i end up here:

"extraResources": ["appData.db"],

and here:

const dbFile = path.join(__dirname, '/appData.db').replace('/app.asar', '');

hmmm...

@develar
Copy link
Member

develar commented Apr 18, 2017

Update: add examples to doc.

@piyush0
Copy link

piyush0 commented Jun 3, 2017

@wende60

"extraResources": ["appData.db"],

Did it work?

@develar develar closed this as completed Jun 4, 2017
@wende60
Copy link
Author

wende60 commented Jun 4, 2017

as mentioned above, it works only if i toggle the path like here:
const dbFile = path.join(__dirname, '/appData.db').replace('/app.asar', '');

I stopped testing here as I switched to a completely different setup using pouchdb...

cheers, jo

@develar
Copy link
Member

develar commented Jun 4, 2017

Fix on electron side is required. https://www.npmjs.com/package/hazardous

@wende60
Copy link
Author

wende60 commented Jun 4, 2017

cool, thanks :)

@debotos
Copy link

debotos commented Jun 12, 2018

"extraResources": ["appData.db"],
and
const dbFile = path.join(__dirname, '/appData.db').replace('/app.asar', '');

Worked for me!!!

@salmidiv
Copy link

hi evryone
i fix it with this
in packege.json , in build section add:
"extraResources": [
"path/to/database.sqlite3"
],
in main.js add use:
const getDBPath = (filename) => {
let base = app.getAppPath()
if (app.isPackaged) {
base = base.replace('\app.asar', '')
}
return path.resolve(base, path/to/${filename}.sqlite3)
}

@avinashcoditation
Copy link

thanks buddy, worked for me

@zestones
Copy link

hi evryone i fix it with this in packege.json , in build section add: "extraResources": [ "path/to/database.sqlite3" ], in main.js add use: const getDBPath = (filename) => { let base = app.getAppPath() if (app.isPackaged) { base = base.replace('\app.asar', '') } return path.resolve(base, path/to/${filename}.sqlite3) }

Worked for me too

@dxsuporte
Copy link

I used it that way, and everything worked out fine.

//##########################################

const Path = require('path')

const config = {
client: 'better-sqlite3',
connection: {
filename: Path.join(__dirname, __dirname.includes('app.asar') ? '../../database' : '/database'),
},
useNullAsDefault: true,
migrations: {
tableName: 'migrations',
directory: Path.join(__dirname, '/migrations'),
},
seeds: {
directory: Path.join(__dirname, '/seeds'),
},
}
module.exports = require('knex')(config)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants