@tomsd/fsdb
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

@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

Readme

Keywords

Package Sidebar

Install

npm i @tomsd/fsdb

Weekly Downloads

2

Version

1.2.0

License

MIT

Unpacked Size

17.5 kB

Total Files

11

Last publish

Collaborators

  • tomsd