1.2.0 • Published 1 year ago

@tomsd/fsdb v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@tomsd/fsdb

It's a data handler that a file is as the store.
See fsdb.netlify.app also.

npm NPM npms.io (quality) Libraries.io dependency status for latest release Maintenance

Installation

npm install @tomsd/fsdb

Usage

import { FileDb } from "@tomsd/fsdb";

const filePath = "path/to/file";
const db = new FileDb(filePath);

// getting all data
console.log(await db.get()); // {} empty object for no data saved

// saving data
console.log(
  await db.save({
    some: "thing"
  })
); // { _id: xxxxxx, some: "thing" }

// getting all data again
console.log(await db.get());
/*
{
  xxxxx: {
    _id: xxxxx,
    some: "thing"
  }
}
*/

// getting one data by id
console.log(await db.get("xxxxx")); // { _id: "xxxxx", some: "thing" }

// removing data
await db.remove("xxxxx");

// drop(file will be deleted)
await db.drop();
import { DirDb } from "@tomsd/fsdb";

const dirPath = "path/to/directory";
const db = new DirDb(dirPath);

// getting all ids
console.log(await db.getIds()); // []

// saving an item
console.log(
  await db.save({
    message: "test"
  })
); // { _id: "xxx", message: "test" }

// fetching an item
console.log(
  await db.get("xxx")
); // { _id: "xxx", message: "test" }

// deleting an item
console.log(
  await db.remove("xxx")
) // true

// drop(directory will be deleted)
console.log(
  await db.drop()
); // true
1.2.0

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago