dbqp

0.0.2 • Public • Published

dbqp

A sync tool for MySQL database schema

Description

dbqp may help you dump database schema, diff (even sychronise directly) schemas of two databases.

Name dbqp is made up of abbreviation word db and its reflection qp.

dbqp

Declarations and Attentions

  • The author will be NOT responsible for any damage caused by dbqp on your database or data. Please do backup before using dbqp.
  • Until now, ONLY MySQL is supported.
  • Until now, ONLY TABLES are manipulated.
  • Until now, NO DROP opertaion is supported.

ToC

Get Started

dbqp offers both API and CLI.

CLI Mode

When installed globally, dbqp generates a homonymic command help you to manage database schema in command line.

# Install globally. 
npm install -g dbqp
 
# Dump schema of database "employees". 
dbqp dump --host localhost --user root --password root --database employees

Run dbqp help for entire manual.

API Mode

Of course, you can require dbqp into your Node.js program.

const dbqp = require('dbqp');
 
let conn = new dbqp.Connection({
    host: 'localhost',
    port: 3306,
    user: 'root',
    password: 'root',
});
 
conn.dump('employees', (err, metaJson) => {
    // ...
});
 
conn.diff('employeesCopy', 'employees', (err, SQLs) => {
    // ...
});

Standalone API Mode

Sub module of dbqp may be required as standalone module for specified task.

const dump = require('dbqp/mysql/dump');
 
const conn = {
    host: 'localhost',
    port: 3306,
    user: 'root',
    password: 'root',
}
dump(conn, 'employees', (err, metaJson) => {
    // ...
});

API

dbqp.Connection

const Connection = require('dbqp').Connection;
  • class dbqp.Connection( Object connOptions )
  • Promise <conn>.dump( string dbName )
  • Promise <conn>.diff( string refererDbName, string refereeDbName )
  • Promise <conn>.sync( string refererDbName, string refereeDbName )
  • void <conn>.dump( string dbName, Function callback )
  • void <conn>.diff( string refererDbName, string refereeDbName, Function callback )
  • void <conn>.sync( string refererDbName, string refereeDbName, Function callback )
  • void <conn>.destroy()

See also API Parameters.

dbqp/mysql/dump

const dump = require('dbqp/mysql/dump');
  • Promise <conn>.dump( Object connOptions, string dbName )
  • void <conn>.dump( Object connOptions, string dbName, Function callback )

See also API Parameters, dbqp Dump for MySQL.

dbqp/mysql/diff

const diff = require('dbqp/mysql/diff');
  • Promise <conn>.diff( Object connOptions, string refererDbName, string refereeDbName )
  • void <conn>.diff( Object connOptions, string refererDbName, string refereeDbName, Function callback )

See also API Parameters, dbqp Diff for MySQL.

dbqp/mysql/sync

const sync = require('dbqp/mysql/sync');
  • Promise <conn>.sync( Object connOptions, string refererDbName, string refereeDbName )
  • void <conn>.sync( Object connOptions, string refererDbName, string refereeDbName, Function callback )

See also API Parameters.

API Parameters

  • connOptions Object
    Contains necessary parameters required to connect to a MySQL server.

    {
        host, /* string DEFAULT 'localhost' */
        port, /* number DEFAULT 3306 */
        user, /* string */
        password, /* string */
    }
  • callback Function(Error, any)

Examples

Release Database Design

Suppose that you are in charge of maintaining an application which depending on a database.

In first edition v1.0, a SQL file 1.0.sql offered to initialize the database.

In second edition v2.0, something changed in database. A new SQL file 2.0.sql offered to initialize the database. However, to help early users of v1.0 to upgrade their existing databases, another upgrade-from-1.0.sql is necessary.

In third edition v3.0, more changes happened. You have to offer following SQL files:

  • 3.0.sql for new users.
  • uprade-from-2.0.sql for early users of v2.0.
  • uprade-from-1.0.sql for early users of v1.0.

When more and more editions released, it is really difficult to maintain more and more SQL files.

---- It can be easy with dbqp. ----

  • If you are developer, use dbqp dump to create schema.json which will be delivered to your users.
  • If you are user, whatever a new user or early user, use dbqp sync to make your database ready. Of course, you should create an empty database if it not exists.

Package Sidebar

Install

npm i dbqp

Weekly Downloads

2

Version

0.0.2

License

Apache License 2.0

Unpacked Size

67.6 kB

Total Files

28

Last publish

Collaborators

  • youngoat