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
|
@ -102,14 +102,13 @@ module DB
|
||||||
|
|
||||||
# Same as `#open` but the database is yielded and closed automatically.
|
# Same as `#open` but the database is yielded and closed automatically.
|
||||||
def self.open(uri : URI | String, &block)
|
def self.open(uri : URI | String, &block)
|
||||||
build_database(uri).tap do |db|
|
db = build_database(uri)
|
||||||
begin
|
begin
|
||||||
yield db
|
yield db
|
||||||
ensure
|
ensure
|
||||||
db.close
|
db.close
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
private def self.build_database(connection_string : String)
|
private def self.build_database(connection_string : String)
|
||||||
build_database(URI.parse(connection_string))
|
build_database(URI.parse(connection_string))
|
||||||
|
|
|
@ -31,13 +31,8 @@ module DB
|
||||||
# The `ResultSet` is closed automatically.
|
# The `ResultSet` is closed automatically.
|
||||||
def query(query, *args)
|
def query(query, *args)
|
||||||
# CHECK prepare(query).query(*args, &block)
|
# CHECK prepare(query).query(*args, &block)
|
||||||
query(query, *args).tap do |rs|
|
rs = query(query, *args)
|
||||||
begin
|
yield rs ensure rs.close
|
||||||
yield rs
|
|
||||||
ensure
|
|
||||||
rs.close
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Performs the `query` and returns an `ExecResult`
|
# Performs the `query` and returns an `ExecResult`
|
||||||
|
|
|
@ -69,19 +69,14 @@ module DB
|
||||||
|
|
||||||
# See `QueryMethods#query`
|
# See `QueryMethods#query`
|
||||||
def query(*args)
|
def query(*args)
|
||||||
query(*args).tap do |rs|
|
rs = query(*args)
|
||||||
begin
|
yield rs ensure rs.close
|
||||||
yield rs
|
|
||||||
ensure
|
|
||||||
rs.close
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private def perform_exec_and_release(args : Enumerable) : ExecResult
|
private def perform_exec_and_release(args : Enumerable) : ExecResult
|
||||||
perform_exec(args).tap do
|
res = perform_exec(args)
|
||||||
release_connection
|
release_connection
|
||||||
end
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
protected abstract def perform_query(args : Enumerable) : ResultSet
|
protected abstract def perform_query(args : Enumerable) : ResultSet
|
||||||
|
|
Loading…
Reference in a new issue