From f836bbfccb187379f4abfc984b2905a6e56947f0 Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Thu, 23 Jun 2016 17:27:30 -0300 Subject: [PATCH] add Database#using_connection to get a connection from the pool and return it when work is done. --- src/db/database.cr | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/db/database.cr b/src/db/database.cr index 7216ca5..6c8384e 100644 --- a/src/db/database.cr +++ b/src/db/database.cr @@ -45,6 +45,16 @@ module DB @in_pool = true end + # yields a connection from the pool + # the connection is returned to the pool after + # when the block ends + def using_connection + connection = get_from_pool + yield connection + ensure + return_to_pool connection + end + include QueryMethods end end