frpc-desktop/electron/storage/version.ts

42 lines
911 B
TypeScript
Raw Normal View History

2023-11-27 15:03:25 +08:00
import Datastore from "nedb";
import path from "path";
2024-07-17 14:21:31 +08:00
import {Proxy} from "./proxy";
import {app} from "electron";
2023-11-27 15:03:25 +08:00
const versionDB = new Datastore({
2024-07-17 14:21:31 +08:00
autoload: true,
filename: path.join(app.getPath("userData"), "version.db")
2023-11-27 15:03:25 +08:00
});
/**
*
* @param proxy
* @param cb
*/
export const insertVersion = (
2024-07-17 14:21:31 +08:00
version: any,
cb?: (err: Error | null, document: any) => void
2023-11-27 15:03:25 +08:00
) => {
2024-07-17 14:21:31 +08:00
versionDB.insert(version, cb);
2023-11-27 15:03:25 +08:00
};
/**
*
* @param cb
*/
export const listVersion = (
2024-07-17 14:21:31 +08:00
callback: (err: Error | null, documents: any[]) => void
2023-11-27 15:03:25 +08:00
) => {
2024-07-17 14:21:31 +08:00
versionDB.find({}, callback);
2023-11-27 15:03:25 +08:00
};
export const getVersionById = (
2024-07-17 14:21:31 +08:00
id: string,
callback: (err: Error | null, document: any) => void
2023-11-27 15:03:25 +08:00
) => {
2024-07-17 14:21:31 +08:00
versionDB.findOne({id: id}, callback);
2023-11-27 15:03:25 +08:00
};
2024-07-17 14:21:31 +08:00
export const deleteVersionById = (id: string, callback: (err: Error | null, document: any) => void) => {
versionDB.remove({id: id}, callback);
}