A simple DB based on Deno.
This module is a work in progress.
We are working on a pilot implementation of a module like NeDB.
If the feature you need is not present in the “Upcoming features”, please let us know what you want in Issue.
When creating a file, you must add --allow-read
and --allow-write
at execution to read and write the file.
The first argument is the DB type. If it is “file”, it is a file; if it is “memory”, it is managed in-memory.
The second argument is the DB path. If it is “file”, it will be an error if it is not written.
import { SimpleDB } from 'https://github.com/windchime-yk/deno-simple-db/raw/master/mod.ts'
interface DB {
_id: string,
name?: string
}
const db = new SimpleDB<DB>({
type: 'file',
folder: './db/',
})
The first argument is the Object to add to the DB.
The second argument is the key used in the duplication prevention process.
import { v4 } from 'https://deno.land/std@0.77.0/uuid/mod.ts';
const test = {
_id: v4.generate(),
name: 'Asomaka Toika'
}
await db.add(test, 'name')
The first argument is the key, and the second argument is the value of the key.
await db.delete('name', 'Asomaka Toika')
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.
const data = await db.find('name', 'Asomaka Toika')
const dataAll = await db.find()
Execute the following command.
$ git clone git@github.com:windchime-yk/deno-simple-db.git
$ cd path/to/deno-simple-db
# If there is no Denon
$ deno run --allow-write --allow-read test.ts
# If you have a Denon
$ denon test
I am using “DeepL Translation” to translate this README.
Author: windchime-yk
Source Code: https://github.com/windchime-yk/deno-json-db
#deno #nodejs #node #javascript #json