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 🙏

© 2021 – Pkg Stats / Ryan Hefner

mysql-import

v5.0.21

Published

Import .sql into a MySQL database with Node.

Downloads

16,326

Readme

Version 5.0.21 (NPM) (Github)

Build Status Coverage Status

Import MySQL files with Node!

Table of Contents

Install

via NPM:

$ npm install --save-dev mysql-import

Via Github:

git clone https://github.com/Pamblam/mysql-import.git

TLDR:

const host = 'localhost';
const user = 'root';
const password = 'password';
const database = 'mydb';

const Importer = require('mysql-import');
const importer = new Importer({host, user, password, database});

// New onProgress method, added in version 5.0!
importer.onProgress(progress=>{
  var percent = Math.floor(progress.bytes_processed / progress.total_bytes * 10000) / 100;
  console.log(`${percent}% Completed`);
});

importer.import('path/to/dump.sql').then(()=>{
  var files_imported = importer.getImported();
  console.log(`${files_imported.length} SQL file(s) imported.`);
}).catch(err=>{
  console.error(err);
});

Methods

new Importer({host, user, password[, database]})

The constructor requires an object with a host, user, and password parameter. Passing in a database parameter is optional.

Importer.prototype.getImported()

Get an array of files imported.

Importer.prototype.setEncoding(encoding)

Set the encoding to use when reading import files. Supported arguments are: utf8, ucs2, utf16le, latin1, ascii, base64, or hex.

Importer.prototype.use(database)

Set or change the database to import to.

Importer.prototype.onProgress(callback)

(New in v. 5.0!) - Set a callback to be called as the importer processes chunks of the dump file. Callback is provided an object with the following properties:

  • total_files: The total files in the queue.
  • file_no: The number of the current dump file in the queue.
  • bytes_processed: The number of bytes of the file processed.
  • total_bytes: The size of the dump file.
  • file_path: The full path to the dump file.

Importer.prototype.onDumpCompleted(callback)

(New in v. 5.0!) - Set a callback to be called after each dump file has completed processing. Callback is provided an object with the following properties:

  • total_files: The total files in the queue.
  • file_no: The number of the current dump file in the queue.
  • file_path: The full path to the dump file.
  • error: If there was an error, the error object; if no errors, this will be null.

Importer.prototype.import(...input)

Import an .sql file or files into the database. This method will take...

  • Any number of paths to individual .sql files.
    importer.import('path/to/dump1.sql', 'path/to/dum2.sql')
  • Any number of paths that contain any number of .sql files.
    importer.import('path/to/mysqldumps/')
  • Any number of arrays containing either of the above.
    importer.import(['path/to/dump.sql', 'path/to/dumps/'])
  • Any combination of any of the above.

Importer.prototype.disconnect(graceful=true)

Disconnects the connection. If graceful is switched to false it will force close any connections. This is called automatically after files are imported so typically this method should never be required.

Contributing

Contributions are more than welcome! Please check out the Contributing Guidelines for this project.