1.0.0 • Published 4 years ago

mysqldumpjs v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

MySQLDump.js

A tiny wrapper around mysqldump utility to generate a dump file of a MySQL database.

Usage

  • yarn add mysqldumpjs
  • Import the package:
import MySQLDump from "mysqldumpjs";

Dump all tables

new MySQLDump({
  dbName: process.env.DATABASE_NAME,
  password: process.env.DATABASE_PASSWORD,
}).doBackup("outputFileName");

Dump specific tables

new MySQLDump({
  dbName: process.env.DATABASE_NAME,
  password: process.env.DATABASE_PASSWORD,
  flags: {
    tables: ["customers", "orders"],
    compact: true,
  },
}).doBackup("outputFileName");

Dump tables with where clause

new MySQLDump({
  dbName: process.env.DATABASE_NAME,
  password: process.env.DATABASE_PASSWORD,
  flags: {
    tables: [
      "customers",
      "orders",
      { table: "products", where: "product_id = 4" },
      { table: "shippers", where: "name = 'Hettinger LLC'" },
    ],
    compact: true,
  },
}).doBackup("outputFileName");

Options

These are mysqldump options you can pass in to a MySQLDump instance.

OptionDescriptionDefault
tablesThe list of tables you want to export[]
noDataDo not dump table contentsfalse
whereDump only rows selected by given WHERE conditionfalse
compactProduce more compact outputfalse
addDropDatabaseAdd DROP DATABASE statement before each CREATE DATABASE statementfalse
addDropTableAdd DROP TABLE statement before each CREATE TABLE statementfalse
withRoutinesDump stored routines (procedures and functions) from dumped databasesfalse