Simple JSON Database for Deno.

Simple JSON “database” for Deno. You can use it for small projects like a url shortener.

INFO: If you find a bug or have a feature request, feel free to create an issue or contribute. 🙂

Run

deno run --allow-read --allow-write xxx.ts

Quick Usage

import { SimpleDB } from "https://raw.githubusercontent.com/EntenKoeniq/SimpleDB/master/mod.ts";

const db = new SimpleDB({filePath: "./test.json"}); // or 'new SimpleDB();' to create a database with the default name "db.json"

/* ===== INSERT ===== */
let insert = await db.insert({ username: "EntenKoeniq" });
console.log(`${insert.username}`);

/* ===== FIND ONE ===== */
let findOne = await db.findOne("username", insert.username);

if (typeof findOne === "undefined") console.log("Not found!");
else console.log(findOne);

/* ===== UPDATE ===== */
await db.findOneAndUpdate(insert.username, "username", "KoeniqEnten");
console.log("Username updated!");

/* ===== EXISTS ===== */
console.log(await db.exists("username", insert.username));

/* ===== DELETE ===== */
let deleteIt = await db.delete(insert.username);
console.log(`Error: ${deleteIt.error} | Message: ${deleteIt.message}`);

JSON example

{
  "n2toa7c4yr2ils1gmdlitu55": {
    "username": "KoeniqEnten"
  }
}

How to use

insert

db.insert({ url: "google.de", short: "cj5f39", clicks: 0 }); // insert (You can only insert values as string or number!)

exists

db.exists("url", "google.de"); // return a boolean value

findOne

db.findOne("url", "google.de");

/* ===== RESULT ===== */
{
  "url": "google.de",
  "short": "cj5f39",
  "clicks": 0
}

findOneAndUpdate

db.findOneAndUpdate("google.de", "url", ".degoogle"); // Search a value and replace one key with the new value

delete

db.delete("google.de"); // Delete the first object with the value "google.de"

Download Details:

Author: EntenKoeniq

Source Code: https://github.com/EntenKoeniq/SimpleDB

#deno #nodejs #node #javascript

Simple JSON  Database for Deno.
10.25 GEEK