npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mysql-mongo-db

v1.0.5

Published

Mysql and Mongodb interface for basic database operations

Readme

Synopsis

This is a Mysql and Mongodb interface for basic database operations (CRUD).

Code Example

Creat Mysql object

const mysql_mongo = require('mysql-mongo-db')

const mysql = mysql_mongo.createDB('MySQL')

Create Mongo object

const mysql_mongo = require('mysql-mongo-db')
const mongodb = mysql_mongo.createDB('MongoDB')

Connect to database

let config = { host: 'my-host', user: 'my-user', pass: 'my-pass', db: 'my-db' }
mysql.connect(config, err => {
  if(err) throw err
  console.log(`Connected in ${config.host}/${config.db}`)
})
let config = { host: 'my-host', user: 'my-user', port: 27017, pass: 'my-pass', db: 'my-db' }
mongodb.connect(config, err => {
  if(err) throw err
  console.log(`Connected in ${config.host}/${config.db}`)
})

CRUD Mysql

let valuesToInsert = {nombre: 'John Doe', age: 40, address: '42th. Street'}
mysql.insert('my_table', valuesToInsert, (err, res) => {
  if (err) throw err
  console.log(res)
})

let valuesToUpdate = {name: 'Johana Daw', age: 30}
let updateParams = {where: 'id = 1' and: 'name = John Doe'}
mysql.update('my_table', valuesToUpdate, updateParams, (err, res) => {
  if (err) throw err
  console.log(`Changed rows: ${res.changedRows}`)
  t.end()
})

let deleteParams = {where: 'id = 1'}
mysql.delete('my_table', deleteParams, (err, res) => {
  if (err) throw err
  console.log(`Affected rows: ${res.affectedRows}`)
  t.end()
})

Params in mysql database operations If you want to add some params like where sentence (or like, limit, etc), you must use a object like:

let params = {where: 'id > 1 ', and: 'age > 10'}

Examples with Select

// This will get all the rows of my_table
mysql.select('my_table', null, null, (err, res, fields) => {
  if (err) throw err
  console.log(`Num results: ${res.length}`)
})

// This will get all the data with specific columns 
let columns = ['nombre', 'edad'] // Must be an array
mysql.select('my_table', columns, null, (err, res, fields) => {
  if (err) throw err
  console.log(`Num results: ${res.length}`)
})

// This will get all the data with specific columns and the params
let selectParams = {where: 'id_pruebas > 1'}
mysql.select('my_table', columns, selectParams, (err, res, fields) => {
      if (err) throw err
      console.log(`Num results: ${res.length}`) 
    })

CRUD Mongogb Before crud, you need create a schema and model:

// Basic schema, you can do more complex if you want
let schema = {name: String, age: Number, address: String}
let personSchema = mongodb.create(schema)
let PersonModel = mongodb.createModel('my_collection', itemSchema)

Using the previous example:

let doc = {name: 'Jason', age: 25, address: '7th. Street'}
const docModel = new PersonModel(doc)

mongoDb.save(docModel, (error, docStored) => {
  if (err) throw err
  console.log(docStored)
})

// You can get the id with the find method
let newValue = {age: 30}
mongoDb.updateById(docModel, '5873e9666e75a111102c073b', newValue, (err, doc) => {
  if (err) throw err
  console.log(doc)
})

// You can use other find method, explained below
mongoDb.findOne(docModel, (err, doc) => {
  if (err) throw err
  mongoDb.remove(doc, (err) => {
    if (err) throw err
  })
})

mongoDb.find(docModel, null, (err, docs) => {
  if (err) throw err
  console.log(docs)
})

// With params
mongoDb.find(docModel, {age: 30}, (err, docs) => {
  if (err) throw err
  console.log(docs)
})

mongoDb.findOne(docModel, (err, docs) => {
  if (err) throw err
  console.log(docs)
})

mongoDb.findById(docModel, '5873e9666e75a111102c073b', (err, docs) => {
  if (err) throw err
  console.log(docs)
})

Close connection


mysql.close()

// Or with callback

mysql.close(() => {
  // Do something you want
})

// Will print message in console 
mongoDb.close(() => {
})

Motivation

I want to create a db library that you can use mysql or mongodb easily and in the same interface.

Installation

npm install mysql-mongo-db --save

License

MIT