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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fecdbe7976189c6a9b9831e20218d6bca1c194f76db554972ead718cc2a26d36
4
- data.tar.gz: 6ebbac4f006d91085cc048803c0f683eafcce313cba70e2de8fa744b4d99f981
3
+ metadata.gz: b130a54954373ada660f1203488dbf1a8c7f086b7d22f6fdc3a1e5f37cbf5266
4
+ data.tar.gz: f6d4feef16b9bcf531bddeee8ac7628e95286e3f263c335213daad2cf889bca9
5
5
  SHA512:
6
- metadata.gz: acf29c44149ff9d77b66c248518e5f6bd2cdc0efd3ba3e8f831042557e63ed9512a163478669d7b5563fcb23c9de14e7afa28cc2b64369d18a35a5b0b5a25dd6
7
- data.tar.gz: 489890fdb0c75e76030bb01274c7178f2b132c587b7f19361ace87c7517ed5079003e4c36df4366a6b04c641827c7cb9b411211213c9e45cfffa0c21b2272208
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: [], filters: [], limit: nil, sorters: [])
26
- @fields = Field.array(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
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module Dbee
11
- VERSION = '1.0.0-alpha.2'
11
+ VERSION = '1.0.0-alpha.3'
12
12
  end
@@ -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' }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbee
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.alpha.2
4
+ version: 1.0.0.pre.alpha.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio