dump2js

1.0.1 • Public • Published

Overview

This node.js module allows the conversion of a mysqldump file to JS Objects, which is useful for importing data into any other datasource using your own migration process.

This package has been tested on mysqldump 10.x from mysql version 5.5.

Ouput

npm2js returns an object, containing your table data keyed on table name. Each table entry has the following properties:

  • name: the name of the converted table
  • fields: an array of field definitions
    • name: name of the field
    • type: type of the field
  • values: an array of the values from the table

Sample output:

{
  users: {   // table named users
    name: 'users',
    fields: [
      {
        name: 'email',
        type: 'varchar(255)'
      },
      {
        name: 'id',
        type: 'int(11)'
      }
    ],
    values: [
      {
        email: 'someguy@yahoo.com',
        id: 1
      },
      {
        email: 'anotherdude@altavista.com',
        id: 2
      }
    ]
  }
}

Usage

Install dump2js in your project. Await dump2js.getData, providing a filename and relative path to your mysqldump.sql file.

foo@bar:~$npm install dump2js
    const dump2js = require('dump2js');
    const fileName = 'mydatadump.sql'
 
    const init = async () => {
      const data = await dump2js.getData(fileName)
      console.log(JSON.stringify(data, null, 2))
    }
 
    init()

Package Sidebar

Install

npm i dump2js

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

14.2 kB

Total Files

5

Last publish

Collaborators

  • weltertech