Skip to content

Parse SOQL string to abstract syntax tree expression in JavaScript

Notifications You must be signed in to change notification settings

stomita/soql-parse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

soql-parse

Parse SOQL query string to abstract syntax tree in JavaScript.

Build Status

Online Demo

https://stomita.github.io/soql-parse/

Install

npm install soql-parse

Usage

import { parse } from 'soql-parse';

const soql = `
Select Id, Name, toLabel(Type) from Account
WHERE Name like 'A%' and Type IN ('Partner', 'Customer')
ORDER by CreatedDate DESC
LIMIT 10
`;

const parsed = parse(soql);
console.log(parsed);

Result:

{
    "type": "Query",
    "fields": [
        {
            "type": "FieldReference",
            "path": [
                "Id"
            ]
        },
        {
            "type": "FieldReference",
            "path": [
                "Name"
            ]
        },
        {
            "type": "FunctionCall",
            "name": "toLabel",
            "arguments": [
                {
                    "type": "FieldReference",
                    "path": [
                        "Type"
                    ]
                }
            ]
        }
    ],
    "object": {
        "type": "ObjectReference",
        "name": "Account"
    },
    "condition": {
        "type": "LogicalCondition",
        "operator": "AND",
        "left": {
            "type": "ComparisonCondition",
            "field": {
                "type": "FieldReference",
                "path": [
                    "Name"
                ]
            },
            "operator": "LIKE",
            "value": {
                "type": "string",
                "value": "A%"
            }
        },
        "right": {
            "type": "ComparisonCondition",
            "field": {
                "type": "FieldReference",
                "path": [
                    "Type"
                ]
            },
            "operator": "IN",
            "value": {
                "type": "list",
                "values": [
                    {
                        "type": "string",
                        "value": "Partner"
                    },
                    {
                        "type": "string",
                        "value": "Customer"
                    }
                ]
            }
        }
    },
    "sort": [
        {
            "field": {
                "type": "FieldReference",
                "path": [
                    "CreatedDate"
                ]
            },
            "direction": "DESC"
        }
    ],
    "limit": {
        "type": "number",
        "value": 10
    }
}

About

Parse SOQL string to abstract syntax tree expression in JavaScript

Resources

Stars

Watchers

Forks

Packages

No packages published