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

jsalphadb

v1.0.3

Published

Database system for NodeJS & Port of phpAlphaDB

Downloads

13

Readme

jsalphadb

Simple flat-file database system for NodeJS & Port of phpAlphaDB Version: 1.0.3

Installation

I recommend you install from NPM npm install jsalphadb Put this at the top of your javascript file.

var key = "Something"; // The secret key, though theres no point to changing it.
var ext = ".4db"; // The extension of the database.

const jsAlphaDB = require("jsalphadb");
const db = new jsAlphaDB(key, ext);

Make sure node is allowed to write to the filesystem.

Description

This is a Node.js remake of the flatfile database system made by HeapOverride called phpAlphaDB. The purpose is to create a basic, easy to learn and use flat database system for JavaScript

This was made when I was in my JavaScript infancy, so I did a lot of things wrong and wrote a lot of messy code. Since I saw there were still weekly downloads, I decided I should maintain it again and give it a little clean-up.

Docs

There is the legacy fully synchronous version still in the program, and it's exactly the same syntax as before. However, I will always recommend you use promises as they are non-blocking.

const Alpha = require("jsalphadb");

// make a new database instance
const db = new Alpha("test");
const table = "my table";

// create a table
db.create(table); // will be "my_table" on the filesystem, returns true or false if it was successful in creating it.

// add some data
db.write(table, `id=${Date.now()} name=${db.en("John Smith")} role=admin`); // each of these returns true or false if it was successful in writing it.
db.write(name, `id=${Date.now()} name=${db.en("James Kenny")} role=user`); // since we have spaces in the name, we need to encode it for it to be stored properly.
db.write(name, `id=${Date.now()} name=${db.en("Jim Johnson")} role=user`);

// get some data
const rows = db.read(name, "role=admin", "name role"); // will return James Kenny and Jim Johnson rows, with name and role. excluses the id row cuz we didn't select it.
for(const row of rows){
    // extract the data from the rows
    const name = db.de(db.column(row, "name")); // since we have encoded the name, we need to decode it now.
    const role = db.column(row, "role"); // role is plaintext
}

// delete some data
db.rowdelete(name, `name=${db.en("Jim Johnson")}`); // will remove the Jim Johnson row in our table.

// all of the same stuff but with promises
(async () => {
    const db = new Alpha.promises("test");
    const table = "my async table";

    await db.create(table);

    await db.write(table, `id=${Date.now()} name=${db.en("John Smith")} role=admin`);
    await db.write(name, `id=${Date.now()} name=${db.en("James Kenny")} role=user`);
    await db.write(name, `id=${Date.now()} name=${db.en("Jim Johnson")} role=user`);

    const rows = await db.read(name, "role=admin", "name role");
    for await(const row of rows){
        const name = await db.de(db.column(row, "name"));
        const role = await db.column(row, "role");
    }

    // delete some data
    await db.rowdelete(name, `name=${db.en("Jim Johnson")}`);
})();

License

WTFPL - http://www.wtfpl.net/