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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

executing sql files

janro1 opened this issue · comments

commented

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?

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) {
  // ...  
}