Socket
Book a DemoInstallSign in
Socket

soql_builder

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

soql_builder

1.0.9
bundlerRubygems
Version published
Maintainers
1
Created
Source

SOQL-BUILDER

Build Status

A ruby SOQL query builder, to build salesforce query strings. It doesn't include all the available SOQL queries. Contributions are welcome.

How to use

# ruby
gem install 'soql_builder'

# rails
gem 'soql_builder'
require 'soql_builder'

builder = SoqlBuilder.new(type: :select)

Simple select query

# In the fields method you can add parent table fields, an exaple of Contract__r.Name below
builder.fields(['Name', 'Contract__r.Name'])
       .from('Account')
       .where('id = 1')

builder.query
=> "select Name, Contract__r.Name from Account where id = 1"

# Add a limit
builder.fields(['Name', 'Contract__r.Name'])
       .from('Account')
       .where('id = 1')
       .limit(1)

builder.query
=> "select Name, Contract__r.Name from Account where id = 1 limit 1"

Select query with subquery

builder.fields(['Name', 'Contract__r.Name'])
       .add_subquery(
         table: 'Account.Quotes',
         fields: ['Quotes.Name', 'Quotes.id']
       )
       .from('Account')
       .where('id = 1')

builder.query
=> "select Name, Contract__r.Name, (select Quotes.Name, Quotes.id from Account.Quotes) from Account where id = 1"

Select query with multiple subqueries

builder.fields(['Name', 'Contract__r.Name'])
       .add_subquery(
         table: 'Account.Quotes',
         fields: ['Quotes.Name', 'Quotes.id']
       )
       .add_subquery(
         table: 'Account.Contacts',
         fields: ['Contacts.Name']
       )
       .from('Account')
       .where('id = 1')

builder.query
=> "select Name, Contract__r.Name, (select Quotes.Name, Quotes.id from Account.Quotes), (select Contacts.Name from Account.Contacts) from Account where id = 1"

Queries can be added one at a time, instead of chaining

builder.fields(['Name', 'Contract__r.Name'])

builder.add_subquery(
         table: 'Account.Quotes',
         fields: ['Quotes.Name', 'Quotes.id']
       )

builder.from('Account')

builder.where('id = 1')

builder.query
=> "select Name, Contract__r.Name, (select Quotes.Name, Quotes.id from Account.Quotes) from Account where id = 1"

Reset the query and create another one with the same object

builder.fields(['Name', 'Contract__r.Name'])

builder.add_subquery(
         table: 'Account.Quotes',
         fields: ['Quotes.Name', 'Quotes.id']
       )

builder.from('Account')

builder.where('id = 1')

builder.query
=> "select Name, Contract__r.Name, (select Quotes.Name, Quotes.id from Account.Quotes) from Account where id = 1"

builder.clean

builder.fields(['Name', 'Contract__r.Name'])
       .from('Account')
       .where('id = 1')

builder.query
=> "select Name, Contract__r.Name from Account where id = 1"

FAQs

Package last updated on 10 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.