gpt4 book ai didi

electron - 如何在 Electron 中连接到本地数据库

转载 作者:行者123 更新时间:2023-12-03 12:22:32 25 4
gpt4 key购买 nike

我是 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 );
} );

}
}

4)将服务导入到所需的组件中。

关于electron - 如何在 Electron 中连接到本地数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49906807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com