% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/db_utils.R
\name{ddbs_create_conn}
\alias{ddbs_create_conn}
\title{Create a DuckDB connection with spatial extension}
\usage{
ddbs_create_conn(
  dbdir = "memory",
  threads = NULL,
  memory_limit_gb = NULL,
  upgrade = FALSE,
  ...,
  duckdb_storage_version = duckspatial_storage_default()
)
}
\arguments{
\item{dbdir}{String. Either \code{"tempdir"}, \code{"memory"}, or a DuckDB database
file path with \code{.duckdb}, \code{.db}, or \code{.ddb} extension. Defaults to \code{"memory"}.}

\item{threads}{Integer. Number of threads to use. If \code{NULL} (default), the setting is not changed, and DuckDB engine will use all available cores it detects (warning, on some shared HPC nodes the detected number of cores might be total number of cores on the node, not the per-job allocation).}

\item{memory_limit_gb}{Numeric. Memory limit in GB. If \code{NULL} (default), the setting is not changed, and DuckDB engine will use 80\% of available operating system memory it detects (warning, on some shared HPC nodes the detected memory might be the full node memory, not the per-job allocation).}

\item{upgrade}{if TRUE, it upgrades the DuckDB extension to the latest version}

\item{...}{Additional parameters to be passed to \code{\link[DBI]{dbConnect}}}

\item{duckdb_storage_version}{Storage compatibility for newly created persistent
native DuckDB files (\code{.duckdb}, \code{.db}, \code{.ddb}). See
\url{https://duckdb.org/docs/internals/storage} for more information on
DuckDB storage versions and compatibility.
\itemize{
\item \code{"v1.5.0"} (\strong{Native Spatial Storage}, Default): Preserves
CRS metadata in native DuckDB \code{GEOMETRY} columns. Requires
DuckDB >= 1.5.0 to open the file.
\item \code{"v1.0.0"} (\strong{Legacy Compatibility}): Creates
files readable by older DuckDB versions (>= 1.0.0). Persists CRS
metadata in duckspatial-managed column comments (a convention not
recognized by other spatial software).
\item \code{"latest"}: Use the highest storage version supported by your
installed DuckDB engine.
}
Other major version strings like \code{"v1.4.0"}, \code{"v1.3.0"}, etc., are also supported.}
}
\value{
A \code{duckdb_connection}
}
\description{
It creates a DuckDB connection, and then it installs and loads the
spatial extension
}
\examples{
\dontrun{
# load packages
library(duckspatial)

# create a duckdb database in memory (with spatial extension)
conn <- ddbs_create_conn(dbdir = "memory")

# create a duckdb database in disk  (with spatial extension)
conn <- ddbs_create_conn(dbdir = "tempdir")

# create a connection with 1 thread and 2GB memory limit
conn <- ddbs_create_conn(threads = 1, memory_limit_gb = 2)
ddbs_stop_conn(conn)
}
}
