Latest Release: 1.0.0-rc2
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()
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 insteadaddStatement(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.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.0-rc2:
- Redo README.md as it was out of date
- 1.0.0-rc1: