soql_builder 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/soql_builder.rb +26 -15
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3003ce633f92747de3b8260ee7156bac4ad8aad978be30e1d884f9ef96f65a6
4
- data.tar.gz: 0eab09a6d55c77d374b4da34e302313589b6eb7d8d408990e35fb5214a0cb613
3
+ metadata.gz: 5102bd01df0a350e928e8c4873716f75e100ec1cfe08eb21b0384e0a2c33c2e4
4
+ data.tar.gz: 01f59d9e6b1a28dc28e23fe40f3edc9843254720fe7667ec27fcf4acae16b469
5
5
  SHA512:
6
- metadata.gz: cdd7394f5c64f710b15596e52aaf591fb4189b6c3aee51980d22af66ee28fd27cdc5061d48640f51f2de477dbec25c74c2699e0ad6348f4e72dacf0dc9b069d5
7
- data.tar.gz: 58f4534abb3f2ac8b65231202a01701a6d3b1b7eca7c4605bece95777680c31f22951d99053d5806938b57f28173a202d2bf5bce1b9d2c16af1d77ea56f045eb
6
+ metadata.gz: 3f291b31b62fc0b2569452bfc69aace985513d8d9bf3216e26f87ed48efd6819aefb066e4ec3dd950dccccac021ecd86aed9cf955d1dde42465345f4851b9d31
7
+ data.tar.gz: 42a8007add11319de3bc397ba758da370734ac6cc27d18e1a7d1e047afbe1456da1ed8758856da0d9221e644a40678a6877fd37bf7ac0873ba46e1b2f54f68a9
data/lib/soql_builder.rb CHANGED
@@ -6,47 +6,58 @@ class SoqlBuilder
6
6
  }.freeze
7
7
 
8
8
  def initialize(type:)
9
- @query = []
10
- add_to_query(TYPES[type])
9
+ @query = {
10
+ type: TYPES[type],
11
+ fields: [],
12
+ subquery: {
13
+ object_table: '',
14
+ fields: []
15
+ },
16
+ object_table: '',
17
+ where: '',
18
+ }
11
19
  end
12
20
 
13
21
  def query
14
- @query.clone.join(' ')
22
+ structure_query
15
23
  end
16
24
 
17
25
  def fields(fields = [])
18
- add_to_query(structure_fields(fields))
26
+ @query[:fields] = fields
19
27
  self
20
28
  end
21
29
 
22
- def add_child_lookup(child:, fields: [])
23
- subquery = ', (select '
24
- subquery += structure_fields(fields).join(' ')
25
- subquery += " from #{child})"
26
- add_to_query(subquery)
30
+ def add_subquery(table:, fields: [])
31
+ @query[:subquery][:object_table] = table
32
+ @query[:subquery][:fields] = fields
27
33
  self
28
34
  end
29
35
 
30
36
  def from(table)
31
- add_to_query('from ' + table)
37
+ @query[:object_table] = table
32
38
  self
33
39
  end
34
40
 
35
- def where(query)
36
- add_to_query('where ' + query)
41
+ def where(where_condition)
42
+ @query[:where] = where_condition
37
43
  self
38
44
  end
39
45
 
40
46
  private
41
47
 
42
- def add_to_query(partial_query)
43
- @query << partial_query
48
+ def structure_query
49
+ qs = @query[:type]
50
+ qs += " #{structure_fields(@query[:fields])}" unless @query[:fields].empty?
51
+ qs += ", (select #{ structure_fields(@query[:subquery][:fields]) } from #{ @query[:subquery][:object_table] })" unless @query[:subquery][:fields].empty?
52
+ qs += " from #{@query[:object_table]}"
53
+ qs += " where #{@query[:where]}" unless @query[:where] == ''
54
+ qs
44
55
  end
45
56
 
46
57
  def structure_fields(fields)
47
58
  fields.map.with_index do |field, index|
48
59
  field << ',' unless fields.length - 1 == index
49
60
  field
50
- end
61
+ end.join(' ')
51
62
  end
52
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soql_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Avlonitis