A zero-dependency, TypeScript/JavaScript parser for SOQL (Salesforce Object Query Language) that converts query strings into structured objects.
- π Complete SOQL Support: Parses all major SOQL clauses (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, OFFSET)
- π¦ TypeScript First: Fully typed API with comprehensive type definitions
- π Zero Dependencies: Lightweight with no external runtime dependencies
- π Streaming Support: Can parse queries incrementally from streams
- π― Accurate: Handles complex queries including subqueries, aggregate functions, and nested field paths
- π‘οΈ Error Handling: Provides detailed error messages for malformed queries
npm install soql-parser-liteOr with pnpm:
pnpm add soql-parser-liteOr with yarn:
yarn add soql-parser-liteimport { parseSoqlQuery } from 'soql-parser-lite'
// Parse a simple query
const query = parseSoqlQuery(
'SELECT Id, Name FROM Account WHERE Status = "Active" LIMIT 10',
)
console.log(JSON.stringify(query, null, 2))
// Output:
/*
{
"select": {
"items": [
{
"item": {
"name": "Id"
}
},
{
"item": {
"name": "Name"
}
}
]
},
"from": {
"objects": [
{
"name": "Account"
}
]
},
"where": {
"expr": {
"left": {
"name": "Status"
},
"right": {
"value": "Active"
}
}
},
"limit": 10
}
*/import { parseSoqlQuery } from 'soql-parser-lite'
const query = parseSoqlQuery('SELECT Id, Name, Email FROM Contact')const query = parseSoqlQuery(
'SELECT Id, Name FROM Account WHERE Status = "Active" AND Revenue > 1000000',
)const query = parseSoqlQuery(
'SELECT COUNT(Id) cnt, MAX(Amount) maxAmount FROM Opportunity GROUP BY StageName',
)const query = parseSoqlQuery(
'SELECT Name, (SELECT LastName FROM Contacts) FROM Account',
)const query = parseSoqlQuery('SELECT Id FROM Case WHERE CreatedDate = TODAY')const query = parseSoqlQuery(
'SELECT Id, Name, CreatedDate FROM Account ORDER BY CreatedDate DESC LIMIT 100 OFFSET 50',
)const query = parseSoqlQuery(
'SELECT Id, Account.Name, Account.Owner.Email FROM Contact',
)- β SELECT clause with fields, aggregate functions, and subqueries
- β FROM clause with multiple objects and aliases
- β WHERE clause with comparison and logical operators
- β GROUP BY clause
- β HAVING clause
- β ORDER BY clause with ASC/DESC
- β LIMIT clause
- β OFFSET clause
- β Date literals (TODAY, YESTERDAY, LAST_N_DAYS, etc.)
- β Bind variables (:variable)
- β IN operator with arrays and subqueries
- β Relationship field paths (Account.Owner.Name)
- β Aggregate functions (COUNT, MAX, MIN, SUM, AVG)
- β Field aliases
# Install dependencies
pnpm install
# Build the project
pnpm run compile
# Run tests
pnpm test
# Format code
pnpm run format
# Generate documentation
pnpm run docs:genContributions are welcome! Please see CONTRIBUTING.md for details.
MIT Β© Jacob Shirley
- π Documentation
- π¬ GitHub Issues
- π Examples