Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rdsdb

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rdsdb

Lightweight API to use in conjunction with MySQL. Built on promise-mysql

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Latest Release: 1.0.0-rc3

Old Package

What's New?

RDSDB

RDSDB is a simple database using node.js and promise-mysql that allows you to 'build' your own sql statements.

Installation

 $ npm i -g rdsdb

Using RDSDB

RDSDB.Builder() [ PREFERRED ]

First, we will just connect our db. You can use all the connection options as promise-mysql.

const { RDSDB } = require("../rdsdb.js")

require('dotenv').config() // only used for process.env, not strictly required.

const exampleDB = new RDSDB.Builder({
    host: process.env.DB_HOST,
    port: 3306,
    database: process.env.TEST_DB,
    user: process.env.TEST_DB_USERNAME,
    password: process.env.TEST_DB_PASSWORD,
    table: process.env.TEST_TABLE,
    supportBigNumbers: true,
    reconnect: true
});

The builder contains 7 different functions to build a query.

  • insertInto() adds INSERT INTO ${table} to the statement.
  • update() adds UPDATE ${table} to the statement.
  • listWithParenthesis(any[]) adds a list, for ex. (one, two, three)
  • valuesList(any[]) adds a string list, for ex. (`one`, `two`, `three`)
  • setValue(key, value) adds a key with a value, for ex. one = `1`
  • where(key, value) is the same assetValue(), but use this for where clauses instead
  • addStatement(string) adds whatever you put in on to the end of the statement.

At the very end, just call .exec() to run your query. This does return a Promise

Some examples of simple queries are:

Insert into table
exampleDB.insertInto().valuesList([`test`, `wow`])
Update test and test2 given preset id and secondid
testDB.update().setValue(`test`, 1).setValue(`test2`, true).where(`id`, 47283).where(`secondid`, 582356763)


 

A full file could look like:

const { RDSDB } = require("rdsdb")

require('dotenv').config()

const testDB = new RDSDB.Builder({
    host: process.env.TEST_HOST,
    port: 3306,
    database: process.env.TEST_DB,
    user: process.env.TEST_DB_USERNAME,
    password: process.env.TEST_DB_PASSWORD,
    table: process.env.TEST_TABLE,
    supportBigNumbers: true,
    reconnect: true
});

async function test() {
    await testDB.ensureConnection();

    // testDB.insertInto().valuesList([`test`, `wow`])
    testDB.update().setValue(`test`, 1).setValue(`test2`, true).where(`id`, 47283).where(`secondid`, 582356763)

    await testDB.exec().catch((err) => {
        console.error(err)
    })
}

test();

Changelog

  • 1.0.1:
    • rdsdb.d.ts added
  • 1.0.0:
    • Remove 1.0.0-rc1 as I may have exposed my .env
    • Remove DarksDB and DarksDBBuilder classes (carried over from the old project)
  • 1.0.0-rc2:
    • Redo README.md as it was out of date
  • 1.0.0-rc1:

Keywords

FAQs

Package last updated on 07 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc