soql_builder 1.0.4 → 1.0.5

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: 6896103cda585b0692c479836fcd1fa54977a0c376b140cd0106ba02b0f7cf25
4
- data.tar.gz: f4c83fbe9aded0e162b0d5685154e3ece6044f92130ac8e8b5f4a8f228f04022
3
+ metadata.gz: ffcd93c75d97fff1473a54e9e22fb187a8e4196046db8caf74d746ac7187448b
4
+ data.tar.gz: 1202cc894c24d22f72b697a779377302c8853d3ff30102a2c5d050624773bf2d
5
5
  SHA512:
6
- metadata.gz: b14707fd25c85dc5f851e69f816b8b4b0b242111a8e9cedb5c7f2f06fa6cc67c5ecb1ad57d26fa923b5dfb4d995b2d690a02b2d4ac84ca2086a123efee970e1b
7
- data.tar.gz: 68a972be44ff182ff270f9c06b6d1b3bd60da89a0ce4ab3bc22533fe3e4a1a96f206d685b17b859d9915ef1e9e4d5b9f93125c1ff81e07b478177ee722d09334
6
+ metadata.gz: f6daed2b7355eef9c0b12ec116a70676f54b1961640aa7ebce9ea6ab66bc80d8a333d794d906213f94af967d396701449ac06ffaf6a9d388b79ad7d95e98f248
7
+ data.tar.gz: 9a6ee1363f638789810a05de38b95a50cdc84beb6db489252002934074272b064c8a992d9ab8da9a64a768c77b42878ad27d17e45c968de5960fc2c1f6ea7a56
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # SOQL-BUILDER (BETA)
2
+
3
+ [![Build Status](https://travis-ci.org/AlexAvlonitis/soql-builder.svg?branch=master)](https://travis-ci.org/AlexAvlonitis/soql-builder)
4
+
5
+ A ruby SOQL query builder, to build salesforce query strings.
6
+ It doesn't include all the available SOQL queries.
7
+ Contributions are welcome.
8
+
9
+ ## How to use
10
+
11
+ ```ruby
12
+ # ruby
13
+ gem install 'soql_builder'
14
+
15
+ # rails
16
+ gem 'soql_builder'
17
+ ```
18
+
19
+ ```ruby
20
+ require 'soql_builder'
21
+
22
+ builder = SoqlBuilder.new(type: :select)
23
+ ```
24
+
25
+ **Simple select query**
26
+ ```ruby
27
+ # In the fields method you can add parent table fields, an exaple of Contract__r.Name below
28
+ builder.fields(['Name', 'Contract__r.Name'])
29
+ .from('Account')
30
+ .where('id = 1')
31
+
32
+ builder.query
33
+ => "select Name, Contract__r.Name from Account where id = 1"
34
+
35
+ # Add a limit
36
+ builder.fields(['Name', 'Contract__r.Name'])
37
+ .from('Account')
38
+ .where('id = 1')
39
+ .limit(1)
40
+
41
+ builder.query
42
+ => "select Name, Contract__r.Name from Account where id = 1 limit 1"
43
+
44
+ ```
45
+
46
+ **Select query with subquery**
47
+
48
+ ```ruby
49
+ builder.fields(['Name', 'Contract__r.Name'])
50
+ .add_subquery(
51
+ table: 'Account.Quotes',
52
+ fields: ['Quotes.Name', 'Quotes.id']
53
+ )
54
+ .from('Account')
55
+ .where('id = 1')
56
+
57
+ builder.query
58
+ => "select Name, Contract__r.Name, (select Quotes.Name, Quotes.id from Account.Quotes) from Account where id = 1"
59
+
60
+ ```
61
+
62
+ **Queries can be added one at a time, instead of chaining**
63
+
64
+ ```ruby
65
+ builder.fields(['Name', 'Contract__r.Name'])
66
+
67
+ builder.add_subquery(
68
+ table: 'Account.Quotes',
69
+ fields: ['Quotes.Name', 'Quotes.id']
70
+ )
71
+
72
+ builder.from('Account')
73
+
74
+ builder.where('id = 1')
75
+
76
+ builder.query
77
+ => "select Name, Contract__r.Name, (select Quotes.Name, Quotes.id from Account.Quotes) from Account where id = 1"
78
+ ```
79
+
80
+
data/lib/soql/query.rb ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Soql
4
+ class Query
5
+ attr_accessor :fields, :subquery, :object_table, :where, :limit
6
+ attr_reader :type
7
+
8
+ TYPES = {
9
+ select: 'select'
10
+ }.freeze
11
+
12
+ def initialize
13
+ @type = ''
14
+ @fields = []
15
+ @subquery = { object_table: '', fields: [] }
16
+ @object_table = ''
17
+ @where = ''
18
+ @limit = ''
19
+ end
20
+
21
+ def type=(type)
22
+ @type = TYPES[type]
23
+ end
24
+
25
+ def structure_query
26
+ qs = type
27
+ qs += " #{join_fields(fields)}" unless fields.empty?
28
+ qs += ", (select #{join_fields(subquery[:fields])} from #{subquery[:object_table]})" unless subquery[:fields].empty?
29
+ qs += " from #{object_table}" unless object_table == ''
30
+ qs += " where #{where}" unless where == ''
31
+ qs += " limit #{limit}" unless limit == ''
32
+ qs
33
+ end
34
+
35
+ private
36
+
37
+ def join_fields(fields)
38
+ fields.join(', ')
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Soql
4
+ VERSION = '1.0.5'.freeze
5
+ 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.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Avlonitis
@@ -30,6 +30,9 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
+ - README.md
34
+ - lib/soql/query.rb
35
+ - lib/soql/version.rb
33
36
  - lib/soql_builder.rb
34
37
  homepage: https://github.com/AlexAvlonitis/soql-builder
35
38
  licenses: