4.0.0 • Published 9 months ago

@runnerty/executor-sqlserver v4.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

NPM version Downloads Dependency Status

Microsoft SQL Server executor for Runnerty:

Installation:

Through NPM

npm i @runnerty/executor-sqlserver

You can also add modules to your project with runnerty

npx runnerty add @runnerty/executor-sqlserver

This command installs the module in your project, adds example configuration in your config.json and creates an example plan of use.

If you have installed runnerty globally you can include the module with this command:

runnerty add @runnerty/executor-sqlserver

Configuration:

Add in config.json:

{
  "id": "sqlserver_default",
  "type": "@runnerty-executor-sqlserver",
  "user": "sa",
  "password": "yourStrong(!)Password",
  "database": "master",
  "server": "localhost",
  "port": 1433
}
{
  "id": "sqlserver_default",
  "type": "@runnerty-executor-sqlserver",
  "user": "sa",
  "password": "yourStrong(!)Password",
  "database": "master",
  "server": "localhost",
  "port": 1433,
  "options": {
    "useUTC": true
  }
}

Configuration params:

ParameterDescription
userThe sqlserver user to authenticate as.
passwordThe password of that sqlserver user.
databaseName of the database to use for this connection. (Optional)
serverThe hostname of the database you are connecting to.
portThe port number to connect to. (Default: 3306)
domainOnce you set domain, driver will connect to SQL Server using domain login.
connectionTimeoutConnection timeout in ms (default: 15000).
requestTimeoutRequest timeout in ms (default: 15000).
pool.maxThe maximum number of connections there can be in the pool (default: 10).
pool.minThe minimum of connections there can be in the pool (default: 0).
pool.idleTimeoutMillisThe Number of milliseconds before closing an unused connection default: 30000).
ssh.hostHostname or IP address of the ssh server.
ssh.portPort number of the ssh server.
ssh.usernameUsername for authentication on the ssh server.
ssh.passwordPassword for password-based user authentication on the ssh server.
ssh.privateKeyBuffer or string that contains a private key for either key-based or hostbased user authentication (OpenSSH format).
ssh.passphraseFor an encrypted private key, this is the passphrase used to decrypt it.
ssh.srcHostHostname or IP address of the source server for outbound forwarding.
ssh.srcPortPort number of the source server for outbound forwarding.
optionsget more information about the options in the module documentation node-mssql

Plan sample:

Add in plan.json:

{
  "id": "sqlserver_default",
  "command_file": "/etc/runnerty/sql/test.sql"
}
{
  "id": "sqlserver_default",
  "command": "SELECT NOW()"
}

Generation of files:

The saved can be indicated in the file of the results obtained from a query in csv, xlsx and json format. These files will be generated with streams. You only have to indicate the corresponding property in the parameters:

XLSX

XLSX Format

ParameterDescription
xlsxFileExportPath of xlsx file export.
xlsxAuthorNameAuthor file name. (Optional)
xlsxSheetNameName of the sheet. (Optional)

Sample:

{
  "id": "sqlserver_default",
  "command": "SELECT * FROM USERS",
  "xlsxFileExport": "./my_output.xlsx",
  "xlsxAuthorName": "Runnerty",
  "xlsxSheetName": "MySheetSample"
}

CSV

CSV Format

ParameterDescription
csvFileExportPath of csv file export.
csvOptions/headersType: boolean/string[]. The headers will be auto detected from the first row or you can to provide headers array: 'h1name','h2name',....
csvOptions/delimiterAlternate delimiter. (Default: ',')
csvOptions/quoteAlternate quote. (Default: '"')
csvOptions/alwaysWriteHeadersSet to true if you always want headers written, even if no rows are written. (Default: false)
csvOptions/rowDelimiterSpecify an alternate row delimiter (i.e \r\n). (Default: '\n')
csvOptions/quoteHeadersIf true then all headers will be quoted. (Default: quoteColumns value)
csvOptions/quoteColumnsIf true then columns and headers will be quoted (unless quoteHeaders is specified). (Default: false). More info here.
csvOptions/escapeAlternate escaping value. (Default: '"')
csvOptions/includeEndRowDelimiterSet to true to include a row delimiter at the end of the csv. (Default: false)
csvOptions/writeBOMSet to true if you want the first character written to the stream to be a utf-8 BOM character. (Default: false)

Sample:

{
  "id": "sqlserver_default",
  "command": "SELECT * FROM USERS",
  "csvFileExport": "@GV(WORK_DIR)/users.csv",
  "csvOptions": {
    "delimiter": ";",
    "quote": "\""
  }
}

JSON

JSON Format

Sample:

{
  "id": "sqlserver_sample",
  "command": "SELECT * FROM USERS",
  "fileExport": "@GV(WORK_DIR)/users.json"
}

Loading files:

For file upload you must indicate the path of the csv file to be loaded in the localInFile parameter and the name of the table to load the data into in the tableName parameter. For example:

{
  "id": "sqlserver_default",
  "localInFile": "/sample.csv"
  "tableName": "dbo.TABLE_NAME"
}

Output (Process values):

Standard

  • PROCESS_EXEC_MSG_OUTPUT: sqlserver output message.
  • PROCESS_EXEC_ERR_OUTPUT: Error output message.

Query output

  • PROCESS_EXEC_DATA_OUTPUT: sqlserver query output data.
  • PROCESS_EXEC_DB_COUNTROWS: sqlserver query count rows.
  • PROCESS_EXEC_DB_FIRSTROW: sqlserver query first row data.
  • PROCESS_EXEC_DB_FIRSTROW_[FILED_NAME]: sqlserver first row field data.

If the process executes more than one query, it will be able to access its first row indicating its number in order, starting at zero. The first query corresponds to PROCESS_EXEC_DB_FIRSTROW, the next to PROCESS_EXEC_DB_FIRSTROW_1 and so on. The same is true for the rest of the values.

Operation output

  • PROCESS_EXEC_DB_AFFECTEDROWS: sqlserver affected rows count.

If the process executes more than one operation, it will be able to access its first row indicating its number in order, starting at zero. The first operation corresponds to PROCESS_EXEC_DB_AFFECTEDROWS, the next to PROCESS_EXEC_DB_AFFECTEDROWS_1 and so on.