Skip to content

Commit

Permalink
Nebula query engine
Browse files Browse the repository at this point in the history
The Nebula project (https://github.com/jongpie/NebulaFramework) has added a lot of new features for dynamic querying, but it's currently dependent on the rest of the Nebula framework. The query engine from Nebula has been ported so that it's a freestanding project that can be deployed without the rest of the framework.
  • Loading branch information
jongpie authored Dec 12, 2017
1 parent 92accfa commit 963410a
Show file tree
Hide file tree
Showing 81 changed files with 3,095 additions and 1,360 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ node_js:
install:
- npm install -g jsforce-metadata-tools
script:
- jsforce-deploy --checkOnly -u $DEPLOYMENT_USERNAME -p $DEPLOYMENT_PASSWORD$DEPLOYMENT_TOKEN -D $TRAVIS_BUILD_DIR/src -l $DEPLOYMENT_LOGIN_URL --rollbackOnError true --testLevel $DEPLOYMENT_TEST_LEVEL --pollTimeout $POLL_TIMEOUT --pollInterval $POLL_INTERVAL--verbose
- jsforce-deploy --checkOnly -u $DEPLOYMENT_USERNAME -p $DEPLOYMENT_PASSWORD$DEPLOYMENT_TOKEN -D $TRAVIS_BUILD_DIR/src -l $DEPLOYMENT_LOGIN_URL --rollbackOnError true --testLevel $DEPLOYMENT_TEST_LEVEL --pollTimeout $POLL_TIMEOUT --pollInterval $POLL_INTERVAL--verbose
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# Apex Query Generator
<a target="_blank" href="https://githubsfdeploy.herokuapp.com?owner=jongpie&repo=ApexQueryGenerator">
<a target="_blank" href="https://githubsfdeploy.herokuapp.com">
<img alt="Deploy to Salesforce"
src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/src/main/webapp/resources/img/deploy.png">
</a>

## Issue
--Coming soon--
## Overview
This is an freestanding version of the [Nebula framework's](https://github.com/jongpie/NebulaFramework/) query engine - it has been updated to remove any dependencies on the rest of the Nebula framework.

## Goals
The overall goal of the project is to help auto-generate dynamic SOQL for commonly used queries
* Provide a structure to centralise frequently used queries for each SObject
* Provide a configurable way to change the query fields, while still preventing accidental deletion of fields being used
* Provide a way to create a WHERE statement as a string in Apex, while still preventing accidental deletion of fields being used

## Implementation
--Coming soon--

### Example Implementation: LeadQueryRepository.cls
## Features
The overall goal of the project is to generate dynamic SOQL & SOSL queries. Features currently include
* Leverage field-level security to dynamically include fields
* Dynamically include filter conditions (not possible with standard SOQL/SOSL)
* Retain Salesforce's compilation-time errors for invalid fields while still taking advantage of dynamic queries - this helps avoid issues with deleting fields, misspelled field names, etc that can occur when working with strings and dynamic queries
* Support for nearly all SOQL & SOSL features & keywords, including date literals, aggregate results and more
* Easy-to-use query caching
118 changes: 0 additions & 118 deletions src/classes/AccountRepository_Tests.cls

This file was deleted.

108 changes: 108 additions & 0 deletions src/classes/CollectionUtils.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*************************************************************************************************
* This file is part of the Nebula Framework project, released under the MIT License. *
* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
*************************************************************************************************/

/**
*
* @group Utils
*
* @description A utility class to help with dealing with collections (lists, sets & maps)
*
*/
public without sharing class CollectionUtils {

/**
* @description Returns the last item in a list
* @param listOfItems the list to check
* @return The last Object in the provided list
* @example
* List<String> myList = new List<String>{'A', B', 'C'};
* String lastItem = CollectionUtils.getLastItem(myList);
* System.assertEquals('C', lastItem);
*/
public static Object getLastItem(List<Object> listOfItems) {
Integer indexOfItem = listOfItems.size() - 1;
return listOfItems[indexOfItem];
}

/**
* @description Removes the last item in the provided list & returns the item
* @param listOfItems the list to check
* @return The last Object in the provided list
* @example
* List<String> myList = new List<String>{'A', B', 'C'};
* System.assertEquals(3, myList.size());
* String lastItem = CollectionUtils.getLastItem(myList);
* System.assertEquals('C', lastItem);
* System.assertEquals(2, myList.size());
*/
public static Object pop(List<Object> listToSplice) {
return splice(listToSplice, listToSplice.size() - 1);
}

/**
* @description Removes the item in the specified index from the provided list & returns the item
* @param listOfItems The list to check
* @param indexOfItem The index of the item to remove
* @return The Object at the specified index
* @example
* List<String> myList = new List<String>{'A', B', 'C'};
* System.assertEquals(3, myList.size());
* String itemToRemove = CollectionUtils.splice(myList, 1);
* System.assertEquals('B', itemToRemove);
* System.assertEquals(2, myList.size());
*/
public static Object splice(List<Object> listToSplice, Integer indexOfItem) {
Object itemToRemove = listToSplice[indexOfItem];
listToSplice.remove(indexOfItem);
return itemToRemove;
}

/**
* @description Determines if the provided input is a type of collection (list, set or map)
* @param input The Object to check
* @return true if the item is a type of collection, otherwise returns false
* @example
* List<String> myList = new List<String>{'A', 'B', 'C'};
* System.assert(CollectionUtils.isCollection(myList));
*/
public static Boolean isCollection(Object input) {
return isList(input) || isSet(input) || isMap(input);
}

public static Boolean isList(Object input) {
// If we can cast the object to a list of objects, then it's a list
try {
Object convertedInput = (List<Object>)input;
return true;
} catch(System.TypeException ex) {
return false;
}
}

public static Boolean isSet(Object input) {
// We can't cast the object to a set of objects
// But if we try to cast it to a list of objects & it's a set,
// then a TypeException is thrown so we know it's a set
try {
Object convertedInput = (List<Object>)input;
return false;
} catch(System.TypeException ex) {
return ex.getMessage().contains('Set<');
}
}

public static Boolean isMap(Object input) {
// We can't cast the object to a map of objects
// But if we try to cast it to a list of objects & it's a map,
// then a TypeException is thrown so we know it's a map
try {
Object convertedInput = (List<Object>)input;
return false;
} catch(System.TypeException ex) {
return ex.getMessage().contains('Map<');
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>38.0</apiVersion>
<apiVersion>40.0</apiVersion>
<status>Active</status>
</ApexClass>
Loading

0 comments on commit 963410a

Please sign in to comment.