Skip to contents

Return or print the current database user for a MotherDuck / DuckDB connection.

Usage

show_current_user(.con, motherduck_token, return = "msg")

Arguments

.con

A valid DBI connection (DuckDB / MotherDuck).

motherduck_token

Character. Either the name of an environment variable containing your MotherDuck access token (default "MOTHERDUCK_TOKEN") or the token itself.

return

Character scalar, one of "msg" or "arg". Default: "msg".

Details

This helper queries the active DB connection for the current user (via SELECT current_user). You may either provide an existing DBI connection via .con or provide a motherduck_token and let the function open a short-lived connection for you. When the function opens a connection it will close it before returning.

The function supports two output modes:

  • "msg" — prints a small informative message and returns the result invisibly (useful for interactive use),

  • "arg" — returns a tibble containing the current_user column.

Examples

if (FALSE) { # \dontrun{
# Using an existing connection
con <- connect_to_motherduck("my_token")
show_current_user(.con = con, return = "msg")

# Let the function open a connection from a token
tbl <- show_current_user(motherduck_token = "my_token", return = "arg")
} # }