initial commit
This commit is contained in:
30
readme.md
Normal file
30
readme.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Simplistic JSON database
|
||||
|
||||
- Save / load all data from one JSON file
|
||||
- Automatically saves data after any modifications (create / update / delete)
|
||||
- Autoincremented ids
|
||||
|
||||
## Usage
|
||||
|
||||
```typescript
|
||||
import { Database } from "./database.ts";
|
||||
import { Table } from "./table.ts";
|
||||
|
||||
const database = await Database.load("./data.json", async (emptyDatabase) => {
|
||||
await emptyDatabase.createTable("foo");
|
||||
await emptyDatabase.createTable("bar");
|
||||
await emptyDatabase.createTable("baz");
|
||||
});
|
||||
|
||||
const fooTable = await database.getTable("foo") as Table<{
|
||||
id: number;
|
||||
name: string;
|
||||
}>;
|
||||
|
||||
const insertedEntry = await fooTable.insert({ name: "Hello world" });
|
||||
const updatedEntries = await fooTable.update(
|
||||
(candidat) => candidat.id === insertedEntry.id,
|
||||
(entry) => entry.name = "Goodbye",
|
||||
);
|
||||
const deletedEntries = await fooTable.delete(() => true);
|
||||
```
|
||||
Reference in New Issue
Block a user