Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 在生产模式下找不到sqlite文件;有棱角的_Angular_Sqlite_Electron_Knex.js_Electron Builder - Fatal编程技术网

Angular 在生产模式下找不到sqlite文件;有棱角的

Angular 在生产模式下找不到sqlite文件;有棱角的,angular,sqlite,electron,knex.js,electron-builder,Angular,Sqlite,Electron,Knex.js,Electron Builder,我使用带有Angular的electron和SQLite db在本地保存数据。它在开发环境中工作得很好,但在我使用electron builder构建它时,它在生产环境中失败了,因为它“找不到”数据库文件。 此外,我还在这个过程中使用这个伟大的样板回购=> 下面是我的目录结构 - src/ - db/ -- database.sqlite - main.ts 下面是我如何尝试使用Knex访问main.ts中的数据库文件 let knex = Knex({ client: "sql

我使用带有Angular的electron和SQLite db在本地保存数据。它在开发环境中工作得很好,但在我使用electron builder构建它时,它在生产环境中失败了,因为它“找不到”数据库文件。 此外,我还在这个过程中使用这个伟大的样板回购=>

下面是我的目录结构

- src/
- db/
-- database.sqlite
- main.ts
下面是我如何尝试使用Knex访问main.ts中的数据库文件

let knex = Knex({
  client: "sqlite3",
  connection: {
    filename:path.join(__dirname, '/db/', 'database.sqlite')
  }
});
以下是我的脚本和配置

electron builder.json

{
  "productName": "POS Billing",
  "directories": {
    "output": "release/"
  },
    "files": [
        "**/*",
        "!**/*.ts",
        "!*.code-workspace",
        "!LICENSE.md",
        "!package.json",
        "!package-lock.json",
        "!src/",
        "!e2e/",
        "!hooks/",
        "!angular.json",
        "!_config.yml",
        "!karma.conf.js",
        "!tsconfig.json",
        "!tslint.json"
    ],
  "win": {
    "icon": "dist/assets/icons",
    "target": [
      "portable"
    ]
  },
  "mac": {
    "icon": "dist/assets/icons",
    "target": [
      "dmg"
    ]
  },
  "linux": {
    "icon": "dist/assets/icons",
    "target": [
      "AppImage"
    ]
  }
}
{
  "name": "pos-billing",
  "version": "1.0.0",
  "main": "main.js",
  "private": true,
 
  "scripts": {
    "postinstall": "electron-builder install-app-deps",
    "ng": "ng",
    "start": "npm-run-all -p electron:serve ng:serve",
    "build": "npm run electron:serve-tsc && ng build --base-href ./",
    "build:dev": "npm run build -- -c dev",
    "build:prod": "npm run build -- -c production",
    "ng:serve": "ng serve -c web -o",
   "electron:serve-tsc": "tsc -p tsconfig.serve.json",
    "electron:serve": "wait-on tcp:4200 && npm run electron:serve-tsc && npx electron . --serve",
    "electron:local": "npm run build:prod && npx electron .",
    "electron:build": "npm run build:prod && electron-builder build",
    "test": "ng test --watch=false",
    "test:watch": "ng test",
    "e2e": "npm run build:prod && cross-env TS_NODE_PROJECT='e2e/tsconfig.e2e.json' mocha --timeout 300000 --require ts-node/register e2e/**/*.e2e.ts",
    "version": "conventional-changelog -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
    "lint": "ng lint"
  },
  "devDependencies": {
    "@angular-builders/custom-webpack": "10.0.1",
    "@angular-devkit/build-angular": "0.1001.6",
    "@angular-eslint/builder": "0.5.0-beta.3",
    "@angular-eslint/eslint-plugin": "0.5.0-beta.3",
    "@angular-eslint/eslint-plugin-template": "0.5.0-beta.3",
    "@angular-eslint/template-parser": "0.5.0-beta.3",
    "@angular/cli": "10.1.6",
    "@angular/compiler": "10.1.5",
    "@angular/compiler-cli": "10.1.5",
    "@angular/language-service": "10.1.5",
    "@angular/platform-browser": "10.1.5",
    "@angular/platform-browser-dynamic": "10.1.5",
    "@ngx-translate/core": "13.0.0",
    "@ngx-translate/http-loader": "6.0.0",
    "@types/jasmine": "3.5.14",
    "@types/jasminewd2": "2.0.8",
    "@types/mocha": "8.0.3",
    "@types/node": "14.11.8",
    "@typescript-eslint/eslint-plugin": "4.4.0",
    "@typescript-eslint/eslint-plugin-tslint": "4.4.0",
    "@typescript-eslint/parser": "4.4.0",
    "chai": "4.2.0",
    "electron-packager": "^15.1.0",
    "conventional-changelog-cli": "2.1.0",
    "core-js": "3.6.5",
    "cross-env": "7.0.2",
    "electron": "10.1.3",
    "electron-builder": "22.8.1",
    "electron-reload": "1.5.0",
    "eslint": "7.11.0",
    "eslint-plugin-import": "2.22.1",
    "jasmine-core": "3.6.0",
    "jasmine-spec-reporter": "6.0.0",
    "karma": "5.2.3",
    "karma-coverage-istanbul-reporter": "3.0.3",
    "karma-electron": "6.3.1",
    "karma-jasmine": "4.0.1",
    "karma-jasmine-html-reporter": "1.5.4",
    "mocha": "8.1.3",
    "npm-run-all": "4.1.5",
    "rxjs": "6.6.3",
    "spectron": "12.0.0",
    "ts-node": "9.0.0",
    "tslib": "2.0.3",
    "typescript": "4.0.3",
    "wait-on": "5.2.0",
    "webdriver-manager": "12.1.7",
    "zone.js": "0.11.1"
  },
  "dependencies": {
    "@angular/common": "10.1.5",
    "@angular/core": "10.1.5",
    "@angular/forms": "10.1.5",
    "@angular/animations": "~10.1.5",
    "@angular/router": "10.1.5",
    "@ng-select/ng-select": "^5.0.7",
    "@swimlane/ngx-datatable": "^18.0.0",
    "file-saver": "^2.0.2",
    "guid-typescript": "^1.0.9",
    "knex": "^0.21.6",
    "license-key-gen": "^0.1.4",
    "ng-select": "^1.0.2",
    "ngx-export-as": "^1.5.0",
    "ngx-print": "^1.2.0-beta.5",
    "sqlite3": "^5.0.0"
  },
  "engines": {
    "node": ">=10.13.0"
  }
}
package.json

{
  "productName": "POS Billing",
  "directories": {
    "output": "release/"
  },
    "files": [
        "**/*",
        "!**/*.ts",
        "!*.code-workspace",
        "!LICENSE.md",
        "!package.json",
        "!package-lock.json",
        "!src/",
        "!e2e/",
        "!hooks/",
        "!angular.json",
        "!_config.yml",
        "!karma.conf.js",
        "!tsconfig.json",
        "!tslint.json"
    ],
  "win": {
    "icon": "dist/assets/icons",
    "target": [
      "portable"
    ]
  },
  "mac": {
    "icon": "dist/assets/icons",
    "target": [
      "dmg"
    ]
  },
  "linux": {
    "icon": "dist/assets/icons",
    "target": [
      "AppImage"
    ]
  }
}
{
  "name": "pos-billing",
  "version": "1.0.0",
  "main": "main.js",
  "private": true,
 
  "scripts": {
    "postinstall": "electron-builder install-app-deps",
    "ng": "ng",
    "start": "npm-run-all -p electron:serve ng:serve",
    "build": "npm run electron:serve-tsc && ng build --base-href ./",
    "build:dev": "npm run build -- -c dev",
    "build:prod": "npm run build -- -c production",
    "ng:serve": "ng serve -c web -o",
   "electron:serve-tsc": "tsc -p tsconfig.serve.json",
    "electron:serve": "wait-on tcp:4200 && npm run electron:serve-tsc && npx electron . --serve",
    "electron:local": "npm run build:prod && npx electron .",
    "electron:build": "npm run build:prod && electron-builder build",
    "test": "ng test --watch=false",
    "test:watch": "ng test",
    "e2e": "npm run build:prod && cross-env TS_NODE_PROJECT='e2e/tsconfig.e2e.json' mocha --timeout 300000 --require ts-node/register e2e/**/*.e2e.ts",
    "version": "conventional-changelog -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
    "lint": "ng lint"
  },
  "devDependencies": {
    "@angular-builders/custom-webpack": "10.0.1",
    "@angular-devkit/build-angular": "0.1001.6",
    "@angular-eslint/builder": "0.5.0-beta.3",
    "@angular-eslint/eslint-plugin": "0.5.0-beta.3",
    "@angular-eslint/eslint-plugin-template": "0.5.0-beta.3",
    "@angular-eslint/template-parser": "0.5.0-beta.3",
    "@angular/cli": "10.1.6",
    "@angular/compiler": "10.1.5",
    "@angular/compiler-cli": "10.1.5",
    "@angular/language-service": "10.1.5",
    "@angular/platform-browser": "10.1.5",
    "@angular/platform-browser-dynamic": "10.1.5",
    "@ngx-translate/core": "13.0.0",
    "@ngx-translate/http-loader": "6.0.0",
    "@types/jasmine": "3.5.14",
    "@types/jasminewd2": "2.0.8",
    "@types/mocha": "8.0.3",
    "@types/node": "14.11.8",
    "@typescript-eslint/eslint-plugin": "4.4.0",
    "@typescript-eslint/eslint-plugin-tslint": "4.4.0",
    "@typescript-eslint/parser": "4.4.0",
    "chai": "4.2.0",
    "electron-packager": "^15.1.0",
    "conventional-changelog-cli": "2.1.0",
    "core-js": "3.6.5",
    "cross-env": "7.0.2",
    "electron": "10.1.3",
    "electron-builder": "22.8.1",
    "electron-reload": "1.5.0",
    "eslint": "7.11.0",
    "eslint-plugin-import": "2.22.1",
    "jasmine-core": "3.6.0",
    "jasmine-spec-reporter": "6.0.0",
    "karma": "5.2.3",
    "karma-coverage-istanbul-reporter": "3.0.3",
    "karma-electron": "6.3.1",
    "karma-jasmine": "4.0.1",
    "karma-jasmine-html-reporter": "1.5.4",
    "mocha": "8.1.3",
    "npm-run-all": "4.1.5",
    "rxjs": "6.6.3",
    "spectron": "12.0.0",
    "ts-node": "9.0.0",
    "tslib": "2.0.3",
    "typescript": "4.0.3",
    "wait-on": "5.2.0",
    "webdriver-manager": "12.1.7",
    "zone.js": "0.11.1"
  },
  "dependencies": {
    "@angular/common": "10.1.5",
    "@angular/core": "10.1.5",
    "@angular/forms": "10.1.5",
    "@angular/animations": "~10.1.5",
    "@angular/router": "10.1.5",
    "@ng-select/ng-select": "^5.0.7",
    "@swimlane/ngx-datatable": "^18.0.0",
    "file-saver": "^2.0.2",
    "guid-typescript": "^1.0.9",
    "knex": "^0.21.6",
    "license-key-gen": "^0.1.4",
    "ng-select": "^1.0.2",
    "ngx-export-as": "^1.5.0",
    "ngx-print": "^1.2.0-beta.5",
    "sqlite3": "^5.0.0"
  },
  "engines": {
    "node": ">=10.13.0"
  }
}
这会在release/目录下创建一个exe文件,但当我打开它时,它无法加载数据库。 我曾尝试使用
app.getPath(“userData”)
解决方案,但也不起作用

任何帮助都将不胜感激。感谢您的帮助。

文件名:path.join(uu dirname,“/db/”,“database.sqlite”)

您正在将文件存储在应用程序资源中,但该资源无法保存。在应用程序包中,我们不允许写入或更改内容

这在开发应用程序时是可能的,但在打包之后是不可能的

您必须将数据库文件存储在某个位置。照常 如果应用程序需要,您可以将其存储在
应用程序数据中
目录您可以使用
app.getPath('userData')