sequel_count_comparisons 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/README.md +5 -10
- data/lib/sequel/count_comparisons/version.rb +1 -1
- data/lib/sequel/extensions/count_comparisons.rb +2 -29
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ced6b80b49999435cc463ecc48ab25bca414d9c70bb68a724818e153eac4d6a3
|
4
|
+
data.tar.gz: 6d86081df88ccffa77d0e351ab7f8030e39ddd6644be472f03a1584195c14ef4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfcfb41e72e28b9fd36e5c7b83f456b465a353cc85331fbbbb995fcebe232dbfa4d1332816faa19e09cd97ddfe7139aafc0fd886fc5f49db296c20e996be78b3
|
7
|
+
data.tar.gz: c684ee9ac727f9589343975ca53d1eb9060cd9636d958c5842f719e5f2d5fe3534ecb20c0b109322d2434477971cbc12ccc5bd4144a25184df0f1fd3ff3f9a63
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
# Sequel::CountComparisons
|
2
2
|
|
3
|
-
This gem adds
|
3
|
+
This gem adds three methods to `Sequel::Dataset`:
|
4
4
|
|
5
5
|
* `#count_equals?`
|
6
|
-
* `#count_greater_than?`
|
7
6
|
* `#count_less_than?`
|
8
|
-
* `#
|
9
|
-
* `#count_at_least?`
|
7
|
+
* `#count_greater_than?`
|
10
8
|
|
11
9
|
These methods allow you to efficiently compare a dataset's row count to a given number.
|
12
10
|
|
@@ -45,6 +43,9 @@ DB.extension(:count_comparisons)
|
|
45
43
|
DB[:table].count_equals?(1)
|
46
44
|
# SELECT EXISTS (SELECT 1 FROM table OFFSET 0) AND NOT EXISTS (SELECT 1 FROM table OFFSET 1)
|
47
45
|
|
46
|
+
DB[:table].count_equals?(0)
|
47
|
+
# SELECT 1 FROM table LIMIT 1
|
48
|
+
|
48
49
|
DB[:table].count_greater_than?(0)
|
49
50
|
# SELECT 1 FROM table LIMIT 1
|
50
51
|
|
@@ -57,12 +58,6 @@ DB[:table].count_less_than?(1)
|
|
57
58
|
DB[:table].count_less_than?(5)
|
58
59
|
# SELECT 1 FROM table LIMIT 1 OFFSET 4
|
59
60
|
|
60
|
-
DB[:table].count_at_least?(3)
|
61
|
-
# SELECT 1 FROM table LIMIT 1 OFFSET 2
|
62
|
-
|
63
|
-
DB[:table].count_at_most?(100)
|
64
|
-
# SELECT 1 FROM table LIMIT 1 OFFSET 100
|
65
|
-
|
66
61
|
```
|
67
62
|
|
68
63
|
## Caveats
|
@@ -3,8 +3,8 @@
|
|
3
3
|
require 'sequel'
|
4
4
|
require_relative '../count_comparisons/version'
|
5
5
|
|
6
|
-
# The count_comparisons extension adds the #count_greater_than?, #count_less_than
|
7
|
-
#
|
6
|
+
# The count_comparisons extension adds the #count_greater_than?, #count_less_than?
|
7
|
+
# and #count_equals? methods to Dataset. These methods can be used to efficiently
|
8
8
|
# compare a dataset's row count to a given number.
|
9
9
|
|
10
10
|
# You can load this extension into specific datasets:
|
@@ -60,33 +60,6 @@ module Sequel
|
|
60
60
|
!count_greater_than?(number_of_rows - 1)
|
61
61
|
end
|
62
62
|
|
63
|
-
# Returns true if at least *number_of_rows* records exist in the dataset, false otherwise
|
64
|
-
#
|
65
|
-
# Equivalent to a "greater than or equal to" (>=) comparison
|
66
|
-
#
|
67
|
-
# @param number_of_rows [Integer] The number to compare against
|
68
|
-
# @return [Boolean] Whether the dataset contains at least *number_of_rows*
|
69
|
-
# @raise [ArgumentError] If `number_of_rows` is not an integer
|
70
|
-
def count_at_least?(number_of_rows)
|
71
|
-
unless number_of_rows.is_a?(Integer)
|
72
|
-
raise ArgumentError,
|
73
|
-
"`number_of_rows` must be an Integer, got #{number_of_rows.inspect}"
|
74
|
-
end
|
75
|
-
|
76
|
-
count_greater_than?(number_of_rows - 1)
|
77
|
-
end
|
78
|
-
|
79
|
-
# Returns true if at most *number_of_rows* records exist in the dataset, false otherwise
|
80
|
-
#
|
81
|
-
# Equivalent to a "less than or equal to" (<=) comparison
|
82
|
-
#
|
83
|
-
# @param number_of_rows [Integer] The number to compare against
|
84
|
-
# @return [Boolean] Whether the dataset contains at most *number_of_rows*
|
85
|
-
# @raise [ArgumentError] If `number_of_rows` is not an integer
|
86
|
-
def count_at_most?(number_of_rows)
|
87
|
-
!count_greater_than?(number_of_rows)
|
88
|
-
end
|
89
|
-
|
90
63
|
# Returns true if exactly *number_of_rows* records exist in the dataset, false otherwise
|
91
64
|
#
|
92
65
|
# Equivalent to an "equal to" (==) comparison
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel_count_comparisons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- eriklovmo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -88,6 +88,5 @@ requirements: []
|
|
88
88
|
rubygems_version: 3.5.16
|
89
89
|
signing_key:
|
90
90
|
specification_version: 4
|
91
|
-
summary: 'Adds #
|
92
|
-
and #count_at_most? to Sequel::Dataset'
|
91
|
+
summary: 'Adds #count_less_than?, #count_equals? and #count_greater_than? to Sequel::Dataset'
|
93
92
|
test_files: []
|