mariadb-corporation / mariadb-connector-nodejs

MariaDB Connector/Node.js is used to connect applications developed on Node.js to MariaDB and MySQL databases. MariaDB Connector/Node.js is LGPL licensed.
GNU Lesser General Public License v2.1
363 stars 93 forks source link

executing sql files #242

Closed janro1 closed 1 year ago

janro1 commented 1 year ago

It would be good if the client could read sql files to restore backups for example, because in some environments it is difficult to install binaries. This is for example the case in AWS lambda.

Or maybe there is already a way that I missed in the documentation?

rusher commented 1 year ago

this has been implemented in 3.2.0 release . See importFile method : without connection

try {
    await mariadb.importFile({ host: 'localhost', user: 'root', file: '/tmp/tools/data-dump.sql'});
} catch (e) {
    // ...
}

with an existing connection

try {
    await conn.importFile({
        file: '/tmp/someFile.sql', 
        database: 'myDb'
    });
} catch (e) {
  // ...  
}

or from a pool:

try {
    await pool.importFile({
        file: '/tmp/someFile.sql', 
        database: 'myDb'
    });
} catch (e) {
  // ...  
}