A lightweight json db with TypeScript support.
npm install bluedb``js
import { Connection } from "bluedb";
type DatabaseSchema = {
array: string[],
object: {
nestedObject: {
string: string,
},
},
value: string | number,
};
const connection = new Connection
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.
`js
import { Connection } from "bluedb";
type DatabaseSchema = {
array: string[],
value: string | number,
};
export class DatabaseService {
private static connection?: Connection
static createConnection(path: string) {
DatabaseService.connection = new Connection
}
static getConnection() {
if (!DatabaseService.connection) throw new Error ("No existing connection.");
return DatabaseService.connection;
}
}
``js
import { DatabaseService } from "../path/DatabaseService"
const connection = DatabaseService.getConnection();
connection.db.value = "Hello.";
connection.persistChanges();
``