Skip to content

MaximilianHeidenreich/DsDDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


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.

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

// 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.

// 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<IDino>();

// 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();