Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/MaximilianHeidenreich/DsDDB

A "Dead Simple Deno DataBase".
https://github.com/MaximilianHeidenreich/DsDDB

Last synced: 25 days ago
JSON representation

A "Dead Simple Deno DataBase".

Awesome Lists containing this project

README

        





Deno Logo

DsDDB


A lightweight, developer friendly, key-value persistant storage solution for Deno projects.


Explore the docs »




Report Bug
·
Request Feature



## About The Project

I created this project because I needed a super simple key-value database which
could store data between script restarts. This is the result of that attempt.

Obviously it can't hold up with "real" databases but if you are just starting
out developing a new project and you want a dead simple way to store data, this
probably is the solution for you.

If you want to use it, please check out the docs for the project.

### Project Goals

- Store & Access key-value pairs (support for primitive & custom values)
- Write stored data to disk
- Load stored data from disk
- Expose a dead simple API to developers
- Don't include anything else other than Deno std


## Usage

This is the most basic example to get DsDDB up and running within your project.
For further information check out the
[API Documentation](https://doc.deno.land/https/deno.land/x/dsddb/mod.ts).

> ! Note: If you are using the load() and write() methods, you need to run your
> Deno program with the "--allow-read --allow-write" flags.

```TypeScript
// 1. Import DsDDB
import { DsDDB } from "https://deno.land/x/[email protected]/mod.ts";

// 2. Create new DsDDB instance
const database = new DsDDB();

// 3. Load from disk
await database.load();

// 4. Use database
database.set("key1", "value 1"); // Always override value.
database.set("myKey", "Hello World", false); // Never override value.

console.log(database.get("myKey"));

// 5. Write data to disk
await database.write();
```

If you want to store custom data structures, there's a solution to that as well.

```TypeScript
// 1. Import DsDDB
import { DsDDB } from "https://deno.land/x/[email protected]/mod.ts";

// 2. Define your data structure.
interface IDino {
name: string;
size: number;
birthday: Date;
}

// 3. Define your data.
let data1: IDino = {
name: "Deno",
size: 69,
birthday: new Date(),
};

// 4. Create new DsDDB instance
const database = new DsDDB();

// 5. Load from disk
await database.load();

// 6. Use database
database.set("deno", data1);

console.log(database.get("deno"));

// 7. Write data to disk
await database.write();
```