exec-mssql
v1.0.1
Published
Execute your *.sql files which contain multiple sql statements.
Downloads
3
Readme
exec-mssql
Execute your ms.sql files which contain multiple sql statements.GO
deliminators in files are replaced at runtime by ;
Usage
As a CLI tool
Make sure you have
exec-mssql
installed globallynpm install -g exec-mssql
Configure your db access for the first time. Usage:
exec-mssql [-e] -c "server" "database" "user" "password"
.exec_mssql -c "localhost" "database" "root" "root"
Execute a bunch of sql statements
exec_mssql "use db_cam; delete from admin;"
Execute a
.sql
fileexec_mssql -f ./db.sql
As a Node dependency
Make sure you have
exec-mssql
installed locallynpm install exec-mssql
Require and use
var exec_mssql = require('exec-mssql'), dbConfig = { host: 'localhost', database: 'myDatabase', user: 'root', password: 'root', options: { encrypt: false } }, sql = 'use db_cam;', sqlFile = __dirname + '/db.sql'; exec_mssql.config( dbConfig ).then( () => { exec_mssql.exec( sql ).then( results => { exec_mssql.execFile( sqlFile ).then( data => { if (data.err) throw data.err; console.log( results, data.results ); exec_mssql.end(); process.exit(0); }).catch( error => { console.error( 'error executing SQL file', error ); exec_mssql.end(); process.exit(0); }) }).catch( error => { console.error( 'error executing SQL block', error ); exec_mssql.end(); process.exit(0); }) })