Make sql::with_conn and sql::start_stmt public

Existing public methods that use these functions, like sql::execute, are
only suitable for executing a single statement.

Sometimes it is useful to execute multiple statements within one
connection, for example to begin a transaction, execute mutliple SELECT
and INSERT queries and commit or rollback the whole transaction.
This commit is contained in:
Alexander Krotov
2020-02-15 16:28:46 +03:00
parent adb96e72b9
commit 784964efad

View File

@@ -113,7 +113,7 @@ impl Sql {
self.with_conn(|conn| conn.execute(sql, params).map_err(Into::into))
}
fn with_conn<T, G>(&self, g: G) -> Result<T>
pub fn with_conn<T, G>(&self, g: G) -> Result<T>
where
G: FnOnce(&mut Connection) -> Result<T>,
{
@@ -360,7 +360,7 @@ impl Sql {
.and_then(|r| r.parse().ok())
}
fn start_stmt(&self, stmt: impl AsRef<str>) {
pub fn start_stmt(&self, stmt: impl AsRef<str>) {
if let Some(query) = self.in_use.get_cloned() {
let bt = backtrace::Backtrace::new();
eprintln!("old query: {}", query);