Lustra::SQL::Query::Fetch
Instance methods
Fetch the result set row per row
fetch_all optional parameter is helpful in transactional environment, so it stores
the result and close the resultset before starting to call yield over the data
preventing creation of a new connection if you need to call SQL into the
yielded block.
# This is wrong: The connection is still busy retrieving the users:
Lustra::SQL.select.from("users").fetch do |u|
Lustra::SQL.select.from("posts").where { u["id"] == posts.id }
end
# Instead, use `fetch_all`
# Lustra will store the value of the result set in memory
# before calling the block, and the connection is now ready to handle
# another query.
Lustra::SQL.select.from("users").fetch(fetch_all: true) do |u|
Lustra::SQL.select.from("posts").where { u["id"] == posts.id }
end
fetch_first
Alias for first because first is redefined in Collection::Base
object to return a model instead.
fetch_first!
SourceFetch the data using CURSOR. This will prevent Lustra to load all the data from the database into memory. This is useful if you need to retrieve and update a large dataset.
first
Return the first line of the query as Hash(String, ::Lustra::SQL::Any), or nil if not found
first!
Sourcescalar(type : T.class) forall T
Helpers to fetch a SELECT with only one row and one column return.