Skip to content

superhero/js.db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DB

Licence: MIT


npm version

A simple DB interface implementation that reads queries from a file, segregating your code from your queries.

Install

npm install @superhero/db

...or just set the dependency in your package.json file:

{
  "dependencies":
  {
    "@superhero/db": "*"
  }
}

Example | MySql

const
connections     = 5,
host            = 'mysql.example.com',
user            = 'root',
password        = 'b4real',
filePath        = '/sql',
fileSuffix      = '.sql',
mysql           = require('mysql'),
Db              = require('@superhero/db'),
AdapterFactory  = require('@superhero/db/adapter/mysql/factory'),
adapterFactory  = new AdapterFactory(),
adapter         = adapterFactory.create(mysql, { connections, host, user, password }),
db              = new Db(adapter, filePath, fileSuffix),
result          = await db.query('file', ['context'])

The example above will create a pool with 5 idle connections and query the database with the content from the /sql/file.sql file composed with the specified context.

Example | Postgres

const
host            = 'postgres.example.com',
user            = 'root',
database        = 'stuff',
password        = 'b4real',
filePath        = '/sql',
fileSuffix      = '.sql',
pg              = require('pg'),
Db              = require('@superhero/db'),
AdapterFactory  = require('@superhero/db/adapter/postgres/factory'),
adapterFactory  = new AdapterFactory(),
adapter         = adapterFactory.create(pg, { host, user, password, database }),
db              = new Db(adapter, filePath, fileSuffix),
result          = await db.query('file', ['context'])

The example above will create a pool and query the database with the content from the /sql/file.sql file composed with the specified context.

About

DB interaction, designed to separate queries from the source code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors