Class: Simple::SQL::Result
- Inherits:
-
Array
- Object
- Array
- Simple::SQL::Result
- Defined in:
- lib/simple/sql/result.rb,
lib/simple/sql/result.rb
Overview
The result of SQL.all
This class implements the basic interface of a Result set. Record result sets support the conversion of a record into a custom type of the callers choice, via the :into option for SQL.all and SQL.ask.
Direct Known Subclasses
Defined Under Namespace
Modules: AssociationLoader Classes: Records
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Class Method Summary collapse
-
.build(connection, records, target_type:, pg_source_oid:) ⇒ Object
A Result object is requested via ::Simple::SQL::Result.build, which then chooses the correct implementation, based on the
target_type:parameter.
Instance Method Summary collapse
-
#current_page ⇒ Object
returns the current page number in a paginated search.
-
#initialize(connection, records) ⇒ Result
constructor
:nodoc:.
- #paginated? ⇒ Boolean
-
#total_count ⇒ Object
returns the (potentialy slow) exact total count of results.
-
#total_fast_count ⇒ Object
returns the (potentialy estimated) total count of results.
-
#total_fast_pages ⇒ Object
returns the (potentialy estimated) total number of pages.
-
#total_pages ⇒ Object
returns the (potentialy estimated) total number of pages.
Constructor Details
#initialize(connection, records) ⇒ Result
:nodoc:
33 34 35 36 |
# File 'lib/simple/sql/result.rb', line 33 def initialize(connection, records) # :nodoc: @connection = connection replace(records) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
31 32 33 |
# File 'lib/simple/sql/result.rb', line 31 def connection @connection end |
Class Method Details
.build(connection, records, target_type:, pg_source_oid:) ⇒ Object
A Result object is requested via ::Simple::SQL::Result.build, which then chooses the correct implementation, based on the target_type: parameter.
23 24 25 26 27 28 29 |
# File 'lib/simple/sql/result.rb', line 23 def self.build(connection, records, target_type:, pg_source_oid:) # :nodoc: if target_type.nil? new(connection, records) else Records.new(connection, records, target_type: target_type, pg_source_oid: pg_source_oid) end end |
Instance Method Details
#current_page ⇒ Object
returns the current page number in a paginated search
This is only available for paginated scopes
69 70 71 |
# File 'lib/simple/sql/result.rb', line 69 def current_page @current_page ||= pagination_scope.page end |
#paginated? ⇒ Boolean
73 74 75 |
# File 'lib/simple/sql/result.rb', line 73 def paginated? !!@pagination_scope end |
#total_count ⇒ Object
returns the (potentialy slow) exact total count of results
This is only available for paginated scopes
55 56 57 |
# File 'lib/simple/sql/result.rb', line 55 def total_count @total_count ||= pagination_scope.count end |
#total_fast_count ⇒ Object
returns the (potentialy estimated) total count of results
This is only available for paginated scopes
41 42 43 |
# File 'lib/simple/sql/result.rb', line 41 def total_fast_count @total_fast_count ||= pagination_scope.fast_count end |
#total_fast_pages ⇒ Object
returns the (potentialy estimated) total number of pages
This is only available for paginated scopes
48 49 50 |
# File 'lib/simple/sql/result.rb', line 48 def total_fast_pages @total_fast_pages ||= (total_fast_count * 1.0 / pagination_scope.per).ceil end |
#total_pages ⇒ Object
returns the (potentialy estimated) total number of pages
This is only available for paginated scopes
62 63 64 |
# File 'lib/simple/sql/result.rb', line 62 def total_pages @total_pages ||= (total_count * 1.0 / pagination_scope.per).ceil end |