soql-parse

1.1.1 • Public • Published

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
    }
}

Readme

Keywords

none

Package Sidebar

Install

npm i soql-parse

Weekly Downloads

577

Version

1.1.1

License

MIT

Unpacked Size

685 kB

Total Files

64

Last publish

Collaborators

  • stomita