mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Release DB connection if an exception occurs during execution of a query
This commit is contained in:
parent
4f724475e0
commit
d7fdf1eada
1 changed files with 12 additions and 3 deletions
|
@ -80,17 +80,17 @@ module DB
|
|||
|
||||
# See `QueryMethods#query`
|
||||
def query
|
||||
perform_query Tuple.new
|
||||
perform_query_with_rescue Tuple.new
|
||||
end
|
||||
|
||||
# See `QueryMethods#query`
|
||||
def query(args : Array)
|
||||
perform_query args
|
||||
perform_query_with_rescue args
|
||||
end
|
||||
|
||||
# See `QueryMethods#query`
|
||||
def query(*args)
|
||||
perform_query args
|
||||
perform_query_with_rescue args
|
||||
end
|
||||
|
||||
private def perform_exec_and_release(args : Enumerable) : ExecResult
|
||||
|
@ -99,6 +99,15 @@ module DB
|
|||
release_connection
|
||||
end
|
||||
|
||||
private def perform_query_with_rescue(args : Enumerable) : ResultSet
|
||||
return perform_query(args)
|
||||
rescue e : Exception
|
||||
# Release connection only when an exception occurs during the query
|
||||
# execution since we need the connection open while the ResultSet is open
|
||||
release_connection
|
||||
raise e
|
||||
end
|
||||
|
||||
protected abstract def perform_query(args : Enumerable) : ResultSet
|
||||
protected abstract def perform_exec(args : Enumerable) : ExecResult
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue