Skip to content

Commit

Permalink
Merge pull request #8 from windchime-yk/release-v1
Browse files Browse the repository at this point in the history
Release v1
  • Loading branch information
windchime-yk committed Jan 26, 2021
2 parents d4a8175 + 39e2adb commit 226a352
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Deno JSON DB
# BracesDB
[日本語](./README_JP.md) / English】

DB module in JSON format created by Deno.
DB module in JSON format created with Deno.

## Notes
**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](https://github.com/windchime-yk/deno-json-db/issues/new).
**This module does not support encryption. Do not use it to store important data.**

## Feature
- Deno Modules
Expand All @@ -22,6 +19,8 @@ If the feature you need is not present in the "Upcoming features", please let us
- [x] Asynchronous support
- [x] 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](https://github.com/windchime-yk/bracesdb/issues/new). 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.

Expand All @@ -31,14 +30,14 @@ When creating a file, you must add `--allow-read` and `--allow-write` at executi
`filename` is the DB name. Default name is `main`.

``` typescript
import { JsonDB } from "https://github.com/windchime-yk/deno-json-db/raw/master/mod.ts";
import { BracesDB } from "https://deno.land/x/bracesdb/mod.ts";

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

const db = new JsonDB<DB>({
const db = new BracesDB<DB>({
type: "file",
folder: "./db/",
filename: "test",
Expand Down Expand Up @@ -79,8 +78,8 @@ const dataAll = await db.find();
### Test
Execute the following command.
``` bash
$ git clone git@github.com:windchime-yk/deno-json-db.git
$ cd path/to/deno-json-db
$ git clone git@github.com:windchime-yk/bracesdb.git
$ cd path/to/bracesdb

# If there is no Denon
$ deno test --allow-write --allow-read
Expand Down
17 changes: 8 additions & 9 deletions README_JP.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Deno JSON DB
# BracesDB
【日本語 / [English](./README.md)

Denoで作られたJSON形式のDBモジュール。

## 注意事項
**まだ開発中のモジュールです。**
NeDBのようなモジュールを目指し、試験的に実装しています。

もし必要な機能が『今後追加される機能』になければ、[Issues](https://github.com/windchime-yk/deno-json-db/issues/new)で教えてください。
**このモジュールは暗号化に対応していません。重要なデータの保存には用いないでください。**

## 特徴
- Denoモジュール
Expand All @@ -22,6 +19,8 @@ NeDBのようなモジュールを目指し、試験的に実装しています
- [x] 非同期対応
- [x] 正規表現による部分検索

もし必要だと思う機能がなければ、[Issues](https://github.com/windchime-yk/bracesdb/issues/new)で教えてください。参考にします。

## API
ファイルを作成する保存形式では、ファイルの読み込みと書き込みを行なうため、実行の際に`--allow-read``--allow-write`をつけてください。

Expand All @@ -30,14 +29,14 @@ NeDBのようなモジュールを目指し、試験的に実装しています
`folder`はDBファイルを格納するフォルダのパスです。デフォルトではプロジェクトルートに生成されます。
`filename`はDBファイルの名前です。デフォルトは`main`です。
``` typescript
import { JsonDB } from "https://github.com/windchime-yk/deno-json-db/raw/master/mod.ts";
import { BracesDB } from "https://deno.land/x/bracesdb/mod.ts";

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

const db = new JsonDB<DB>({
const db = new BracesDB<DB>({
type: "file",
folder: "./db/",
filename: "test",
Expand Down Expand Up @@ -79,8 +78,8 @@ const dataAll = await db.find();
## テスト
以下のコマンドを実行してください。
``` bash
$ git clone git@github.com:windchime-yk/deno-json-db.git
$ cd path/to/deno-json-db
$ git clone git@github.com:windchime-yk/bracesdb.git
$ cd path/to/bracesdb

# Denonがない場合
$ deno test --allow-write --allow-read
Expand Down
12 changes: 6 additions & 6 deletions mod.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
import { JsonDB } from "./mod.ts";
import { BracesDB } from "./mod.ts";

interface Test {
name?: string;
Expand Down Expand Up @@ -32,7 +32,7 @@ const dataList: Test[] = [

const folder = "./db/store";
const filename = "test";
const addDb = async (db: JsonDB<Test>): Promise<void> => {
const addDb = async (db: BracesDB<Test>): Promise<void> => {
for (const item of dataList) {
await db.add(
{
Expand All @@ -52,7 +52,7 @@ Deno.test(
"Add item",
async (): Promise<void> => {
try {
const db = new JsonDB<Test>({
const db = new BracesDB<Test>({
type: "file",
folder,
filename,
Expand All @@ -69,7 +69,7 @@ Deno.test(
"Delete item",
async (): Promise<void> => {
try {
const db = new JsonDB<Test>({
const db = new BracesDB<Test>({
type: "file",
folder,
filename,
Expand All @@ -88,7 +88,7 @@ Deno.test(
"Find item",
async (): Promise<void> => {
try {
const db = new JsonDB<Test>({
const db = new BracesDB<Test>({
type: "file",
folder,
filename,
Expand All @@ -107,7 +107,7 @@ Deno.test(
"Partial find item",
async (): Promise<void> => {
try {
const db = new JsonDB<Test>({
const db = new BracesDB<Test>({
type: "file",
folder,
filename,
Expand Down
6 changes: 3 additions & 3 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isExistFileSync, writeFileSync, readFileSync, writeFile } from 'https://github.com/windchime-yk/deno-util/raw/master/mod.ts';

export type JsonDBOption = {
export type BracesDBOption = {
/**
* Save type.
*
Expand All @@ -25,13 +25,13 @@ export type JsonDBOption = {
filename?: string
}

export class JsonDB<T> {
export class BracesDB<T> {
private readonly type: string
private readonly folder?: string
private readonly file: string
private data: T[]

constructor(option: JsonDBOption) {
constructor(option: BracesDBOption) {
const { type, folder = './', filename = 'main' } = option

this.type = type
Expand Down

0 comments on commit 226a352

Please sign in to comment.