1.0.3 • Published 1 year ago

sf-mobile-smartquery v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Salesforce Mobile Smart Query factory

JS Library to securely generate Smart Queries used by Salesforce Mobile SDK. This library prevents SQL injections. It can be used in React Native or Cordova apps.

Why Use This Library

When Salesforce SmartSQL Queries has to be dynamically generated based on user input, it is very easy to introduce SQL injections. This library parses all inputs and generates a query that can be consumed by Salesforce SmartStore

This library allows you to generate most basic SmartSQL Queries. This library does not support the creation of comples queries (yet). For more examples please checkout the test scripts

Installation

Install using npm or yarn

npm install sf-mobile-smartquery

or

yarn add sf-mobile-smartquery

Usage

import {SmartQuery} from 'sf-mobile-smartquery'; 

// Regular usage
const q = new SmartQuery();
q.select(['_soup']);
q.from('Account');
q.run() // output: SELECT {Account:_soup} from {Account}

// Chaining functions
const q = new SmartQuery();
q.select(['Id', 'Name'])
.from('Account')
.where('Id', '=', `'001XXXXXXXXXXX'`)
.run() // output: SELECT {Account:Id}, {Account:Name} FROM {Account} WHERE {Account:Id} = '001XXXXXXXXXXX'

// Capturing errors
import {SmartQuery, EXCEPTIONS} from 'sf-mobile-smartquery';
try {
  const q = new SmartQuery()
  q.select(['_soup']);
  q.from(`Account' `);  // Spaces and quotes are not allowed. An exception is thrown
  const query = q.run();
} catch (e) {
  console.log(e) // Error instance is thrown
}

More examples can be found in the test scripts