bluedb
v1.0.0
Published
A lightweight json db with TypeScript support.
Downloads
18
Readme
Introduction
bluedb is a lightweight json db with TypeScript support.
Usage
import { Connection } from "bluedb";
type DatabaseSchema = {
array: string[],
object: {
nestedObject: {
string: string,
},
},
value: string | number,
};
const connection = new Connection<DatabaseSchema>("db.json");
connection.db.value = "Hello.";
connection.db.array.push("A value.");
connection.persistChanges();
Changes will be persisted synchronously.
By design, there aren't any predefined functions (e.g. for creating a collection). This is to allow for more flexibility when implementing this library in your own code. For example, you could extend it by wrapping it within a singleton-like, globally available container class.
import { Connection } from "bluedb";
type DatabaseSchema = {
array: string[],
value: string | number,
};
export class DatabaseService {
private static connection?: Connection<DatabaseSchema>;
static createConnection(path: string) {
DatabaseService.connection = new Connection<DatabaseSchema>(path);
}
static getConnection() {
if (!DatabaseService.connection) throw new Error ("No existing connection.");
return DatabaseService.connection;
}
}
import { DatabaseService } from "../path/DatabaseService"
const connection = DatabaseService.getConnection();
connection.db.value = "Hello.";
connection.persistChanges();