Package Exports
- mysql-import
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mysql-import) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Import MySQL files with Node!
Table of Contents
Install
via NPM:
$ npm install --save-dev mysql-importVia Github:
git clone https://github.com/Pamblam/mysql-import.gitTLDR:
const host = 'localhost';
const user = 'root';
const password = 'password';
const database = 'mydb';
const mysql_import = require('mysql-import');
const Importer = require('../mysql-import.js');
const importer = new Importer({host, user, password, database});
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.import(...input)
Import an .sql file or files into the database. This method will take...
- Any number of paths to individual
.sqlfiles.importer.import('path/to/dump1.sql', 'path/to/dum2.sql') - Any number of paths that contain any number of
.sqlfiles.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.