1.0.1 • Published 10 months ago

rdsdb v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

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:
1.0.1

10 months ago

1.0.0

10 months ago

1.0.0-rc2

10 months ago

1.0.0-rc1

10 months ago