adbc_connection_join {adbcdrivermanager}R Documentation

Join the lifecycle of a unique parent to its child

Description

It is occasionally useful to return a connection, statement, or stream from a function that was created from a unique parent. These helpers tie the lifecycle of a unique parent object to its child such that the parent object is released predictably and immediately after the child. These functions will invalidate all references to the previous R object.

Usage

adbc_connection_join(connection, database)

adbc_statement_join(statement, connection)

Arguments

connection

A connection created with adbc_connection_init()

database

A database created with adbc_database_init()

statement

A statement created with adbc_statement_init()

Value

The input, invisibly.

Examples

# Use local_adbc to ensure prompt cleanup on error;
# use join functions to return a single object that manages
# the lifecycle of all three.
stmt <- local({
  db <- local_adbc(adbc_database_init(adbc_driver_log()))

  con <- local_adbc(adbc_connection_init(db))
  adbc_connection_join(con, db)

  stmt <- local_adbc(adbc_statement_init(con))
  adbc_statement_join(stmt, con)

  adbc_xptr_move(stmt)
})

# Everything is released immediately when the last object is released
adbc_statement_release(stmt)


[Package adbcdrivermanager version 0.11.0 Index]