Class: Connection

Connection(database, numThreads)

new Connection(database, numThreads)

Initialize a new Connection object. Note that the initialization is done lazily, so the connection is not initialized until the first query is executed. To initialize the connection immediately, call the `init()` function on the returned object.
Parameters:
Name Type Default Description
database kuzu.Database the database object to connect to.
numThreads Number null the maximum number of threads to use for query execution.
Source:

Methods

(async) _getConnection() → {KuzuNative.NodeConnection}

Internal function to get the underlying native connection object.
Source:
Throws:
if the connection is closed.
Type
Error
Returns:
the underlying native connection.
Type
KuzuNative.NodeConnection

_getConnectionSync() → {KuzuNative.NodeConnection}

Internal function to get the underlying native connection object synchronously.
Source:
Throws:
if the connection is closed.
Type
Error
Returns:
the underlying native connection.
Type
KuzuNative.NodeConnection

_getNextQueryResult(nodeQueryResult) → {Promise.<kuzu.QueryResult>}

Internal function to get the next query result for multiple query results.
Parameters:
Name Type Description
nodeQueryResult KuzuNative.NodeQueryResult the current node query result.
Source:
Returns:
a promise that resolves to the next query result. The promise is rejected if there is an error.
Type
Promise.<kuzu.QueryResult>

(async) _unwrapMultipleQueryResults(nodeQueryResult) → {Promise.<Array.<kuzu.QueryResult>>|kuzu.QueryResult}

Internal function to unwrap multiple query results into an array of query results.
Parameters:
Name Type Description
nodeQueryResult KuzuNative.NodeQueryResult the node query result.
Source:
Returns:
a promise that resolves to an array of query results. The promise is rejected if there is an error.
Type
Promise.<Array.<kuzu.QueryResult>> | kuzu.QueryResult

_unwrapMultipleQueryResultsSync(nodeQueryResult) → {Array.<kuzu.QueryResult>|kuzu.QueryResult}

Internal function to unwrap multiple query results into an array of query results synchronously.
Parameters:
Name Type Description
nodeQueryResult KuzuNative.NodeQueryResult the node query result.
Source:
Throws:
if there is an error.
Type
Error
Returns:
an array of query results.
Type
Array.<kuzu.QueryResult> | kuzu.QueryResult

(async) close()

Close the connection. Note: Call to this method is optional. The connection will be closed automatically when the object goes out of scope.
Source:

closeSync()

Close the connection synchronously.
Source:
Throws:
if there is an undergoing asynchronous initialization.
Type
Error

execute(preparedStatement, params, progressCallbackopt) → {Promise.<kuzu.QueryResult>}

Execute a prepared statement with the given parameters.
Parameters:
Name Type Attributes Description
preparedStatement kuzu.PreparedStatement the prepared statement to execute.
params Object a plain object mapping parameter names to values.
progressCallback function <optional>
Optional callback function that is invoked with the progress of the query execution. The callback receives three arguments: pipelineProgress, numPipelinesFinished, and numPipelines.
Source:
Returns:
a promise that resolves to the query result. The promise is rejected if there is an error.
Type
Promise.<kuzu.QueryResult>

executeSync(preparedStatement, params) → {Array.<kuzu.QueryResult>|kuzu.QueryResult}

Execute a prepared statement with the given parameters synchronously. This function blocks the main thread for the duration of the query, so use it with caution.
Parameters:
Name Type Description
preparedStatement kuzu.PreparedStatement the prepared statement
params Object a plain object mapping parameter names to values.
Source:
Throws:
if there is an error.
Type
Error
Returns:
an array of query results. If there is only one query result, the function returns the query result directly.
Type
Array.<kuzu.QueryResult> | kuzu.QueryResult

(async) init()

Initialize the connection. Calling this function is optional, as the connection is initialized automatically when the first query is executed.
Source:

initSync()

Initialize the connection synchronously. Calling this function is optional, as the connection is initialized automatically when the first query is executed. This function may block the main thread, so use it with caution.
Source:

prepare(statement) → {Promise.<kuzu.PreparedStatement>}

Prepare a statement for execution.
Parameters:
Name Type Description
statement String the statement to prepare.
Source:
Returns:
a promise that resolves to the prepared statement. The promise is rejected if there is an error.
Type
Promise.<kuzu.PreparedStatement>

prepareSync(statement) → {kuzu.PreparedStatement}

Prepare a statement for execution synchronously. This function blocks the main thread so use it with caution.
Parameters:
Name Type Description
statement String the statement to prepare.
Source:
Throws:
if there is an error.
Type
Error
Returns:
the prepared statement.
Type
kuzu.PreparedStatement

query(statement, progressCallbackopt) → {Promise.<kuzu.QueryResult>}

Execute a query.
Parameters:
Name Type Attributes Description
statement String the statement to execute.
progressCallback function <optional>
Optional callback function that is invoked with the progress of the query execution. The callback receives three arguments: pipelineProgress, numPipelinesFinished, and numPipelines.
Source:
Returns:
a promise that resolves to the query result. The promise is rejected if there is an error.
Type
Promise.<kuzu.QueryResult>

querySync(statement) → {Array.<kuzu.QueryResult>|kuzu.QueryResult}

Execute a query synchronously.
Parameters:
Name Type Description
statement String the statement to execute. This function blocks the main thread for the duration of the query, so use it with caution.
Source:
Throws:
  • if there is an error.
    Type
    Error
  • if the statement is not a string.
    Type
    Error
  • if the connection is closed.
    Type
    Error
Returns:
an array of query results. If there is only one query result, the function returns the query result directly.
Type
Array.<kuzu.QueryResult> | kuzu.QueryResult

setMaxNumThreadForExec(numThreads)

Set the maximum number of threads to use for query execution.
Parameters:
Name Type Description
numThreads Number the maximum number of threads to use for query execution.
Source:

setQueryTimeout(timeoutInMs)

Set the timeout for queries. Queries that take longer than the timeout will be aborted.
Parameters:
Name Type Description
timeoutInMs Number the timeout in milliseconds.
Source: