Exciting news!Announcing our $4.6M Series Seed. Learn more
Socket
LoveBlogFAQ
Install
Log in

tedious-async

Package Overview
Dependencies
1
Maintainers
1
Versions
13
Issues
File Explorer

Advanced tools

tedious-async

https://github.com/SyedNaqiRizvi/tedious-async.git

    1.0.9latest

Version published
Maintainers
1
Yearly downloads
3,676
increased by81.62%

Weekly downloads

Changelog

Source

1.0.9 (2019-06-05)

Readme

Source

Build Status Maintainability Test Coverage

Tedious Async

An ES6 Typescript async/await wrapper around the tedious library (http://tediousjs.github.io/tedious/index.html).

Details

This package includes several extension functions that can be used with async/await as well as all original tedious functions. It also includes built-in utilities for SQL operations such as having an option to return SQL data as JSON with SQL types converted to JavaScript types..

Additional Details:

  • Last updated: June 4, 2019
  • Dependencies: tedious

Installation

npm install --save tedious-async

Usage

  1. Creating a new Instance
  2. Connection Events

Creating a new instance

Configuration Model

FieldValue
serverHostname to connect to.
authentication.typeType of the authentication method, valid types are default, ntlm, azure-active-directory-password
authentication.options.userNameUser name to use for authentication.
authentication.options.passwordPassword to use for authentication.
authentication.options.domainOnce you set domain for ntlm authentication type, driver will connect to SQL Server using domain login.
options.portPort to connect to (default: 1433). Mutually exclusive with options.instanceName.
options.instanceNameThe instance name to connect to. The SQL Server Browser service must be running on the database server, and UDP port 1434 on the database server must be reachable. (no default), Mutually exclusive with options.port.
options.databaseDatabase to connect to (default: dependent on server configuration).
options.fallbackToDefaultDbBy default, if the database requested by options.database cannot be accessed, the connection will fail with an error. However, if options.fallbackToDefaultDb is set to true, then the user's default database will be used instead (Default: false).
options.enableAnsiNullDefaultIf true, SET ANSI_NULL_DFLT_ON ON will be set in the initial sql. This means new columns will be nullable by default. See the T-SQL documentation for more details. (Default: true).
options.connectTimeoutThe number of milliseconds before the attempt to connect is considered failed (default: 15000).
options.requestTimeoutThe number of milliseconds before a request is considered failed, or 0 for no timeout (default: 15000).
options.cancelTimeoutThe number of milliseconds before the cancel (abort) of a request is considered failed (default: 5000).
options.packetSizeThe size of TDS packets (subject to negotiation with the server). Should be a power of 2. (default: 4096).
options.useUTCA boolean determining whether to pass time values in UTC or local time. (default: true).
options.abortTransactionOnErrorA boolean determining whether to rollback a transaction automatically if any error is encountered during the given transaction's execution. This sets the value for SET XACT_ABORT during the initial SQL phase of a connection (documentation).
options.localAddressA string indicating which network interface (ip address) to use when connecting to SQL Server.
options.useColumnNamesA boolean determining whether to return rows as arrays or key-value collections. (default: false).
options.camelCaseColumnsA boolean, controlling whether the column names returned will have the first letter converted to lower case (true) or not. This value is ignored if you provide a columnNameReplacer. (default: false).
options.columnNameReplacerA function with parameters (columnName, index, columnMetaData) and returning a string. If provided, this will be called once per column per result-set. The returned value will be used instead of the SQL-provided column name on row and meta data objects. This allows you to dynamically convert between naming conventions. (default: null).
options.debug.packetA boolean, controlling whether debug events will be emitted with text describing packet details (default: false).
options.debug.dataA boolean, controlling whether debug events will be emitted with text describing packet data details (default: false).
options.debug.payloadA boolean, controlling whether debug events will be emitted with text describing packet payload details (default: false).
options.debug.tokenA boolean, controlling whether debug events will be emitted with text describing token stream tokens (default: false).
options.isolationLevelThe default isolation level that transactions will be run with. The isolation levels are available from require('tedious').ISOLATION_LEVEL [READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE, SNAPSHOT] (default: READ_COMMITED).
options.connectionIsolationLevelThe default isolation level that transactions will be run with. The isolation levels are available from require('tedious').ISOLATION_LEVEL [READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE, SNAPSHOT] (default: READ_COMMITED).
options.readOnlyIntentA boolean, determining whether the connection will request read only access from a SQL Server Availability Group. For more information, see here. (default: false).
options.encryptA boolean determining whether or not the connection will be encrypted. Set to true if you're on Windows Azure. (default: false).
options.cryptoCredentialsDetailsWhen encryption is used, an object may be supplied that will be used for the first argument when calling tls.createSecurePair (default: {}).
options.rowCollectionOnDoneA boolean, that when true will expose received rows in Requests' done* events. See done,doneInProc and doneProc. (default: false). Caution: If many row are received, enabling this option could result in excessive memory usage.
options.rowCollectionOnRequestCompletionA boolean, that when true will expose received rows in Requests' completion callback. See new Request. (default: false). Caution: If many row are received, enabling this option could result in excessive memory usage.
options.tdsVersionThe version of TDS to use. If server doesn't support specified version, negotiated version is used instead. The versions are available from require('tedious').TDS_VERSION. [7_1, 7_2, 7_3_A, 7_3_B,7_4 ]. (default: 7_4).
options.connectionRetryIntervalNumber of milliseconds before retrying to establish connection, in case of transient failure. (default: 500)
options.dateFormatA string representing position of month, day and year in temporal datatypes. (default: mdy)
options.enableAnsiNullA boolean, controls the way null values should be used during comparison operation. (default: true)
options.enableAnsiPaddingA boolean, controls if padding should be applied for values shorter than the size of defined column. (default: true)
options.enableAnsiWarningsIf true, SQL Server will follow ISO standard behavior during various error conditions. For details, see documentation. (default: true)
options.enableConcatNullYieldsNullA boolean, determines if concatenation with NULL should result in NULL or empty string value, more details in documentation. (default: true)
options.enableCursorCloseOnCommitA boolean, controls whether cursor should be closed, if the transaction opening it gets committed or rolled back. (default: false)
options.enableImplicitTransactionsA boolean, sets the connection to either implicit or autocommit transaction mode. (default: false)
options.enableNumericRoundabortIf false, error is not generated during loss of precession. (default: false)
options.enableQuotedIdentifierIf true, characters enclosed in single quotes are treated as literals and those enclosed double quotes are treated as identifiers. (default: true)
options.appNameApplication name used for identifying a specific application in profiling, logging or tracing tools of SQL Server. (default: Tedious)

Initialization

import Connection from 'tedious-async'; const config: ConnectionConfig = { // Tedious configurations }; const connection = new Connection(config);

Connection Events

onConnectAsync

Here is an example of how you can use the onConnectAsync function. This returns a promise, when successful resolves the connection, when error rejects with Error.

Origin tedious documentation for reference: http://tediousjs.github.io/tedious/api-connection.html#event_connect

try { const onConnectResult = await connection.onConnectAsync(); return onConnectResult; } catch (error) { throw error; }

onEndAsync

Here is an example of how you can use the onErrorAsync function. This returns a promise, when Error is returned it will resolve an Error, when nothing is returned the promise is rejected.

Origin implementation for reference: http://tediousjs.github.io/tedious/api-connection.html#event_end

try { const onErrorResult = await connection.onErrorAsync(); return onErrorResult; } catch (error) { throw error; }

onErrorAsync

Here is an example of how you can use the onErrorAsync function. This returns a promise, when Error is returned it will resolve an Error, when nothing is returned the promise is rejected.

Origin implementation for reference: http://tediousjs.github.io/tedious/api-connection.html#event_error

try { const onErrorResult = await connection.onErrorAsync(); return onErrorResult; } catch (error) { throw error; }

onDebugAsync

Here is an example of how you can use the onDebugAsync function. This returns a promise, when debug message is returned it will resolve the message text, when nothing is returned the promise is rejected.

Origin implementation for reference: http://tediousjs.github.io/tedious/api-connection.html#event_debug

try { const onDebugResult = await connection.onDebugAsync(); return onDebugResult; } catch (error) { throw error; }

onInfoMessageAsync

Here is an example of how you can use the onInfoMessageAsync function. This returns a promise, when info message is returned it will resolve the info message object, when nothing is returned the promise is rejected.

Origin implementation for reference: http://tediousjs.github.io/tedious/api-connection.html#event_infoMessage

Info Message Object Model

InfoMessage { number: number; // Error number state: string; // The error state, used as a modifier to the error number. class: number; // The class (severity) of the error. A class of less than 10 indicates an informational message. message: string; // The message text. procName: string; // The stored procedure name (if a stored procedure generated the message). lineNumber: number; // The line number in the SQL batch or stored procedure that caused the error. Line numbers begin at 1; therefore, if the line number is not applicable to the message, the value of LineNumber will be 0. }

Implementation

try { const onInfoMessageResult = await connection.onInfoMessageAsync(); return onInfoMessageResult; } catch (error) { throw error; }

onErrorMessageAsync

Here is an example of how you can use the onErrorMessageAsync function. This returns a promise, when error message is returned it will resolve the error message object, when nothing is returned the promise is rejected.

Origin implementation for reference: http://tediousjs.github.io/tedious/api-connection.html#event_errorMessage

Error Message Object Model

ErrorMessage { number: number; // Error number state: string; // The error state, used as a modifier to the error number. class: number; // The class (severity) of the error. A class of less than 10 indicates an informational message. message: string; // The message text. procName: string; // The stored procedure name (if a stored procedure generated the message). lineNumber: number; // The line number in the SQL batch or stored procedure that caused the error. Line numbers begin at 1; therefore, if the line number is not applicable to the message, the value of LineNumber will be 0. }

Implementation

try { const onErrorMessageResult = await connection.onErrorMessageAsync(); return onErrorMessageResult; } catch (error) { throw error; }

onDatabaseChangeAsync

Here is an example of how you can use the onDatabaseChangeAsync function. This returns a promise, when database is changed (may be as a result of a successful login, or a use statement) it will resolve the name of the new database, when nothing is returned the promise is rejected.

Origin implementation for reference: http://tediousjs.github.io/tedious/api-connection.html#event_databaseChange

try { const onDatabaseChangeResult = await connection.onDatabaseChangeAsync(); return onDatabaseChangeResult; } catch (error) { throw error; }

onLanguageChangeAsync

Here is an example of how you can use the onLanguageChangeAsync function. This returns a promise, when language is changed it will resolve with the new language string, when nothing is returned the promise is rejected.

Origin implementation for reference: http://tediousjs.github.io/tedious/api-connection.html#event_languageChange

try { const onLanguageChangeResult = await connection.onLanguageChangeAsync(); return onLanguageChangeResult; } catch (error) { throw error; }

onCharsetChangeAsync

Here is an example of how you can use the onCharsetChangeAsync function. This returns a promise, when charset is changed it will resolve with the new charset string, when nothing is returned the promise is rejected.

Origin implementation for reference: http://tediousjs.github.io/tedious/api-connection.html#event_charsetChange

try { const onCharsetChangeResult = await connection.onCharsetChangeAsync(); return onCharsetChangeResult; } catch (error) { throw error; }

Connection Operations

execSqlAsync

Here is an example of how you can use the execSqlAsync function. This returns a promise, when the sql query is successful it will return the result, when there is an error then the promise is rejected. There is an options object that you can pass the this function to transform the result of the operation such as having a list of json objects as the result.

Origin synchronous implementation: https://tediousjs.github.io/tedious/api-connection.html#function_execSql

Options

NameUsePossible Values
formattransforms the format of the returned result[json, default]
const options = { format: 'json' }; const getAllUsers = async() => { try { const users = await connection.execSqlAsync('select * from users;', options); return users; } catch (error) { throw(error) } };

Coming Soon

Keywords

Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc