Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Expand DBI documentation #190

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions R/DBI-custom.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#' bound to a connection. Instead use [poolWithTransaction()].
#'
#' * [DBI::dbDisconnect()] can't work because pool handles disconnection.
#' Use [poolClose()] instead.
#'
#' * [DBI::dbGetInfo()] returns information about the pool, not the database
#' connection.
Expand Down
2 changes: 1 addition & 1 deletion R/DBI-wrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#' These pool method for DBI generics methods check out a connection
#' (with [poolCheckout()]), re-call the generic, then return the connection
#' to the pool (with [poolReturn()]).
#' See [DBI-custom] for DBI methods that do not work with pool objects.
#'
#' @name DBI-wrap
#' @keywords internal
#' @examples
#' mtcars1 <- mtcars[ c(1:16), ] # first half of the mtcars dataset
#' mtcars2 <- mtcars[-c(1:16), ] # second half of the mtcars dataset
Expand Down
12 changes: 12 additions & 0 deletions R/DBI.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
#' `dbPool()` is a drop-in replacement for [DBI::dbConnect()] that
#' provides a shared pool of connections that can automatically reconnect
#' to the database if needed.
#' See [DBI-wrap] for methods to use with pool objects,
#' and [DBI-custom] for unsupported methods and the "pool" way of using them.
#'
#' A new connection is created transparently
#'
#' - if the pool is empty
#' - if the currently checked out connection is invalid
#' (checked at most once every `validationInterval` seconds)
#' - if the pool is not full and the connections are all in use
#'
#' Use [poolClose()] to close the pool and all connections in it.
#' See [poolCraete()] for details on the internal workings of the pool.
#'
#' @param drv A [DBI Driver][DBI::DBIDriver-class], e.g. `RSQLite::SQLite()`,
#' `RPostgres::Postgres()`, `odbc::odbc()` etc.
Expand Down
3 changes: 2 additions & 1 deletion R/pool-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ setMethod("poolClose", "Pool", function(pool) {
#' When pooling DBI database connections, you normally would not use
#' `poolCheckout()`. Instead, for single-shot queries, treat the pool object
#' itself as the DBI connection object and it will perform checkout/return for
#' you. And for transactions, use [poolWithTransaction()].
#' you. And for transactions, use [poolWithTransaction()]. See [dbPool()] for
#' an example.
#'
#' @param pool The pool to get the object from.
#' @export
Expand Down
3 changes: 2 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ reference:
- title: Database functions
contents:
- dbPool
- 'DBI-custom'
- 'DBI-wrap'
- poolWithTransaction
- tbl.Pool
- 'DBI-custom'
1 change: 1 addition & 0 deletions man/DBI-custom.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/DBI-wrap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions man/dbPool.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/poolCheckout.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading