QuestDB Node.js Client - v4.0.2
    Preparing search index...

    Class Sender

    The QuestDB client's API provides methods to connect to the database, ingest data, and close the connection.
    The client supports multiple transport protocols.

    Transport Options:

    • HTTP: Uses standard HTTP requests for data ingestion. Provides immediate feedback via HTTP response codes. Recommended for most use cases due to superior error handling and debugging capabilities. Uses Undici library by default for high performance.
    • HTTPS: Secure HTTP transport with TLS encryption. Same benefits as HTTP but with encrypted communication. Supports certificate validation and custom CA certificates.
    • TCP: Direct TCP connection, provides persistent connections. Uses JWK token-based authentication.
    • TCPS: Secure TCP transport with TLS encryption.

    The client supports authentication.
    Authentication details can be passed to the Sender in its configuration options.
    The client supports Basic username/password and Bearer token authentication methods when used with HTTP protocol, and JWK token authentication when ingesting data via TCP.
    Please, note that authentication is enabled by default in QuestDB Enterprise only.
    Details on how to configure authentication in the open source version of QuestDB: https://questdb.io/docs/reference/api/ilp/authenticate

    The client also supports TLS encryption for both, HTTP and TCP transports to provide a secure connection.
    Please, note that the open source version of QuestDB does not support TLS, and requires an external reverse-proxy, such as Nginx to enable encryption.

    The client supports multiple protocol versions for data serialization. Protocol version 1 uses text-based serialization, while version 2 uses binary encoding for doubles and supports array columns for improved performance. The client can automatically negotiate the protocol version with the server when using HTTP/HTTPS by setting the protocol_version to 'auto' (default behavior).

    The client uses a buffer to store data. It automatically flushes the buffer by sending its content to the server. Auto flushing can be disabled via configuration options to gain control over transactions. Initial and maximum buffer sizes can also be set.

    It is recommended that the Sender is created by using one of the static factory methods, Sender.fromConfig(configString, extraOptions) or Sender.fromEnv(extraOptions). If the Sender is created via its constructor, at least the SenderOptions configuration object should be initialized from a configuration string to make sure that the parameters are validated.
    Detailed description of the Sender's configuration options can be found in the SenderOptions documentation.

    Transport Configuration Examples:

    • HTTP: Sender.fromConfig("http::addr=localhost:9000")
    • HTTPS with authentication: Sender.fromConfig("https::addr=localhost:9000;username=admin;password=secret")
    • TCP: Sender.fromConfig("tcp::addr=localhost:9009")
    • TCPS with authentication: Sender.fromConfig("tcps::addr=localhost:9009;username=user;token=private_key")

    HTTP Transport Implementation:
    By default, HTTP/HTTPS transport uses the high-performance Undici library for connection management and request handling. For compatibility or specific requirements, you can enable the standard HTTP transport using Node.js built-in modules by setting stdlib_http=on in the configuration string. The standard HTTP transport provides the same functionality but uses Node.js http/https modules instead of Undici.

    Extra options can be provided to the Sender in the extraOptions configuration object.
    A custom logging function and a custom HTTP(S) agent can be passed to the Sender in this object.
    The logger implementation provides the option to direct log messages to the same place where the host application's log is saved. The default logger writes to the console.
    The custom HTTP(S) agent option becomes handy if there is a need to modify the default options set for the HTTP(S) connections. A popular setting would be disabling persistent connections, in this case an agent can be passed to the Sender with keepAlive set to false.
    For example: Sender.fromConfig(`http::addr=host:port`, { agent: new undici.Agent({ connect: { keepAlive: false } })})
    If no custom agent is configured, the Sender will use its own agent which overrides some default values of undici.Agent. The Sender's own agent uses persistent connections with 1 minute idle timeout, pipelines requests default to 1.

    Index

    Constructors

    • Creates an instance of Sender.

      Parameters

      • options: SenderOptions

        Sender configuration object.
        See SenderOptions documentation for detailed description of configuration options.

      Returns Sender

    Methods

    • Creates a Sender object by parsing the provided configuration string.

      Parameters

      • configurationString: string

        Configuration string.

      • OptionalextraOptions: ExtraOptions

        Optional extra configuration.

        • 'log' is a logging function used by the Sender. Prototype: (level: 'error'|'warn'|'info'|'debug', message: string) => void.
        • 'agent' is a custom http/https agent used by the Sender when http/https transport is used. Depends on which transport implementation and protocol used, one of the followings expected: undici.Agent, http.Agent or https.Agent.

      Returns Promise<Sender>

      A Sender object initialized from the provided configuration string.

    • Creates a Sender object by parsing the configuration string set in the QDB_CLIENT_CONF environment variable.

      Parameters

      • OptionalextraOptions: ExtraOptions

        Optional extra configuration.

        • 'log' is a logging function used by the Sender. Prototype: (level: 'error'|'warn'|'info'|'debug', message: string) => void.
        • 'agent' is a custom http/https agent used by the Sender when http/https transport is used. Depends on which transport implementation and protocol used, one of the followings expected: undici.Agent, http.Agent or https.Agent.

      Returns Promise<Sender>

      A Sender object initialized from the QDB_CLIENT_CONF environment variable.

    • Resets the sender's buffer, data sitting in the buffer will be lost.
      In other words it clears the buffer, and sets the writing position to the beginning of the buffer.

      Returns Sender

      Returns with a reference to this sender.

    • Creates a TCP connection to the database.

      Returns Promise<boolean>

      Resolves to true if the client is connected.

    • Sends the content of the sender's buffer to the database and compacts the buffer. If the last row is not finished it stays in the sender's buffer.

      Returns Promise<boolean>

      Resolves to true when there was data in the buffer to send, and it was sent successfully.

    • Closes the connection to the database.
      Data sitting in the Sender's buffer will be lost unless flush() is called before close().

      Returns Promise<void>

    • Writes the table name into the buffer of the sender of the sender.

      Parameters

      • table: string

        Table name.

      Returns Sender

      Returns with a reference to this sender.

    • Writes a symbol name and value into the buffer of the sender.
      Use it to insert into SYMBOL columns.

      Parameters

      • name: string

        Symbol name.

      • value: unknown

        Symbol value, toString() is called to extract the actual symbol value from the parameter.

      Returns Sender

      Returns with a reference to this sender.

    • Writes a string column with its value into the buffer of the sender.
      Use it to insert into VARCHAR and STRING columns.

      Parameters

      • name: string

        Column name.

      • value: string

        Column value, accepts only string values.

      Returns Sender

      Returns with a reference to this sender.

    • Writes a boolean column with its value into the buffer of the sender.
      Use it to insert into BOOLEAN columns.

      Parameters

      • name: string

        Column name.

      • value: boolean

        Column value, accepts only boolean values.

      Returns Sender

      Returns with a reference to this sender.

    • Writes a 64-bit floating point value into the buffer of the sender.
      Use it to insert into DOUBLE or FLOAT database columns.

      Parameters

      • name: string

        Column name.

      • value: number

        Column value, accepts only number values.

      Returns Sender

      Returns with a reference to this sender.

    • Writes an array column with its values into the buffer of the sender.

      Parameters

      • name: string

        Column name

      • value: unknown[]

        Array values to write (currently supports double arrays)

      Returns Sender

      Returns with a reference to this sender.

      Error if arrays are not supported by the buffer implementation, or array validation fails:

      • value is not an array
      • or the shape of the array is irregular: the length of sub-arrays are different
      • or the array is not homogeneous: its elements are not all the same type
    • Writes a 64-bit signed integer into the buffer of the sender.
      Use it to insert into LONG, INT, SHORT and BYTE columns.

      Parameters

      • name: string

        Column name.

      • value: number

        Column value, accepts only number values.

      Returns Sender

      Returns with a reference to this sender.

      Error if the value is not an integer

    • Writes a timestamp column with its value into the buffer of the sender.
      Use it to insert into TIMESTAMP columns.

      Parameters

      • name: string

        Column name.

      • value: number | bigint

        Epoch timestamp, accepts numbers or BigInts.

      • Optionalunit: TimestampUnit = "us"

        Timestamp unit. Supported values: 'ns' - nanoseconds, 'us' - microseconds, 'ms' - milliseconds. Defaults to 'us'.

      Returns Sender

      Returns with a reference to this sender.

    • Closes the row after writing the designated timestamp into the buffer of the sender.

      Parameters

      • timestamp: number | bigint

        Designated epoch timestamp, accepts numbers or BigInts.

      • Optionalunit: TimestampUnit = "us"

        Timestamp unit. Supported values: 'ns' - nanoseconds, 'us' - microseconds, 'ms' - milliseconds. Defaults to 'us'.

      Returns Promise<void>

    • Closes the row without writing designated timestamp into the buffer of the sender.
      Designated timestamp will be populated by the server on this record.

      Returns Promise<void>