mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Don't use tap so return value is that of yield
This commit is contained in:
parent
72431bb1d8
commit
038ffef33a
3 changed files with 12 additions and 23 deletions
11
src/db.cr
11
src/db.cr
|
@ -102,12 +102,11 @@ module DB
|
|||
|
||||
# Same as `#open` but the database is yielded and closed automatically.
|
||||
def self.open(uri : URI | String, &block)
|
||||
build_database(uri).tap do |db|
|
||||
begin
|
||||
yield db
|
||||
ensure
|
||||
db.close
|
||||
end
|
||||
db = build_database(uri)
|
||||
begin
|
||||
yield db
|
||||
ensure
|
||||
db.close
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -31,13 +31,8 @@ module DB
|
|||
# The `ResultSet` is closed automatically.
|
||||
def query(query, *args)
|
||||
# CHECK prepare(query).query(*args, &block)
|
||||
query(query, *args).tap do |rs|
|
||||
begin
|
||||
yield rs
|
||||
ensure
|
||||
rs.close
|
||||
end
|
||||
end
|
||||
rs = query(query, *args)
|
||||
yield rs ensure rs.close
|
||||
end
|
||||
|
||||
# Performs the `query` and returns an `ExecResult`
|
||||
|
|
|
@ -69,19 +69,14 @@ module DB
|
|||
|
||||
# See `QueryMethods#query`
|
||||
def query(*args)
|
||||
query(*args).tap do |rs|
|
||||
begin
|
||||
yield rs
|
||||
ensure
|
||||
rs.close
|
||||
end
|
||||
end
|
||||
rs = query(*args)
|
||||
yield rs ensure rs.close
|
||||
end
|
||||
|
||||
private def perform_exec_and_release(args : Enumerable) : ExecResult
|
||||
perform_exec(args).tap do
|
||||
release_connection
|
||||
end
|
||||
res = perform_exec(args)
|
||||
release_connection
|
||||
res
|
||||
end
|
||||
|
||||
protected abstract def perform_query(args : Enumerable) : ResultSet
|
||||
|
|
Loading…
Reference in a new issue