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

jexidb

v1.0.4

Published

JexiDB is a pure JS NPM library for managing data on disk using JSONL efficiently, without the need for a server.

Downloads

197

Readme

Overview

JexiDB is a lightweight, standalone JavaScript database manager that stores data on disk using either JSON format or V8 serialization. It supports indexing and querying capabilities for efficient data operations. Ideal for local Node.js projects as well as apps built with Electron or NW.js. Written in pure JavaScript, it requires no compilation and is compatible with both CommonJS and ESM modules.

Installation

To install JexiDB, you can use npm:

npm install EdenwareApps/jexidb

Usage

Creating a Database Instance

To create a new instance of the database, you need to provide a file path where the database will be stored and an optional configuration object for indexes.

// const { Database } = require('jexidb'); // commonjs

import { Database } from 'jexidb'; // ESM

const db = new Database('path/to/database.jdb', { // file will be created if it does not already exist
  v8: false, // false by default, set to true to use V8 serialization instead of JSON.
  compress: false, // set to true to compress each entry
  compressIndex: false, // set to true to compress the index only
  indexes: { // keys to use in queries, only those key values ​​are kept in memory, so fewer specified keys lead to improved performance
    id: 'number',
    name: 'string'
  }
});

You can learn a bit more about these options at this link.

Initializing the Database

Before using the database, you need to initialize it. This will load the existing data and indexes from the file.

await db.init();

Only the values ​​specified as indexes are kept in memory for faster queries. JexiDB will never load the entire file into memory.

Inserting Data

You can insert data into the database by using the insert method. The data should be an object that contains the defined indexes. All object values will be saved into database.

await db.insert({ id: 1, name: 'John Doe' });
await db.insert({ id: 2, name: 'Jane Doe', anyArbitraryField: '1' });

Querying Data

The query method allows you to retrieve data based on specific criteria. You can specify criteria for multiple fields.

const results = await db.query({ name: 'John Doe' });
console.log(results); // [{ id: 1, name: 'John Doe' }]

Note: For now the query should be limited to using the fields specified as 'indexes' when instantiating the class.

Querying with Conditions

You can use conditions to perform more complex queries:

const results = await db.query({ id: { '>': 1 } });
console.log(results); // [{ id: 2, name: 'Jane Doe' }]

Updating Data

To update existing records, use the update method with the criteria to find the records and the new data.

await db.update({ id: 1 }, { name: 'John Smith' });

Deleting Data

You can delete records that match certain criteria using the delete method.

const deletedCount = await db.delete({ name: 'Jane Doe' });
console.log(`Deleted ${deletedCount} record(s).`);

Iterating Through Records

You can iterate through records in the database using the walk method, which returns an async generator.

for await (const record of db.walk()) {
  console.log(record);
}

Saving Changes

After making any changes to the database, you need to save them using the save method. This will persist the changes to disk.

await db.save();

Conclusion

JexiDB provides a simple yet powerful way to store and manage data in JavaScript applications. With its indexing and querying features, you can build efficient data-driven applications.

Contributing

Please, feel free to contribute to the project by opening a discussion under Issues section or sending your PR.

If you find this library useful, please consider making a donation of any amount via PayPal by clicking here to help the developer continue to dedicate himself to the project. ❤