npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

datadepot

v0.1.0

Published

A file-based database system designed for storage, retrieval, and management of data. It offers multiple ways to read and store data, along with encryption functionality. DataDepot is an ideal solution for small to medium-sized projects that require a lig

Downloads

8

Readme

DataDepot

A file-based database system designed for storage, retrieval, and management of data. It offers multiple ways to read and store data, along with encryption functionality. DataDepot is an ideal solution for small to medium-sized projects that require a lightweight yet powerful data storage option without the overhead of traditional databases.

Usage

Installation

npm

npm install datadepot

yarn

yarn add datadepot

pnpm

pnpm add datadepot

Importing

cjs

const { DataDepot, Depot } = require("datadepot");

esm

import { DataDepot, Depot } from "datadepot";

Creating a db / storage container

const store = new Depot();

With TypeScript, you may declare storage type

const store = new Depot<Record<string, unknown>>();

CURD Operations

store.setItem("data", { foo: "foo", bar: "bar" });
store.updateItem("data", { foo: "bar" });
store.getItem("data"); // { foo: 'bar' }
store.removeItem("data");

One may not duplicate setting keys, update, get or remove a non-existent key, otherwise an exception will be thrown to force the program terminates.

Exporting and loading

store.load({ data: { foo: "foo", bar: "bar" } });
const json = store.export(); // { data: { foo: 'foo', bar: 'bar' } }

The method load() will load data and overwrite all data in the db/storage container.

The method export() will export all the keys and their data in json form.

These two operations shall not be often used unless necessary.

Clear & destroy

store.clear();

After calling the member method clear(), the db/storage container will be cleared.

store.destory();

After calling the member method destory(), the db/storage container will be destroyed, accessing the db/storage container afterwards in any way will lead to an exception.

Writting and Reading

Write into a chunk file with default options

DataDepot.write(store, ".");

All the data in the db/storage container will be serialized, compressed and save into a single chunk file with the specified directory. The chunk name would be an unix timestamp.

Specifying options

DataDepot.write(store, ".", {
    chunkName: "sampleChunk",
    key: "sampleKey",
});

The above example will save the data in a file named sampleChunk. And the file is symmetrically encrypted by the AES algorithm, and the key will be needed when reading the file.

Dump into multiple files

DataDepot.write(store, ".", {
    chunkName: "sampleChunk",
    key: "sampleKey",
    maxChunkCount: 3
});

With maxChunkCount option, the data will be evenly save into n chunk files.

DataDepot.write(store, ".", {
    chunkName: "sampleChunk",
    key: "sampleKey",
    maxChunkSize: 1000,
});

With maxChunkSize option, the max size of a chunk file can be specified, when the max size is reached, it will move on to next chunk file.

However, you may only specify one of the maxChunkCount or maxChunkSize option, or an exception will be thrown.

Read from chunk file(s)

DataDepot.load(store, ".", "sampleChunk", "sampleKey");

One don't need to worries about multiple file, it will find all chunk files belong to the same chunk name. Key can be omitted if it is not specified when writing.

write and read from json file

DataDepot.writeToJson(store, "sample.json");
DataDepot.loadFromJson(store, "sample.json");

About object

class SampleClass {
    constructor(a, b) {
        this.a = a;
        this.b = b;
    }
}

DataDepot.insertAnObject(store, "object", new SampleClass("a", "b"));
store.getItem("object"); // { a: 'a', b: 'b' }

DataDepot.loadFromObject(store, new SampleClass("a", "b"));
store.getItem("a"); // a

One may directly insert an object into the db/storage container, or use an object as data (overwritting all the data in db/storage container).