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

express-database

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-database

Simple database middleware for Express

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

express-database

travis package version nodejs version license downloads

Usage

const mysql = require('express-database-mysql')
const app = express()

// define here routes without needed database connection
// ex: static routes, index page, etw.

// use the database middleware
app.use(database({
  db: mysql("mysql://foo:bar@example.com/db")
})

app.get("/api/foobar", function(req, res, next) {
  const { query, set, get, connect } = req.database
  
  query('show databases').then([rows] => rows)  // our abstract api
  connect.do.some() // yours unsafe raw connector
  
  // ...
  
  // the database connection will be closed automatically 
  res.render('page')
})

API

req.database
  • req.database - reference to connection to your database.
  • req.database.connect - reference to raw connection to your database
  • req.database.close - close connection to database, called automatically.

options

  • options.db - connection's constructor; it should have method open that return Promise with connection.

Connectors

Each connector should have connect property and method close(). Is's required api. Connectors can have any count of other helper methods. Each method should return Promise. Property connect should hold reference to raw api. See express-database-mysql as example.

License

MIT, 2016 (c) Dmitry Tsvettsikh

Keywords

FAQs

Package last updated on 18 Aug 2016

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