mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
ensure the connection is released after exec
avoid releasing connection twice on exec. avoid releasing connection when QueryMethod#query is blockless called.
This commit is contained in:
parent
b5112d9a48
commit
325fa9d4ae
5 changed files with 23 additions and 15 deletions
|
@ -35,7 +35,7 @@ module DB
|
|||
# end
|
||||
# ```
|
||||
def query(query, *args)
|
||||
prepare query, &.query(*args)
|
||||
prepare(query).query(*args)
|
||||
end
|
||||
|
||||
# Executes a *query* and yields a `ResultSet` with the results.
|
||||
|
@ -200,23 +200,13 @@ module DB
|
|||
|
||||
# Performs the `query` and returns an `ExecResult`
|
||||
def exec(query, *args)
|
||||
prepare query, &.exec(*args)
|
||||
prepare(query).exec(*args)
|
||||
end
|
||||
|
||||
# Performs the `query` and returns a single scalar value
|
||||
# puts db.scalar("SELECT MAX(name)").as(String) # => (a String)
|
||||
def scalar(query, *args)
|
||||
prepare query, &.scalar(*args)
|
||||
end
|
||||
|
||||
private def prepare(query)
|
||||
stm = prepare(query)
|
||||
begin
|
||||
yield stm
|
||||
rescue ex
|
||||
stm.release_connection
|
||||
raise ex
|
||||
end
|
||||
prepare(query).scalar(*args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -74,9 +74,9 @@ module DB
|
|||
end
|
||||
|
||||
private def perform_exec_and_release(args : Enumerable) : ExecResult
|
||||
res = perform_exec(args)
|
||||
return perform_exec(args)
|
||||
ensure
|
||||
release_connection
|
||||
res
|
||||
end
|
||||
|
||||
protected abstract def perform_query(args : Enumerable) : ResultSet
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue