% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/SemsqlConn-S7.R
\name{with_connection}
\alias{with_connection}
\title{Execute code with an automatically managed SemsqlConn}
\usage{
with_connection(db_path, expr)
}
\arguments{
\item{db_path}{character(1) path to the SQLite database.}

\item{expr}{an expression to evaluate; \code{conn} is bound to the open
\code{SemsqlConn} within this expression.}
}
\value{
the value of \code{expr}.
}
\description{
Opens a connection, evaluates an expression with \code{conn} bound to the
open \code{SemsqlConn}, then closes the connection even if an error occurs.
Analogous to Python's context manager (\code{with} statement).
}
\examples{
\dontrun{
result <- with_connection("cl.db", {
  get_ancestors(conn, "CL:0000540")
})
}
}
