soql_builder 1.0.8 → 1.0.9
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 +2 -2
- data/lib/soql_builder/interface.rb +22 -29
- data/lib/soql_builder/select_query.rb +29 -0
- data/lib/soql_builder/version.rb +1 -1
- metadata +2 -2
- data/lib/soql_builder/query.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a874d53ad1ef9faef114a669fabf4a4d56a024f3a56975941abbd548144f045f
|
4
|
+
data.tar.gz: 7e8d704b14e8915e97b89b296e92c43f878c09a309cf96f7449cf417ebfbc61e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2eac4f39dfab102d9e62a48d4ec4876a7bd94c4acb5a7d04179b5e1ff752c5144f9e04f39f8577996f29ba5c718e396620f4bf30852d6fc62d504e2ed8fc1ea3
|
7
|
+
data.tar.gz: 4d35f2d585305841f6649b97e5e2431806e6016bc4b13deba776e081fd3278d96d3df93cf0aa0d490c62576eb553692dfa73141b33047e6dc3ee6582f419993a
|
data/lib/soql_builder.rb
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'soql_builder/
|
3
|
+
require 'soql_builder/select_query'
|
4
4
|
|
5
5
|
module SoqlBuilder
|
6
6
|
class Interface
|
7
|
-
def initialize(type
|
8
|
-
@
|
9
|
-
@
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
def initialize(type:)
|
8
|
+
@query_klass = Module.const_get("SoqlBuilder::#{type.capitalize}Query")
|
9
|
+
@query_params = {
|
10
|
+
fields: [],
|
11
|
+
subqueries: [],
|
12
|
+
object_table: '',
|
13
|
+
where: '',
|
14
|
+
limit: ''
|
15
|
+
}
|
16
16
|
end
|
17
17
|
|
18
18
|
def query
|
19
|
-
@
|
20
|
-
type: @type,
|
21
|
-
fields: @fields,
|
22
|
-
subqueries: @subqueries,
|
23
|
-
object_table: @object_table,
|
24
|
-
where: @where,
|
25
|
-
limit: @limit
|
26
|
-
)
|
19
|
+
@query_klass.structure_query(@query_params)
|
27
20
|
end
|
28
21
|
|
29
22
|
def clean
|
30
|
-
@fields = []
|
31
|
-
@subqueries = []
|
32
|
-
@object_table = ''
|
33
|
-
@where = ''
|
34
|
-
@limit = ''
|
23
|
+
@query_params[:fields] = []
|
24
|
+
@query_params[:subqueries] = []
|
25
|
+
@query_params[:object_table] = ''
|
26
|
+
@query_params[:where] = ''
|
27
|
+
@query_params[:limit] = ''
|
35
28
|
end
|
36
29
|
|
37
30
|
def fields(fields = [])
|
38
|
-
@fields = fields
|
31
|
+
@query_params[:fields] = fields
|
39
32
|
self
|
40
33
|
end
|
41
34
|
|
42
35
|
def add_subquery(table:, fields: [])
|
43
|
-
|
44
|
-
@subqueries <<
|
36
|
+
subquery = { object_table: table, fields: fields }
|
37
|
+
@query_params[:subqueries] << subquery
|
45
38
|
self
|
46
39
|
end
|
47
40
|
|
48
41
|
def from(table)
|
49
|
-
@object_table = table
|
42
|
+
@query_params[:object_table] = table
|
50
43
|
self
|
51
44
|
end
|
52
45
|
|
53
46
|
def where(where_condition)
|
54
|
-
@where = where_condition
|
47
|
+
@query_params[:where] = where_condition
|
55
48
|
self
|
56
49
|
end
|
57
50
|
|
58
51
|
def limit(limit_number)
|
59
|
-
@limit = limit_number.to_s
|
52
|
+
@query_params[:limit] = limit_number.to_s
|
60
53
|
end
|
61
54
|
end
|
62
55
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SoqlBuilder
|
4
|
+
class SelectQuery
|
5
|
+
class << self
|
6
|
+
def structure_query(args = {})
|
7
|
+
query = 'select'.dup
|
8
|
+
query += " #{join_fields(args[:fields])}" unless args[:fields].empty?
|
9
|
+
query += join_subqueries(args[:subqueries]) unless args[:subqueries].empty?
|
10
|
+
query += " from #{args[:object_table]}" unless args[:object_table] == ''
|
11
|
+
query += " where #{args[:where]}" unless args[:where] == ''
|
12
|
+
query += " limit #{args[:limit]}" unless args[:limit] == ''
|
13
|
+
query
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def join_fields(fields)
|
19
|
+
fields.join(', ')
|
20
|
+
end
|
21
|
+
|
22
|
+
def join_subqueries(subqueries)
|
23
|
+
subqueries.map do |subquery|
|
24
|
+
", (select #{join_fields(subquery[:fields])} from #{subquery[:object_table]})"
|
25
|
+
end.join
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/soql_builder/version.rb
CHANGED
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.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Avlonitis
|
@@ -33,7 +33,7 @@ files:
|
|
33
33
|
- README.md
|
34
34
|
- lib/soql_builder.rb
|
35
35
|
- lib/soql_builder/interface.rb
|
36
|
-
- lib/soql_builder/
|
36
|
+
- lib/soql_builder/select_query.rb
|
37
37
|
- lib/soql_builder/version.rb
|
38
38
|
homepage: https://github.com/AlexAvlonitis/soql-builder
|
39
39
|
licenses:
|
data/lib/soql_builder/query.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SoqlBuilder
|
4
|
-
class Query
|
5
|
-
TYPES = {
|
6
|
-
select: 'select'
|
7
|
-
}.freeze
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@query = ''
|
11
|
-
end
|
12
|
-
|
13
|
-
def structure_query(args = {})
|
14
|
-
@query = TYPES[args[:type]]
|
15
|
-
@query += " #{join_fields(args[:fields])}" unless args[:fields].empty?
|
16
|
-
@query += join_subqueries(args[:subqueries]) unless args[:subqueries].empty?
|
17
|
-
@query += " from #{args[:object_table]}" unless args[:object_table] == ''
|
18
|
-
@query += " where #{args[:where]}" unless args[:where] == ''
|
19
|
-
@query += " limit #{args[:limit]}" unless args[:limit] == ''
|
20
|
-
@query
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def join_fields(fields)
|
26
|
-
fields.join(', ')
|
27
|
-
end
|
28
|
-
|
29
|
-
def join_subqueries(subqueries)
|
30
|
-
subqueries.map do |subquery|
|
31
|
-
", (select #{join_fields(subquery[:fields])} from #{subquery[:object_table]})"
|
32
|
-
end.join
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|