Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ai-prompts/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Our documentation for the `noql` syntax is stored in organised and separate Markdown files at `/docs/docs/sql-syntax/` folder, we also have a collection of tests in the `/test/` folder that show how to use the library.

All of the functions that are listed as the return value from the function call `functionMappings()` located in the `/lib/MongoFunctions.js` file should be documented in the Markdown files referred to above.

Please can you update the documentation in the `/docs/docs/sql-syntax/` folder, so that any functions which are missing are documented. The newly generated documents should be documented in the same way as the existing markdown files are. Please don't create any new files, I want you to update the existing ones. For each of the new functions you are documenting, please put it in the most appropriate of the existing files. The only exception to this is the `pivot` and `unpivot` operations which should be in a new file called `pivot-unpivot.md`
46 changes: 25 additions & 21 deletions docs/docs/sql-syntax/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ NoQL uses sub-selects with a FROM array field to query array fields in collectio

```sql
SELECT
(SELECT * FROM Rentals WHERE staffId=2) AS t
FROM
(SELECT * FROM Rentals WHERE staffId=2) AS t
FROM
`customers`
```

Expand All @@ -20,9 +20,9 @@ Using '$$ROOT' in sub select promotes the field to the root value of the array
???+ example "Using '$$ROOT' in sub select"

```sql
SELECT
(SELECT filmId AS '$$ROOT' FROM Rentals WHERE staffId=2) AS t
FROM
SELECT
(SELECT filmId AS '$$ROOT' FROM Rentals WHERE staffId=2) AS t
FROM
`customers`
```

Expand All @@ -31,9 +31,9 @@ Slicing the array is supported by limit and offset in queries
???+ example "Slicing an array with limit and offset"

```sql
SELECT
(SELECT * FROM Rentals WHERE staffId=2 LIMIT 10 OFFSET 5) AS t
FROM
SELECT
(SELECT * FROM Rentals WHERE staffId=2 LIMIT 10 OFFSET 5) AS t
FROM
`customers`
```

Expand All @@ -46,15 +46,15 @@ Sorting Arrays is supported in MongoDB 5.2+ and NoQL
(SELECT * FROM Rentals ORDER BY id DESC) AS totalRentals
FROM customers
```

!!! warning "Aggregation functions are not supported in a sub select"
Aggregation functions are not supported in a sub select. For example, the following won't work
```sql
Aggregation functions are not supported in a sub select. For example, the following won't work
`sql
--Wont'Work
SELECT id,
(SELECT count(*) AS count FROM Rentals) AS totalRentals
FROM customers
```
`

## UNWIND Function

Expand All @@ -65,28 +65,29 @@ NoQL has a high level unwind function that will unwind array fields. For Joins,
???+ example "UNWIND in SELECT"

```sql
SELECT
SELECT
field1,
UNWIND(arrFld) as arrFld
FROM
test
```

???+ example "Complex UNWIND"

```sql
SELECT
SELECT
MERGE_OBJECTS(
(SELECT
(SELECT
t.CustomerID
,t.Name
)
,t.Rental
) AS `$$ROOT`
FROM
(SELECT
) AS `$$ROOT`
FROM
(SELECT
id AS CustomerID
,`First Name` AS Name
,UNWIND(Rentals) AS Rental
,UNWIND(Rentals) AS Rental
FROM customers) AS t
```

Expand Down Expand Up @@ -161,6 +162,7 @@ Converts the array to an object.
ARRAY_TO_OBJECT(OBJECT_TO_ARRAY(`Address`)) AS test
FROM `customers`;
```

### CONCAT_ARRAYS

`CONCAT_ARRAYS(array expr,...)`
Expand All @@ -174,6 +176,7 @@ Concatenate the provided list of arrays.
CONCAT_ARRAYS((SELECT `Film Title` AS ‘$$ROOT’ FROM `Rentals`), ARRAY_RANGE(0,10,2)) AS test
FROM `customers`;
```

### FIRST_IN_ARRAY

`FIRST_IN_ARRAY(array expr)`
Expand Down Expand Up @@ -229,6 +232,7 @@ Returns the last element of an array.
LAST_IN_ARRAY(`Rentals`) AS test
FROM `customers`;
```

### OBJECT_TO_ARRAY

`OBJECT_TO_ARRAY(expr)`
Expand Down Expand Up @@ -362,8 +366,8 @@ Sums the values in an array given an array field or sub-select and the field to
`First Name`,
`Last Name`,
SUM_ARRAY(
(SELECT
SUM_ARRAY(`Payments`, ‘Amount’) AS total
(SELECT
SUM_ARRAY(`Payments`, ‘Amount’) AS total
FROM `Rentals`), ‘total’) AS t
FROM customers;
```
Expand Down
Loading
Loading