Skip to main content

BracesDB

日本語 / English】

DB module in JSON format created with Deno.

Notes

This module does not support encryption. Do not use it to store important data.

Feature

  • Deno Modules
  • Save in JSON format
  • The storage formats are in-memory and file

Upcoming features

  • Write data
  • Delete the specified data
  • Return data that matches the condition
  • Save the data as a file
  • Asynchronous support
  • Partial search with regular expressions

If you don’t see a feature you think you need, please let us know what you want in Issue. It will be used as a reference for implementation.

API

When creating a file, you must add --allow-read and --allow-write at execution to read and write the file.

Create DB

type is the DB type. If it is “file”, it is a file; if it is “memory”, it is managed in-memory.
folder is the DB path. Default path is project root.
filename is the DB name. Default name is main.

import { BracesDB } from "https://deno.land/x/bracesdb/mod.ts";

interface DB {
  name?: string;
  description?: string;
}

const db = new BracesDB<DB>({
  type: "file",
  folder: "./db/",
  filename: "test",
});

Add an Object to the DB

The first argument is the Object to add to the DB.
The second argument is the key used in the duplication prevention process.

const test = {
  name: "Toika Asomaka",
  description: "A name that just popped into my head",
};

await db.add(test, "name");

Remove matching objects from DB

The first argument is the key, and the second argument is the value of the key.

await db.delete("name", "Toika Asomaka");

Searching the DB

Perfect match and partial match supported.
Returns an Object that matches the conditions, with the name of the key as the first argument and the value of the key as the second argument.
No arguments return all DB data.

// Perfect match
const data = db.find("name", "Toika Asomaka");
// Partial match
const dataPartial = db.find("name", /Toika/);
// All DB data
const dataAll = db.find();

Test

Execute the following command.

$ git clone git@github.com:windchime-yk/bracesdb.git
$ cd path/to/bracesdb

# If there is no Denon
$ deno test --allow-write --allow-read
# If you have a Denon
$ denon test

On translation

I am using “DeepL Translation” to translate this README.