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

arrowment-db

v1.2.0

Published

A JSON type database similar to Mongoose, uses JSON files to save data

Downloads

99

Readme

Arrowment-DB

Arrowment-DB is a simple JSON database library for Node.js projects, similar to Mongoose but with a focus on simplicity and ease of use.

Getting Started

To start using Arrowment-DB in your project, follow these simple steps:

  1. Install Arrowment-DB using npm:

    npm i arrowment-db
  2. Create a new folder named jsonDB.js in your project directory.

  3. In the jsonDB.js file, set up the database configuration:

    // jsonDB.js
    
    import { ArrowmentJsonDB } from "arrowment-db";
    
    const jsonDB = new ArrowmentJsonDB({ data_dir: "path/to/your/data/directory" });
    
    export { jsonDB };

    Replace "path/to/your/data/directory" with the actual path to the directory where you want to store your JSON data. IT MUST BE ABSOLUTE PATH

  4. Congratulations! You have set up your JSON database. Now you can create and manage your JSON data easily.

Adding Custom String Generator

If you want to add a custom string generator function, you can do so by adding a string_generator property to the ArrowmentJsonDB configuration.

Creating Schema

To define a schema for your data, follow these steps:

  1. Create a new directory named schema in your project directory.

  2. In the schema directory, create a new file (e.g., myschema.js).

  3. In the myschema.js file, define your schema using the JsonSchema class:

    // myschema.js
    
    import { jsonDB } from "../jsonDB";
    import { JsonSchema } from "arrowment-db";
    
    const data = {
        Name: String,
        Age: Number
    };
    
    const info = new JsonSchema({ schema: data, json_class: jsonDB, name: "Info" });

    Make sure to replace "../jsonDB" with the actual path to your jsonDB.js file.

    In this example, we define a schema with two fields: Name (string) and Age (number). The schema is associated with the Info collection in the database.

Managing Data

Once you have set up your schema, you can start managing your data. Here's how:

Creating Data

To create data, simply import the schema and use the create method:

import { info } from "./schema/mySchema.js";

info.create({
    Name: "John",
    Age: 13
});

Deleting Data

To delete data, specify the query and use the delete method:

import { info } from "./schema/mySchema.js";

info.delete({ Age: 13 });

To delete multiple records matching a query, use the deleteAll method:

info.deleteAll({ Age: 13 });

Finding Data

To find data, use the findData method:

const data = await info.findData({ Age: 13 });

To find all records matching a query, use the findAllData method:

const data = await info.findAllData({ Age: 13 });

Saving Data

To save data, use the save method:

const result = await info.findData({ Age: 13 });
const data = result;

data.Name = "The Rock";

await info.save(data, { Name: "John" });

To update all records matching a query, use the updateAll method:

const result = await info.findData({ Age: 13 });
const data = result;

data.Name = "The Rock";

await info.updateAll(data, { Name: "John" });

Finding Path

To find a path, use findPath:

console.log(await personalInfo.findPath({ name: "The Rock" }))
/**
 C:/Users/techn/OneDrive/Desktop/Projects/JSON-DB/test/data/PersonalInfo/l5G0U0t2Z7t4x9u5z0q6fd3357708145db3dfbb81709888536.json
 */

To find all the paths, use findAllPath:

console.log(await personalInfo.findAllPath({ name: "The Rock" }))
/**
[
  'C:/Users/techn/OneDrive/Desktop/Projects/JSON-DB/test/data/PersonalInfo/l5G0U0t2Z7t4x9u5z0q6fd3357708145db3dfbb81709888536.json'
]
 */

Notes

CHANGES IN 1.2.0

  • All methods like findData, findAllData, save, updateAll, and their fuzzy versions now return something.
  • findData, findAllData, save, updateAll, create, and their fuzzy versions will return null if no data is found.
  • The methods findData and findAllData now return only the data, not an object containing the path and the data.
  • findData and findAllData methods return null if no data is found.
  • Methods findPath and findAllPath have been added to the JsonSchema class for finding paths.
  • Methods findPath and findAllPath return the file paths directly.
  • fuzzySearchData, fuzzySearchAllData, fuzzySearchPath, fuzzySearchAllPath, fuzzyDelete, fuzzyDeleteAll, fuzzySave, fuzzyUpdateAll methods have been added for fuzzy searching and operations.
  • Added QuickCollection, Its a map() like class but with fuzzy searching.
  • Added support for searching nested object structures.

Fuzzy Search Methods

What is fuzzy searching?

Fuzzy searching is a searching method used when you don't have the exact query or only have a rough or approximate query. In such cases, instead of requiring an exact match, fuzzy searching employs algorithms like Levenshtein's algorithm to find the best match and retrieve relevant data. This approach allows for more flexible and forgiving searches, accommodating variations in spelling, typos, or slight deviations from the original query.

Finding Data Using Fuzzy Method

To find data using the fuzzy method, use fuzzySearchData:

console.log(await personalInfo.fuzzySearchData({ name: "Jo" })); //We are not sure of the actual name
/**
  {
  name: 'John',
  Age: 13,
  id: 'l5G0U0t2Z7t4x9u5z0q6fd3357708145db3dfbb81709888536'
}
 */

To search all the data and not just one data, use fuzzySearchAllData:

console.log(await personalInfo.fuzzySearchAllData({ name: "Jo" })); //We are not sure of the actual name
/**
 [
  {
    name: 'John',
    Age: 13,
    id: 'l5G0U0t2Z7t4x9u5z0q6fd3357708145db3dfbb81709888536'
  }
]
 */

Finding Path

To find the path using fuzzy search, use fuzzySearchPath:

console.log(await personalInfo.fuzzySearchPath({ name: "Jo" })); //We are not sure of the actual name
/**
C:/Users/techn/OneDrive/Desktop/Projects/JSON-DB/test/data/PersonalInfo/l5G0U0t2Z7t4x9u5z0q6fd3357708145db3dfbb81709888536.json
 */

To find all the paths using fuzzy search, use fuzzySearchAllPath:

console.log(await personalInfo.fuzzySearchAllPath({ name: "Jo" })); //We are not sure of the actual name
/**
[
  'C:/Users/techn/OneDrive/Desktop/Projects/JSON-DB/test/data/PersonalInfo/l5G0U0t2Z7t4x9u5z0q6fd3357708145db3dfbb81709888536.json'
]
 */

Deleting Data

To delete the data using fuzzy search, use fuzzyDelete:

await personalInfo.fuzzyDelete({ name: "Jo" }); //We are not

 sure of the actual name

To delete all the data using fuzzy search, use fuzzyDeleteAll:

await personalInfo.fuzzyDeleteAll({ name: "Jo" }); //We are not sure of the actual name

Updating Data

To update one data using fuzzy search, use fuzzySave:

const s = await personalInfo.fuzzySearchData({ name: "Jo"})
s.name = "TechPowerB"

console.log(await personalInfo.fuzzySave(s, { name: "Jo" })); //We are not sure of the actual name
/**
{
  name: 'TechPowerB',
  Age: 13,
  id: 'l5G0U0t2Z7t4x9u5z0q6fd3357708145db3dfbb81709888536'
}
 */

To update everything using fuzzy search, use fuzzyUpdateAll:

const s = await personalInfo.fuzzySearchData({ name: "Jo"})
s.name = "TechPowerB"

console.log(await personalInfo.fuzzyUpdateAll(s, { name: "Jo" })); //We are not sure of the actual name
/**
{
  name: 'TechPowerB',
  Age: 13,
  id: 'l5G0U0t2Z7t4x9u5z0q6fd3357708145db3dfbb81709888536'
}
 */