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)
adbc_stream_join(stream, x)
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()
- stream
- x
An ADBC database, ADBC connection, ADBC statement, or nanoarrow_array_stream returned from calls to an ADBC function.
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)
})
#> LogDatabaseNew()
#> LogDatabaseInit()
#> LogConnectionNew()
#> LogConnectionInit()
#> LogStatementNew()
# Everything is released immediately when the last object is released
adbc_statement_release(stmt)
#> LogStatementRelease()
#> LogConnectionRelease()
#> LogDatabaseRelease()
#> LogDriverRelease()