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-db

v0.0.6

Published

MySQL database modeling with built in CRUD. Just set the schema and get up and running.

Downloads

14

Readme

MySQL Database Wrapper

MYSQL-DB Dependency badge

MySQL database modeling with built in CRUD. Just create your models, then get up and running.

Installation - Node

npm install --save mysql-db

Environmental Variables

Configuration

  • NODE_ENV - will use test environmental variables if NODE_ENV=test

  • SHOW_DEBUG - if true, will show log messages

  • DB_HOST

  • DB_USER

  • DB_PASSWORD

  • DB_DATABASE

If NODE_ENV is "test", then the following environmental variables will be used:

  • DB_TEST_HOST
  • DB_TEST_USER
  • DB_TEST_PASSWORD
  • DB_TEST_DATABASE

Usage

To use this package to connect to your database you must first:

  1. Setup the environmental variables to connect to your database
  2. Create a new model for every CRUD table/view (and set up any defaults for new rows and for updates)
  3. Use CRUD on your model as you please!

Create a new CRUD model

var Database = require('mysql-db');

var pages = new Database.crud({
	schema: {
		select: [
				'id',
				'slug',
				'title',
				'category',
				'content',
				'created',
				'modified',
				'tags'
		],
		from: 'pages'
	}
});

// default values that will be added to every create/new row inserted
pages.setCreateDefaults({
	created: "UTC_TIMESTAMP()",
	modified: "UTC_TIMESTAMP()"
});

// default values that will be added to every row update
pages.setUpdateDefaults({
	modified: "UTC_TIMESTAMP()"
});

module.exports = pages;

Use the new model to get data

pages.get({},function(err,result){
	// Do stuff
	console.error(err);
	console.log(result);
});

Edit/update fields in the database

pages.update({
	edit: {
		title: 'hi'
	},
	criteria: {
		id: 1
	}
},function(err,result){
	// get response
});

Note: In this example, the modified field is automatically set to UTC_TIMESTAMP() since we previously defined the default when creating the pages model (by using pages.setUpdateDefaults)

Delete an entry

pages.delete({
	id: 3
}, function(err,result){
	// get response
});

Insert/create an entry

pages.create({
	id: 25,
	title: 'hello world',
	content: 'it is a wonderful day!'
},function(err,result){
	// get response
});

Note: In this example, the created and modified are automatically set since we previously set them with pages.setCreateDefaults when defining the model


TODO

  • switch to promises
  • add tests

Changelog

| Version | Notes | |---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 0.0.0 | Intiial version with callbacks |