Gathering detailed insights and metrics for mysql2-import
Gathering detailed insights and metrics for mysql2-import
Gathering detailed insights and metrics for mysql2-import
Gathering detailed insights and metrics for mysql2-import
npm install mysql2-import
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
111,940
Last Day
4
Last Week
388
Last Month
1,993
Last Year
31,706
MIT License
110 Commits
1 Forks
4 Branches
1 Contributors
Updated on May 03, 2021
Latest Version
5.0.22
Package Id
mysql2-import@5.0.22
Size
39.53 kB
NPM Version
6.14.12
Node Version
14.16.1
Published on
May 03, 2021
Cumulative downloads
Total Downloads
Last Day
33.3%
4
Compared to previous day
Last Week
-18.1%
388
Compared to previous week
Last Month
23.7%
1,993
Compared to previous month
Last Year
-29.2%
31,706
Compared to previous year
1
7
Import MySQL files with Node!
via NPM:
$ npm install --save-dev mysql-import
Via Github:
git clone https://github.com/Pamblam/mysql-import.git
1const host = 'localhost'; 2const user = 'root'; 3const password = 'password'; 4const database = 'mydb'; 5 6const Importer = require('mysql-import'); 7const importer = new Importer({host, user, password, database}); 8 9// New onProgress method, added in version 5.0! 10importer.onProgress(progress=>{ 11 var percent = Math.floor(progress.bytes_processed / progress.total_bytes * 10000) / 100; 12 console.log(`${percent}% Completed`); 13}); 14 15importer.import('path/to/dump.sql').then(()=>{ 16 var files_imported = importer.getImported(); 17 console.log(`${files_imported.length} SQL file(s) imported.`); 18}).catch(err=>{ 19 console.error(err); 20});
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...
.sql
files.
importer.import('path/to/dump1.sql', 'path/to/dum2.sql')
.sql
files.
importer.import('path/to/mysqldumps/')
importer.import(['path/to/dump.sql', 'path/to/dumps/'])
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.
Contributions are more than welcome! Please check out the Contributing Guidelines for this project.
No vulnerabilities found.