Class: Sender

Sender(options)

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

The client supports authentication.
A JsonWebKey can be passed to the Sender in its constructor, the JsonWebKey will be used for authentication.
If no JsonWebKey specified the client will not attempt to authenticate itself with the server.
Details on how to configure QuestDB authentication: https://questdb.io/docs/reference/api/ilp/authenticate

The client also supports TLS encryption to provide a secure connection.
However, QuestDB does not support TLS yet and requires an external reverse-proxy, such as Nginx to enable encryption.

Constructor

new Sender(options)

Creates an instance of Sender.
Parameters:
Name Type Description
options object Configuration options.

Properties of the object:

  • bufferSize: number - Size of the buffer used by the sender to collect rows, provided in bytes.
    Optional, defaults to 8192 bytes
  • copyBuffer: boolean - If true a new buffer will be created for every flush() call and the data to be sent to the server will be copied into this new buffer.
    Setting the flag could result in performance degradation, use this flag only if calls to the client cannot be serialised.
    Optional, defaults to false
  • jwk: {x: string, y: string, kid: string, kty: string, d: string, crv: string} - JsonWebKey for authentication.
    If not provided, client is not authenticated and server might reject the connection depending on configuration.
  • log: (level: 'error'|'warn'|'info'|'debug', message: string) => void - logging function.
    If not provided, default logging is used which writes to the console with logging level 'info'.

Source:

Methods

at(timestamp)

Closing the row after writing the designated timestamp into the buffer of the sender.
Parameters:
Name Type Description
timestamp string A string represents the designated timestamp in nanoseconds.
Source:

atNow()

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

booleanColumn(name, value) → {Sender}

Write a boolean column with its value into the buffer of the sender.
Parameters:
Name Type Description
name string Column name.
value boolean Column value, accepts only boolean values.
Source:
Returns:
Returns with a reference to this sender.
Type
Sender

(async) close()

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

connect(options, secureopt) → {Promise.<boolean>}

Creates a connection to the database.
Parameters:
Name Type Attributes Default Description
options net.NetConnectOpts | tls.ConnectionOptions Connection options, host and port are required.
secure boolean <optional>
false If true connection will use TLS encryption.
Source:
Returns:
Resolves to true if client is connected.
Type
Promise.<boolean>

floatColumn(name, value) → {Sender}

Write a float column with its value into the buffer of the sender.
Parameters:
Name Type Description
name string Column name.
value number Column value, accepts only number values.
Source:
Returns:
Returns with a reference to this sender.
Type
Sender

(async) flush() → {Promise.<boolean>}

Sends the buffer's content to the database and compacts the buffer. If the last row is not finished it stays in the sender's buffer.
Source:
Returns:
Resolves to true if there was data in the buffer to send.
Type
Promise.<boolean>

intColumn(name, value) → {Sender}

Write an integer column with its value into the buffer of the sender.
Parameters:
Name Type Description
name string Column name.
value number Column value, accepts only number values.
Source:
Returns:
Returns with a reference to this sender.
Type
Sender

reset() → {Sender}

Resets the buffer, data added to the buffer will be lost.
In other words it clears the buffer and sets the writing position to the beginning of the buffer.
Source:
Returns:
Returns with a reference to this sender.
Type
Sender

resize(bufferSize)

Extends the size of the sender's buffer.
Can be used to increase the size of buffer if overflown. The buffer's content is copied into the new buffer.
Parameters:
Name Type Description
bufferSize number New size of the buffer used by the sender, provided in bytes.
Source:

stringColumn(name, value) → {Sender}

Write a string column with its value into the buffer of the sender.
Parameters:
Name Type Description
name string Column name.
value string Column value, accepts only string values.
Source:
Returns:
Returns with a reference to this sender.
Type
Sender

symbol(name, value) → {Sender}

Write a symbol name and value into the buffer of the sender.
Parameters:
Name Type Description
name string Symbol name.
value any Symbol value, toString() will be called to extract the actual symbol value from the parameter.
Source:
Returns:
Returns with a reference to this sender.
Type
Sender

table(table) → {Sender}

Write the table name into the buffer of the sender.
Parameters:
Name Type Description
table string Table name.
Source:
Returns:
Returns with a reference to this sender.
Type
Sender

timestampColumn(name, value) → {Sender}

Write a timestamp column with its value into the buffer of the sender.
Parameters:
Name Type Description
name string Column name.
value number Column value, accepts only number objects.
Source:
Returns:
Returns with a reference to this sender.
Type
Sender