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.
- checksums.yaml +4 -4
- data/lib/soql_builder.rb +26 -15
- 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: 5102bd01df0a350e928e8c4873716f75e100ec1cfe08eb21b0384e0a2c33c2e4
|
4
|
+
data.tar.gz: 01f59d9e6b1a28dc28e23fe40f3edc9843254720fe7667ec27fcf4acae16b469
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
22
|
+
structure_query
|
15
23
|
end
|
16
24
|
|
17
25
|
def fields(fields = [])
|
18
|
-
|
26
|
+
@query[:fields] = fields
|
19
27
|
self
|
20
28
|
end
|
21
29
|
|
22
|
-
def
|
23
|
-
subquery =
|
24
|
-
subquery
|
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
|
-
|
37
|
+
@query[:object_table] = table
|
32
38
|
self
|
33
39
|
end
|
34
40
|
|
35
|
-
def where(
|
36
|
-
|
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
|
43
|
-
@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
|