Module: Sequel::Extensions::CountComparisons
- Defined in:
- lib/sequel/extensions/count_comparisons.rb
Instance Method Summary collapse
-
#count_equals?(number_of_rows) ⇒ Boolean
Returns true if exactly number_of_rows records exist in the dataset, false otherwise.
-
#count_greater_than?(number_of_rows) ⇒ Boolean
Returns true if more than number_of_rows records exist in the dataset, false otherwise.
-
#count_less_than?(number_of_rows) ⇒ Boolean
Returns true if fewer than number_of_rows records exist in the dataset, false otherwise.
Instance Method Details
#count_equals?(number_of_rows) ⇒ Boolean
Returns true if exactly number_of_rows records exist in the dataset, false otherwise
Equivalent to an “equal to” (==) comparison
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/sequel/extensions/count_comparisons.rb', line 70 def count_equals?(number_of_rows) unless number_of_rows.is_a?(Integer) raise ArgumentError, "`number_of_rows` must be an Integer, got #{number_of_rows.inspect}" end if number_of_rows.negative? false elsif number_of_rows.zero? empty? else ds = @opts[:sql] ? from_self : self ds = ds.unordered.select(LITERAL_1) @db.get( ds.offset(number_of_rows - 1).exists & ~ds.offset(number_of_rows).exists ) end end |
#count_greater_than?(number_of_rows) ⇒ Boolean
Returns true if more than number_of_rows records exist in the dataset, false otherwise
Equivalent to a “greater than” (>) comparison
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sequel/extensions/count_comparisons.rb', line 31 def count_greater_than?(number_of_rows) unless number_of_rows.is_a?(Integer) raise ArgumentError, "`number_of_rows` must be an Integer, got #{number_of_rows.inspect}" end if number_of_rows.negative? true elsif number_of_rows.zero? !empty? else ds = @opts[:sql] ? from_self : self !ds.offset(number_of_rows).empty? end end |
#count_less_than?(number_of_rows) ⇒ Boolean
Returns true if fewer than number_of_rows records exist in the dataset, false otherwise
Equivalent to a “less than” (<) comparison
54 55 56 57 58 59 60 61 |
# File 'lib/sequel/extensions/count_comparisons.rb', line 54 def count_less_than?(number_of_rows) unless number_of_rows.is_a?(Integer) raise ArgumentError, "`number_of_rows` must be an Integer, got #{number_of_rows.inspect}" end !count_greater_than?(number_of_rows - 1) end |