Fixing several bugs and adding very basic rule support
This commit is contained in:
@ -3,6 +3,8 @@ import Settings from "../settings";
|
||||
import getLevelDB from "../storage";
|
||||
import PathLock from "./lock";
|
||||
import Query from "./query";
|
||||
import { Observable } from "@hibas123/utils";
|
||||
import Logging from "@hibas123/logging";
|
||||
|
||||
export class DatabaseManager {
|
||||
static databases = new Map<string, Database>();
|
||||
@ -16,10 +18,11 @@ export class DatabaseManager {
|
||||
})
|
||||
}
|
||||
|
||||
static addDatabase(name: string) {
|
||||
static async addDatabase(name: string) {
|
||||
if (this.databases.has(name))
|
||||
throw new Error("Database already exists!");
|
||||
|
||||
await Settings.addDatabase(name);
|
||||
let database = new Database(name);
|
||||
this.databases.set(name, database);
|
||||
return database;
|
||||
@ -39,11 +42,23 @@ export class DatabaseManager {
|
||||
}
|
||||
}
|
||||
|
||||
export enum ChangeTypes {
|
||||
SET,
|
||||
PUSH
|
||||
}
|
||||
|
||||
export type Change = {
|
||||
type: ChangeTypes;
|
||||
path: string[]
|
||||
}
|
||||
|
||||
export class Database {
|
||||
public level = getLevelDB(this.name);
|
||||
private rules: Rules;
|
||||
public rules: Rules;
|
||||
public locks = new PathLock()
|
||||
|
||||
public changeObservable = new Observable<Change>();
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
name: this.name,
|
||||
|
Reference in New Issue
Block a user