dbee 1.0.0.pre.alpha.2 → 1.0.0.pre.alpha.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dbee/query.rb +10 -2
- data/lib/dbee/version.rb +1 -1
- data/spec/dbee/query_spec.rb +10 -0
- data/spec/dbee_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b130a54954373ada660f1203488dbf1a8c7f086b7d22f6fdc3a1e5f37cbf5266
|
4
|
+
data.tar.gz: f6d4feef16b9bcf531bddeee8ac7628e95286e3f263c335213daad2cf889bca9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29a0abfebc532e09f81953ec8a9918887bb6ab0bbb3e50d68e1615df71b2c913af0fb9a063ab38381adbcf614df27c6322f297a16d4a90d6481a1608b02ac31b
|
7
|
+
data.tar.gz: ad4f0531f7bfc44e7d5461f453fecfebccb3afbbfb997d111a154030188d9ce4a4d206fdcb9d466027439a182e7c4fb3127327b104223e615be203bd9775b857
|
data/lib/dbee/query.rb
CHANGED
@@ -20,10 +20,18 @@ module Dbee
|
|
20
20
|
class Query
|
21
21
|
acts_as_hashable
|
22
22
|
|
23
|
+
class NoFieldsError < StandardError; end
|
24
|
+
|
23
25
|
attr_reader :fields, :filters, :limit, :sorters
|
24
26
|
|
25
|
-
def initialize(fields
|
26
|
-
@fields
|
27
|
+
def initialize(fields:, filters: [], limit: nil, sorters: [])
|
28
|
+
@fields = Field.array(fields)
|
29
|
+
|
30
|
+
# If no fields were passed into a query then we will have no data to return.
|
31
|
+
# Let's raise a hard error here and let the consumer deal with it since this may
|
32
|
+
# have implications in downstream SQL generators.
|
33
|
+
raise NoFieldsError if @fields.empty?
|
34
|
+
|
27
35
|
@filters = Filters.array(filters)
|
28
36
|
@limit = limit.to_s.empty? ? nil : limit.to_i
|
29
37
|
@sorters = Sorter.array(sorters)
|
data/lib/dbee/version.rb
CHANGED
data/spec/dbee/query_spec.rb
CHANGED
@@ -31,6 +31,16 @@ describe Dbee::Query do
|
|
31
31
|
expect(subject).to eq(described_class.make(config))
|
32
32
|
end
|
33
33
|
|
34
|
+
describe '#initialize' do
|
35
|
+
it 'should raise an ArgumentError if fields keyword is missing' do
|
36
|
+
expect { described_class.new }.to raise_error(ArgumentError)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should raise a NoFieldsError if no fields were passed in' do
|
40
|
+
expect { described_class.new(fields: []) }.to raise_error(Dbee::Query::NoFieldsError)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
34
44
|
context 'README examples' do
|
35
45
|
EXAMPLES = {
|
36
46
|
'Get all practices' => {
|
data/spec/dbee_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe Dbee do
|
|
14
14
|
describe '#sql' do
|
15
15
|
let(:provider) { Dbee::Providers::NullProvider.new }
|
16
16
|
|
17
|
-
let(:query) { {} }
|
17
|
+
let(:query) { { fields: [{ key_path: :a }] } }
|
18
18
|
|
19
19
|
it 'accepts a hash as a model and passes a Model instance to provider#sql' do
|
20
20
|
model = { name: 'something' }
|