Tedious
    Preparing search index...

    Class Request

    const { Request } = require('tedious');
    const request = new Request("select 42, 'hello world'", (err, rowCount) => {
    // Request completion callback...
    });
    connection.execSql(request);

    Hierarchy

    • EventEmitter
      • Request
    Index

    Constructors

    • Parameters

      • sqlTextOrProcedure: string | undefined

        The SQL statement to be executed

      • callback: CompletionCallback

        The callback to execute once the request has been fully completed.

      • Optionaloptions: RequestOptions

      Returns Request

    Properties

    cryptoMetadataLoaded: boolean
    shouldHonorAE?: boolean
    statementColumnEncryptionSetting: SQLServerStatementColumnEncryptionSetting

    Methods

    • The Symbol.for('nodejs.rejection') method is called in case a promise rejection happens when emitting an event and captureRejections is enabled on the emitter. It is possible to use events.captureRejectionSymbol in place of Symbol.for('nodejs.rejection').

      import { EventEmitter, captureRejectionSymbol } from 'node:events';

      class MyClass extends EventEmitter {
      constructor() {
      super({ captureRejections: true });
      }

      [captureRejectionSymbol](err, event, ...args) {
      console.log('rejection happened for', event, 'with', err, ...args);
      this.destroy(err);
      }

      destroy(err) {
      // Tear the resource down here.
      }
      }

      Parameters

      • error: Error
      • event: string | symbol
      • ...args: any[]

      Returns void

      v13.4.0, v12.16.0

    • Alias for emitter.on(eventName, listener).

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName: string | symbol
      • listener: (...args: any[]) => void

      Returns this

      v0.1.26

    • Parameters

      • name: string

        The parameter name. This should correspond to a parameter in the SQL, or a parameter that a called procedure expects.

      • type: DataType

        One of the supported data types.

      • Optionalvalue: unknown

        The value that the parameter is to be given. The Javascript type of the argument should match that documented for data types

      • Optionaloptions: Readonly<ParameterOptions> | null

        Additional type options. Optional.

      Returns void

    • Parameters

      • name: string

        The parameter name. This should correspond to a parameter in the SQL, or a parameter that a called procedure expects. The name should not start with @.

      • type: DataType

        One of the supported data types.

      • Optionalvalue: unknown

        The value that the parameter is to be given. The Javascript type of the argument should match that documented for data types.

        A varchar(max), nvarchar(max) or varbinary(max) value, or the rows of a table-valued parameter, can also be given as an async iterable (e.g. a Readable) of chunks, or of rows. The source is read while the request is being sent, so it does not have to fit in memory, and a request that carries one can be executed only once.

        String chunks may split UTF-16 surrogate pairs; the pairs are preserved across chunk boundaries, including empty chunks. An unpaired surrogate is handled by the type's encoding as it is for an in-memory value. A Buffer chunk of 8 KB or more is sent by reference, as socket.write would send it, so a source must not reuse or modify a buffer it has yielded until the request has completed.

      • Optionaloptions: Readonly<ParameterOptions> | null

        Additional type options. Optional.

      Returns void

    • Cancels a request while waiting for a server response.

      Returns void

    • Returns an array listing the events for which the emitter has registered listeners.

      import { EventEmitter } from 'node:events';

      const myEE = new EventEmitter();
      myEE.on('foo', () => {});
      myEE.on('bar', () => {});

      const sym = Symbol('symbol');
      myEE.on(sym, () => {});

      console.log(myEE.eventNames());
      // Prints: [ 'foo', 'bar', Symbol(symbol) ]

      Returns (string | symbol)[]

      v6.0.0

    • Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to events.defaultMaxListeners.

      Returns number

      v1.0.0

    • Returns the number of listeners listening for the event named eventName. If listener is provided, it will return how many times the listener is found in the list of the listeners of the event.

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName: string | symbol

        The name of the event being listened for

      • Optionallistener: (...args: any[]) => void

        The event handler function

      Returns number

      v3.2.0

    • Returns a copy of the array of listeners for the event named eventName.

      server.on('connection', (stream) => {
      console.log('someone connected!');
      });
      console.log(util.inspect(server.listeners('connection')));
      // Prints: [ [Function] ]

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName: string | symbol

      Returns ((...args: any[]) => void)[]

      v0.1.26

    • Alias for emitter.removeListener().

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName: string | symbol
      • listener: (...args: any[]) => void

      Returns this

      v10.0.0

    • This event, describing result set columns, will be emitted before row events are emitted. This event may be emitted multiple times when more than one recordset is produced by the statement.

      An array like object, where the columns can be accessed either by index or name. Columns with a name that is an integer are not accessible by name, as it would be interpreted as an array index.

      Parameters

      • event: "columnMetadata"
      • listener: (columns: ColumnMetadata[] | { [key: string]: ColumnMetadata }) => void

      Returns this

    • The request has been prepared and can be used in subsequent calls to execute and unprepare.

      Parameters

      • event: "prepared"
      • listener: () => void

      Returns this

    • The request encountered an error and has not been prepared.

      Parameters

      • event: "error"
      • listener: (err: Error) => void

      Returns this

    • A row resulting from execution of the SQL statement.

      Parameters

      • event: "row"
      • listener: (columns: any) => void
          • (columns: any): void
          • An array or object (depends on ConnectionOptions.useColumnNames), where the columns can be accessed by index/name. Each column has two properties, metadata and value:

            • metadata

              The same data that is exposed in the columnMetadata event.

            • value

              The column's value. It will be null for a NULL. If there are multiple columns with the same name, then this will be an array of the values.

            Parameters

            • columns: any

            Returns void

      Returns this

    • All rows from a result set have been provided (through row events).

      This token is used to indicate the completion of a SQL statement. As multiple SQL statements can be sent to the server in a single SQL batch, multiple done can be generated. An done event is emitted for each SQL statement in the SQL batch except variable declarations. For execution of SQL statements within stored procedures, doneProc and doneInProc events are used in place of done.

      If you are using Connection.execSql then SQL server may treat the multiple calls with the same query as a stored procedure. When this occurs, the doneProc and doneInProc events may be emitted instead. You must handle both events to ensure complete coverage.

      Parameters

      • event: "done"
      • listener: (rowCount: number | undefined, more: boolean, rst?: any[]) => void
          • (rowCount: number | undefined, more: boolean, rst?: any[]): void
          • Parameters

            • rowCount: number | undefined

              The number of result rows. May be undefined if not available.

            • more: boolean

              If there are more results to come (probably because multiple statements are being executed), then true.

            • Optionalrst: any[]

              Rows as a result of executing the SQL statement. Will only be available if Connection's ConnectionOptions.rowCollectionOnDone is true.

            Returns void

      Returns this

    • request.on('doneInProc', function (rowCount, more, rows) { });

      Indicates the completion status of a SQL statement within a stored procedure. All rows from a statement in a stored procedure have been provided (through row events).

      This event may also occur when executing multiple calls with the same query using Connection.execSql.

      Parameters

      • event: "doneInProc"
      • listener: (rowCount: number | undefined, more: boolean, rst?: any[]) => void
          • (rowCount: number | undefined, more: boolean, rst?: any[]): void
          • Parameters

            • rowCount: number | undefined

              The number of result rows. May be undefined if not available.

            • more: boolean

              If there are more results to come (probably because multiple statements are being executed), then true.

            • Optionalrst: any[]

              Rows as a result of executing the SQL statement. Will only be available if Connection's ConnectionOptions.rowCollectionOnDone is true.

            Returns void

      Returns this

    • Indicates the completion status of a stored procedure. This is also generated for stored procedures executed through SQL statements.
      This event may also occur when executing multiple calls with the same query using Connection.execSql.

      Parameters

      • event: "doneProc"
      • listener: (
            rowCount: number | undefined,
            more: boolean,
            procReturnStatusValue: number,
            rst?: any[],
        ) => void
          • (
                rowCount: number | undefined,
                more: boolean,
                procReturnStatusValue: number,
                rst?: any[],
            ): void
          • Parameters

            • rowCount: number | undefined

              The number of result rows. May be undefined if not available.

            • more: boolean

              If there are more results to come (probably because multiple statements are being executed), then true.

            • procReturnStatusValue: number
            • Optionalrst: any[]

              Rows as a result of executing the SQL statement. Will only be available if Connection's ConnectionOptions.rowCollectionOnDone is true.

            Returns void

      Returns this

    • A value for an output parameter (that was added to the request with addOutputParameter). See also Using Parameters.

      Parameters

      • event: "returnValue"
      • listener: (parameterName: string, value: unknown, metadata: Metadata) => void
          • (parameterName: string, value: unknown, metadata: Metadata): void
          • Parameters

            • parameterName: string

              The parameter name. (Does not start with '@'.)

            • value: unknown

              The parameter's output value.

            • metadata: Metadata

              The same data that is exposed in the columnMetadata event.

            Returns void

      Returns this

    • This event gives the columns by which data is ordered, if ORDER BY clause is executed in SQL Server.

      Parameters

      • event: "order"
      • listener: (orderColumns: number[]) => void
          • (orderColumns: number[]): void
          • Parameters

            • orderColumns: number[]

              An array of column numbers in the result set by which data is ordered.

            Returns void

      Returns this

    • This event gives the names of the base tables of the result set, if the query was executed in browse mode (e.g. with a FOR BROWSE clause or SET NO_BROWSETABLE ON).

      Parameters

      • event: "tabName"
      • listener: (tableNames: string[][]) => void
          • (tableNames: string[][]): void
          • Parameters

            • tableNames: string[][]

              The names of the base tables referenced in the query, in the order the colInfo event's tableNum values refer to them. Each name is given as its individual parts (e.g. ['dbo', 'employees']).

            Returns void

      Returns this

    • This event describes how the columns of the result set map back to the base tables given in the tabName event, if the query was executed in browse mode (e.g. with a FOR BROWSE clause or SET NO_BROWSETABLE ON).

      Parameters

      • event: "colInfo"
      • listener: (columns: ColumnInfo[]) => void
          • (columns: ColumnInfo[]): void
          • Parameters

            • columns: ColumnInfo[]

              One entry for each column in the result set, describing the base table the column was derived from.

            Returns void

      Returns this

    • This event, describing result set columns, will be emitted before row events are emitted. This event may be emitted multiple times when more than one recordset is produced by the statement.

      An array like object, where the columns can be accessed either by index or name. Columns with a name that is an integer are not accessible by name, as it would be interpreted as an array index.

      Parameters

      • event: "requestCompleted"
      • listener: () => void

      Returns this

    • This event, describing result set columns, will be emitted before row events are emitted. This event may be emitted multiple times when more than one recordset is produced by the statement.

      An array like object, where the columns can be accessed either by index or name. Columns with a name that is an integer are not accessible by name, as it would be interpreted as an array index.

      Parameters

      • event: "cancel"
      • listener: () => void

      Returns this

    • This event, describing result set columns, will be emitted before row events are emitted. This event may be emitted multiple times when more than one recordset is produced by the statement.

      An array like object, where the columns can be accessed either by index or name. Columns with a name that is an integer are not accessible by name, as it would be interpreted as an array index.

      Parameters

      • event: "pause"
      • listener: () => void

      Returns this

    • This event, describing result set columns, will be emitted before row events are emitted. This event may be emitted multiple times when more than one recordset is produced by the statement.

      An array like object, where the columns can be accessed either by index or name. Columns with a name that is an integer are not accessible by name, as it would be interpreted as an array index.

      Parameters

      • event: "resume"
      • listener: () => void

      Returns this

    • Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.

      server.once('connection', (stream) => {
      console.log('Ah, we have our first user!');
      });

      Returns a reference to the EventEmitter, so that calls can be chained.

      By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

      import { EventEmitter } from 'node:events';
      const myEE = new EventEmitter();
      myEE.once('foo', () => console.log('a'));
      myEE.prependOnceListener('foo', () => console.log('b'));
      myEE.emit('foo');
      // Prints:
      // b
      // a

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName: string | symbol

        The name of the event.

      • listener: (...args: any[]) => void

        The callback function

      Returns this

      v0.3.0

    • Temporarily suspends the flow of data from the database. No more row events will be emitted until resume is called. If this request is already in a paused state, calling pause has no effect.

      Returns void

    • Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

      server.prependListener('connection', (stream) => {
      console.log('someone connected!');
      });

      Returns a reference to the EventEmitter, so that calls can be chained.

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName: string | symbol

        The name of the event.

      • listener: (...args: any[]) => void

        The callback function

      Returns this

      v6.0.0

    • Adds a one-time listener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked.

      server.prependOnceListener('connection', (stream) => {
      console.log('Ah, we have our first user!');
      });

      Returns a reference to the EventEmitter, so that calls can be chained.

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName: string | symbol

        The name of the event.

      • listener: (...args: any[]) => void

        The callback function

      Returns this

      v6.0.0

    • Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).

      import { EventEmitter } from 'node:events';
      const emitter = new EventEmitter();
      emitter.once('log', () => console.log('log once'));

      // Returns a new Array with a function `onceWrapper` which has a property
      // `listener` which contains the original listener bound above
      const listeners = emitter.rawListeners('log');
      const logFnWrapper = listeners[0];

      // Logs "log once" to the console and does not unbind the `once` event
      logFnWrapper.listener();

      // Logs "log once" to the console and removes the listener
      logFnWrapper();

      emitter.on('log', () => console.log('log persistently'));
      // Will return a new Array with a single function bound by `.on()` above
      const newListeners = emitter.rawListeners('log');

      // Logs "log persistently" twice
      newListeners[0]();
      emitter.emit('log');

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName: string | symbol

      Returns ((...args: any[]) => void)[]

      v9.4.0

    • Removes all listeners, or those of the specified eventName.

      It is bad practice to remove listeners added elsewhere in the code, particularly when the EventEmitter instance was created by some other component or module (e.g. sockets or file streams).

      Returns a reference to the EventEmitter, so that calls can be chained.

      Type Parameters

      • E extends string | symbol

      Parameters

      • OptionaleventName: string | symbol

      Returns this

      v0.1.26

    • Removes the specified listener from the listener array for the event named eventName.

      const callback = (stream) => {
      console.log('someone connected!');
      };
      server.on('connection', callback);
      // ...
      server.removeListener('connection', callback);

      removeListener() will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified eventName, then removeListener() must be called multiple times to remove each instance.

      Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that any removeListener() or removeAllListeners() calls after emitting and before the last listener finishes execution will not remove them from emit() in progress. Subsequent events behave as expected.

      import { EventEmitter } from 'node:events';
      class MyEmitter extends EventEmitter {}
      const myEmitter = new MyEmitter();

      const callbackA = () => {
      console.log('A');
      myEmitter.removeListener('event', callbackB);
      };

      const callbackB = () => {
      console.log('B');
      };

      myEmitter.on('event', callbackA);

      myEmitter.on('event', callbackB);

      // callbackA removes listener callbackB but it will still be called.
      // Internal listener array at time of emit [callbackA, callbackB]
      myEmitter.emit('event');
      // Prints:
      // A
      // B

      // callbackB is now removed.
      // Internal listener array [callbackA]
      myEmitter.emit('event');
      // Prints:
      // A

      Because listeners are managed using an internal array, calling this will change the position indexes of any listener registered after the listener being removed. This will not impact the order in which listeners are called, but it means that any copies of the listener array as returned by the emitter.listeners() method will need to be recreated.

      When a single function has been added as a handler multiple times for a single event (as in the example below), removeListener() will remove the most recently added instance. In the example the once('ping') listener is removed:

      import { EventEmitter } from 'node:events';
      const ee = new EventEmitter();

      function pong() {
      console.log('pong');
      }

      ee.on('ping', pong);
      ee.once('ping', pong);
      ee.removeListener('ping', pong);

      ee.emit('ping');
      ee.emit('ping');

      Returns a reference to the EventEmitter, so that calls can be chained.

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName: string | symbol
      • listener: (...args: any[]) => void

      Returns this

      v0.1.26

    • Resumes the flow of data from the database. If this request is not in a paused state, calling resume has no effect.

      Returns void

    • By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set to Infinity (or 0) to indicate an unlimited number of listeners.

      Returns a reference to the EventEmitter, so that calls can be chained.

      Parameters

      • n: number

      Returns this

      v0.3.5

    • Sets a timeout for this request.

      Parameters

      • Optionaltimeout: number

        The number of milliseconds before the request is considered failed, or 0 for no timeout. When no timeout is set for the request, the ConnectionOptions.requestTimeout of the Connection is used.

      Returns void