作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Electron 新手,正在用角度5和 Electron 编写一个简单的应用程序。我想知道如何像人员表格一样在我的应用程序中存储数据。我知道可以用Node.js代码将数据存储在MySQL和其他数据库引擎中,但是我想使用 typescript 中的角度代码将数据存储在SQLite或MySQL之类的数据库引擎中。
最佳答案
我不是专家,但是我解决了我想对我的angular5 + Electron 进行的操作:
1)我安装了这个包https://github.com/Inoverse/ngx-fs;
2)在CLI中:ng generate service yourServiceName
;
3)我的your-service-name.service.ts
:
import { Injectable } from '@angular/core'; //default from CLI command //
import { FsService } from 'ngx-fs'; // add this line After step 1 //
@Injectable()
export class youServiceNameService {
myDatabaseTable1: Array< any >; // you can pull all the DB in the var
myDatabaseTable2: Array< any >; // I separated the tables
fileSystem: any; // where I put my FS
constructor(
private _fsService: FsService
) {
this.fileSystem = this._fsService.fs; // the property fs of
// the _FsService contents is described here https://nodejs.org/api/fs.html
this.readDB();
}
readDB() {
this.fileSystem.readFile( 'databaseOrTable.json', ( error, data ) => {
if ( error ) throw error;
this.clients = JSON.parse( data );
console.log( this.clients );
} );
}
}
关于electron - 如何在 Electron 中连接到本地数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49906807/
我是一名优秀的程序员,十分优秀!