Git Product home page Git Product logo

soql-builder's Introduction

Salesforce SOQL Builder

SOQL builder that simplifies the process of constructing complex queries to retrieve data from Salesforce databases.

Installation

Ensure you have composer installed, then run the following command:

composer require lyonstahl/soql-builder

That will fetch the library and its dependencies inside your vendor folder. Then you need to use the relevant class, for example:

use LyonStahl\SoqlBuilder\SoqlBuilder;

Features

  • Select
  • Conditionals (where)
  • Conditionals for date values
  • Grouped conditional statements
  • Where in
  • Where not in
  • Limit
  • Offset
  • Order By

Usage

Builder has two entry points for comfortable static usage: SoqlBuilder::select() and SoqlBuilder::from(). Both methods return a SoqlBuilder instance.
In any other context, you must call addSelect() and setFrom() to add the "SELECT" and "FROM" statements. See examples below.

SoqlBuilder::select(['Id', 'Name', 'created_at'])
    ->setFrom('Account')
    ->where('Name', '=', 'Test')
    ->limit(20)
    ->orderBy('created_at', 'DESC')
    ->toSoql();

> SELECT Id, Name, created_at FROM Account WHERE Name = 'Test' ORDER BY created_at DESC LIMIT 20

SoqlBuilder::from('Account')
    ->addSelect(['Id', 'Name'])
    ->where('Name', '=', 'Test')
    ->orWhere('Name', '=', 'Testing')
    ->toSoql();

> SELECT Id, Name FROM Account WHERE Name = 'Test' OR Name = 'Testing'

SoqlBuilder::select(['Id', 'Name'])
    ->setFrom('Account')
    ->startWhere()
    ->where('Name', '=', 'Test')
    ->where('Testing__c', '=', true)
    ->endWhere()
    ->orWhere('Email__c', '=', '[email protected]')
    ->toSoql();

> SELECT Id, Name FROM Account WHERE (Name = 'Test' AND Testing__c = true) OR Email__c = '[email protected]'

Requirements

Running for development with Docker

We have included a Dockerfile to make it easy to run the tests and debug the code. You must have Docker installed. The following commands will build the image and run the container:

  1. docker build -t lyonstahl/soql-builder --build-arg PHP_VERSION=8 .
  2. docker run -it --rm -v ${PWD}:/var/www/soql lyonstahl/soql-builder sh

Debugging with XDebug in VSCode

Docker image is configured with XDebug. To debug the code with VSCode, follow these steps:

  1. Install the PHP Debug extension in VSCode

  2. Add a new PHP Debug configuration in VSCode:

    {
        "name": "XDebug Docker",
        "type": "php",
        "request": "launch",
        "port": 9003,
        "pathMappings": {
            "/var/www/soql/": "${workspaceRoot}/"
        }
    }
    
  3. docker run -it --rm -v ${PWD}:/var/www/soql --add-host host.docker.internal:host-gateway lyonstahl/soql-builder sh

  4. Start debugging in VSCode with the 'XDebug Docker' configuration.

Testing

This library ships with PHPUnit for development. Composer file has been configured with some scripts, run the following command to run the tests:

composer test

soql-builder's People

Contributors

mihasicehcek avatar alekseytatarynov avatar paxanddos avatar faridkoch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.