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

havocwebdblite

v1.0.1-1

Published

Havocweb Tech Mini project DB

Downloads

581

Readme

Contributors npm Version Forks Stargazers


Installation

You can install the module using npm or yarn:

NPM:

npm i havocwebdblite

Yarn:

yarn add havocwebdblite

Usage

Importing the Module

First, import the HavocwebDB class from the module:

import HavocwebDB from "havocwebdblite";

If you're using CommonJS, you would need to require the module like this:

const HavocwebDB = require('havocwebdblite');

Initializing the Database

To initialize the database, you need to use the HavocwebDB class:

const Database = new HavocwebDB(databaseName: string, databaseUniqueID: any);

Creating a Table

To create a new table, use the addTable method. Provide the table name and a list of columns:

const createTable = async () => {
    Database.addTable(tableName: string, columnList: Array[]);
};

createTable();

Adding Rows

To add a new row to a table, use the insertIntoTable method. Provide the table name and the row data (excluding the id, which is generated automatically):

const addRows = async () => {
    Database.insertIntoTable(tableName: string, Row: {});
};

addRows();

Selecting Rows

To select rows from a table based on specific criteria, use the select method. It's similar to SQL syntax where you use:

SELECT column FROM table WHERE key = value

Here's how to use the select function in this module:

const selectExample = async () => {
    const selectingRowsWithSpecificValue = await Database.select(tableName: string, key: string, value: string);
    const selectingAllTableRows = await Database.select(tableName: string, "*", "");
    console.log("Specifics", selectingRowsWithSpecificValue, "All Details", selectingAllTableRows);
};

selectExample();

Deleting Rows

To delete rows from a table based on specific criteria, use the delete method. Provide the table name and the key-value pair:

const deleteExample = async () => {
    Database.delete(tableName: string, key: string, value: string);
    console.log('Row(s) deleted successfully');
};

deleteExample();

Testing

To test the module, you can create a test directory with test files. Here's an example of how to structure your test file to create, add, select, and delete rows assuming you are working with an Express server:

const express = require('express');
const HavocwebDB = require('havocwebdblite');

const router = express.Router();

const Database = new HavocwebDB.HavocwebDB('userTestDatabase', 200100200);

router.post('/createTable', (req, res) => {
    Database.addTable("UserTable", ["email", "name", "password"]);
    res.json({message: "Table created"});
});

router.post('/addUser', (req, res) => {
    const { name, email, password } = req.body;
    Database.insertIntoTable("UserTable", { name, email, password });
    res.json({ message: "Adding user successful" });
});

router.get("/getAllUsers", async (req, res) => {
    const UserList = await Database.select("UserTable", "*", "");
    res.send(UserList);
});

router.post("/getUser", async (req, res) => {
    const { email } = req.body;
    const UserList = await Database.select("UserTable", "email", email);
    const narrowedDownUsers = UserList[0];
    res.json({ users: UserList, narrowed: narrowedDownUsers });
});

router.post("/deleteRow", async (req, res) => {
    const { password } = req.body;
    await Database.delete("UserTable", "password", password);
    res.json({ message: "Account deletion successful" });
});

module.exports = router;

What's New (1.0.0)

Security

All databases are now encrypted upon creation, so you can rest assured that your project won't leak data in case of a security breach.

Static Functions

All HavocwebDB functions are now available as static methods. You no longer need to instantiate the HavocwebDB class before using them—simply call the static functions.

Requirements

  • The project requires environmental variables.
  • Ensure you're installing the latest version of the module.
  • fs module is required.

Installation

Same as above.

Setup

Create a .env file with the following format:

HAVOCWEB_DB_LITE_ENCRYPTION_KEY=BASE64_32_BYTE_STRING
HAVOCWEB_DB_NAME=NAME
HAVOCWEB_DB_UNIQUE_ID=UNIQUE_ID

Although we automatically generate the encryption key for you in the .env file, it’s important to modify or create your own if you want to customize it.

Make sure to enter a name and unique ID for your database before creating it.


Using the Query Method

import HavocwebDB from "havocwebdblite";

const result = await HavocwebDB.query("CREATE TABLE users (name TEXT, age INTEGER)");
console.log(result);
// Expected output: "Table users created successfully with columns: id, name, age"

const result = await HavocwebDB.query("INSERT INTO users (name, age) VALUES (1, 'John', 30)");
console.log(result);
// Expected output: "Inserted into users"

const result = await HavocwebDB.query("SELECT * FROM users WHERE name = 'John'");
console.log(result);
// Expected output: [ { id: 1, name: 'John', age: 30 } ]

const result = await HavocwebDB.query("DELETE FROM users WHERE name = 'John'");
console.log(result);
// Expected output: "Deleted from users"

isDatabaseAvailable and isTableAvailable(tableName: string)

the return boolean indicating whether the database is available or not. also same for the table.

Contribution and License Agreement

If you contribute code to this project, you are implicitly allowing your code to be distributed under the MIT license. You also implicitly verify that all code is your original work.

License

This project is licensed under the MIT License.