Skip to contents

Ensures a database exists and sets it as the active database. If connected to MotherDuck, the function will run CREATE DATABASE IF NOT EXISTS followed by USE <database>. Prints CLI status information about the current user and database.

Usage

create_database(.con, database_name)

Arguments

.con

A valid DBI connection (DuckDB / MotherDuck).

database_name

Name of the database to create/ensure and switch to

Value

Invisibly returns NULL. Side effect: may create a database and switches to it; prints CLI status

Details

  • Connection type is checked via validate_md_connection_status() (with return_type = "arg").

  • On MotherDuck, executes:

    • CREATE DATABASE IF NOT EXISTS <database>

    • USE <database>

  • Displays status and environment info with CLI messages.

Examples

if (FALSE) { # \dontrun{
con_md <- connect_to_motherduck()
create_database(con_md, "analytics")
} # }