module

Lustra::SQL::Query::Fetch

Instance methods

fetch(fetch_all = false, & : Hash(String, Lustra::SQL::Any) -> Nil)

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
Source
fetch_first

Alias for first because first is redefined in Collection::Base object to return a model instead.

Source
fetch_first!
Source
fetch_with_cursor(count = 1000, & : Hash(String, Lustra::SQL::Any) -> Nil)

Fetch 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.

Source
first

Return the first line of the query as Hash(String, ::Lustra::SQL::Any), or nil if not found

Source
first!
Source
scalar(type : T.class) forall T

Helpers to fetch a SELECT with only one row and one column return.

Source
to_a

Return an array with all the rows fetched.

Source