|
1 | | -The syntax used by ArgusDB is an extension of SQL and inspired by [XTDB](https://xtdb.com/). |
2 | | -Examples of syntax for different use cases are given below. |
| 1 | +# Query Language Specification |
3 | 2 |
|
4 | | -## Insertion |
| 3 | +ArgusDB supports a SQL-like query language optimized for manipulating and retrieving JSON documents. |
| 4 | + |
| 5 | +## Data Model |
| 6 | + |
| 7 | +The database consists of collections of JSON documents. Each document is a semi-structured object with nested fields, arrays, and values. |
| 8 | + |
| 9 | +## Statements |
| 10 | + |
| 11 | +### INSERT |
| 12 | + |
| 13 | +The `INSERT` statement is used to add new documents to a collection. |
| 14 | + |
| 15 | +**Syntax:** |
| 16 | + |
| 17 | +```sql |
| 18 | +INSERT INTO <collection_name> |
| 19 | +RECORDS <json_object> [, <json_object> ...] |
| 20 | +``` |
| 21 | + |
| 22 | +**Parameters:** |
| 23 | + |
| 24 | +* `collection_name`: The name of the collection to insert into. |
| 25 | +* `json_object`: A standard JSON object literal representing the document. Keys in the JSON object usually do not require quotes if they are simple identifiers, but standard JSON requires quotes. The parser should support standard JSON syntax. |
| 26 | + |
| 27 | +**Example:** |
5 | 28 |
|
6 | 29 | ```sql |
7 | 30 | INSERT INTO people |
8 | | -RECORDS {_id: 6, |
9 | | - name: 'fred', |
10 | | - info: {contact: [{loc: 'home', |
11 | | - tel: '123'}, |
12 | | - {loc: 'work', |
13 | | - tel: '456', |
14 | | - registered: DATE '2024-01-01'}]}} |
| 31 | +RECORDS { |
| 32 | + "name": "Alice", |
| 33 | + "age": 30, |
| 34 | + "address": {"city": "Paris", "zip": "75001"} |
| 35 | +} |
15 | 36 | ``` |
16 | 37 |
|
17 | | -## Querying |
| 38 | +### SELECT |
| 39 | + |
| 40 | +The `SELECT` statement retrieves data from a collection, allowing for filtering, projection, and pagination. |
| 41 | + |
| 42 | +**Syntax:** |
| 43 | + |
| 44 | +```sql |
| 45 | +SELECT <expression_list> |
| 46 | +FROM <collection_name> |
| 47 | +[WHERE <predicate>] |
| 48 | +[LIMIT <integer>] |
| 49 | +[OFFSET <integer>] |
| 50 | +``` |
| 51 | + |
| 52 | +#### Clauses |
| 53 | + |
| 54 | +* **SELECT**: Specifies the fields or expressions to return in the result set. |
| 55 | +* **FROM**: Specifies the source collection to query. |
| 56 | +* **WHERE**: Filters documents based on a boolean predicate. Only documents for which the predicate evaluates to `TRUE` are included in the result. |
| 57 | +* **LIMIT**: Restricts the maximum number of documents returned. |
| 58 | +* **OFFSET**: Skips a specified number of documents before returning results. |
| 59 | + |
| 60 | +#### Expressions and Operators |
| 61 | + |
| 62 | +The language supports various expressions to interact with JSON data: |
| 63 | + |
| 64 | +* **Field Access**: |
| 65 | + * Dot notation: `info.contact` accesses the `contact` field within the `info` object. |
| 66 | + * Array Indexing: `contact[0]` accesses the first element of the `contact` array. |
| 67 | +* **Literals**: |
| 68 | + * Strings: `'value'` (single quotes) or `"value"` (double quotes) |
| 69 | + * Numbers: `123`, `45.67` |
| 70 | + * Booleans: `TRUE`, `FALSE` |
| 71 | + * Null: `NULL` |
| 72 | +* **Comparison Operators**: |
| 73 | + * `=`: Equality |
| 74 | + * `!=` or `<>`: Inequality |
| 75 | + * `<`, `<=`: Less than, Less than or equal |
| 76 | + * `>`, `>=`: Greater than, Greater than or equal |
| 77 | +* **Logical Operators**: |
| 78 | + * `AND`: Logical conjunction |
| 79 | + * `OR`: Logical disjunction |
| 80 | + * `NOT`: Logical negation |
| 81 | + |
| 82 | +**Example:** |
18 | 83 |
|
19 | 84 | ```sql |
20 | | -SELECT (people.info).contact[2].tel |
| 85 | +SELECT name, info.contact[0].tel |
21 | 86 | FROM people |
22 | | -WHERE people.name = 'fred' |
| 87 | +WHERE age >= 21 AND active = TRUE |
| 88 | +LIMIT 10 |
| 89 | +OFFSET 5 |
23 | 90 | ``` |
0 commit comments