JS/SQL Query Language


Documents are accessed using JS/SQL (JavaScript/SQL) statements executed against Clusterpoint. JS/SQL is based on the idea that instead of defining a proprietary query language we access objects using just the JavaScript, which is organised in a SQL-resembling structure. From the opposite angle it looks like SQL statements with arbitrary JavaScript embedded into them. This allows powerful, extensible transformations done on the data right in the database.

Syntax examples below

Data Manipulation

    INSERT 
            INSERT without specifying unique key 
            INSERT with defining unique key 
    UPDATE 
    UPSERT 
    REPLACE 
    DELETE 
    ACID-Compliant Transactions
    Date and Time


Data Definition API

    CREATE COLLECTION 
    EDIT COLLECTION 
    REINDEX COLLECTION 
    CLEAR COLLECTION 
    DROP COLLECTION 
    DROP DATABASE 
    DESCRIBE COLLECTION 
    LIST DATABASES 
    LIST COLLECTIONS 

Querying

    SELECT 
    SELECT .. WHERE 
            Equality and Comparisons 
            Fields containing Date values 
            Boolean Expressions 
            Arithmetic, String & Other Operations 
            Functions 
            Full Text Search 
                    Single Term 
                    Multiple Terms 
                    Phrase 
                    Wildcard Patterns 
                    Specsymbols 
                    Ignored Search Terms 
                    Boosted Search Terms 
                    Stemming 
                    Proximity Search 
                    Fuzzy search 
            Search in simple arrays 
            Search in complex arrays 
            Snippet and Highlight 
            List Words 
            Alternatives 
            Geospatial search 
                    Circle 
                    Rectangle 
                    Polygon 
                    Geo example of SELECT with WHERE 
    SELECT .. ORDER BY 
            Relevance Ranking 
            Distance in Geographic Coordinates 
    SELECT .. GROUP BY
            Array Aggregation 
            Custom Aggregators 
            GROUP_KEY() function 
    JOINS 
            JOIN Syntax 
            EMBED function 


JS/SQL Syntax

Clusterpoint uses JS/SQL as its query language, which means that you can actually use arbitrary JavaScript code in SELECT, WHERE and ORDER BY clauses, or to define functions before the SELECT clause.

Here is the general query structure showing where and how JavaScript can be used within the query:

[js_code]
SELECT select_column [, select_column ...]
FROM collection_name
[ (INNER | LEFT) JOIN collection_name [, collection_name ...] ON join_condition [, join_condition ...] ]
[ WHERE js_code ]
[ GROUP BY js_code [, js_code ...] ]
[ ORDER BY js_code [ASC | DESC] [, js_code [ASC | DESC] ...] ]
[ LIMIT [offset ,] row_count ]

select_column ::= js_code [AS alias]
collection_name ::= tag_name [AS tag_name]
alias ::= tag_name | "{valid JSON string}"
tag_name ::= {[a-zA-Z0-9\-_.]}
js_code ::= tag_name | {valid javascript that will get executed, last line will be return value}