module Clear::SQL::Query::Fetch
Direct including types
Defined in:
clear/sql/query/fetch.crInstance Method Summary
-
#fetch(fetch_all = false, & : Hash(String, Clear::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. -
#fetch_first
Alias for
#first
because first is redefined in Collection::Base object to return a model instead. - #fetch_first!
-
#fetch_with_cursor(count = 1000, & : Hash(String, Clear::SQL::Any) -> Nil)
Fetch the data using CURSOR.
-
#first
Return the first line of the query as Hash(String, ::Clear::SQL::Any), or nil if not found
- #first!
-
#scalar(type : T.class) forall T
Helpers to fetch a SELECT with only one row and one column return.
-
#to_a : Array(Hash(String, Clear::SQL::Any))
Return an array with all the rows fetched.
Instance Method Detail
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:
Clear::SQL.select.from("users").fetch do |u|
Clear::SQL.select.from("posts").where { u["id"] == posts.id }
end
# Instead, use `fetch_all`
# Clear will store the value of the result set in memory
# before calling the block, and the connection is now ready to handle
# another query.
Clear::SQL.select.from("users").fetch(fetch_all: true) do |u|
Clear::SQL.select.from("posts").where { u["id"] == posts.id }
end
Alias for #first
because first is redefined in Collection::Base
object to return a model instead.
Fetch the data using CURSOR. This will prevent Clear to load all the data from the database into memory. This is useful if you need to retrieve and update a large dataset.
Return the first line of the query as Hash(String, ::Clear::SQL::Any), or nil if not found
Helpers to fetch a SELECT with only one row and one column return.