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
2 changes: 1 addition & 1 deletion docs/docs/javascripts/noql/index.js

Large diffs are not rendered by default.

32 changes: 28 additions & 4 deletions docs/docs/javascripts/playground/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,56 @@ playgroundButton.onclick = function () {
let nodeQuery = '';
let errorMessage = '';

let optimizedPipeline = null;

document.getElementById('playground-error-container').style.display =
'none';
document.getElementById('playground-output-container').style.display =
'none';

let dbDialect = 'postgresql';
if (document.getElementById('dialect-mysql').checked) {
dbDialect = 'mysql';
}
const inputSql = editor.session.getValue();
try {
const unwindJoins = !!document.getElementById('unwind-joins').checked;
const optimizeJoins =
!!document.getElementById('optimize-joins').checked;

if (document.getElementById('force-aggregate').checked) {
noqlOutput = SqlToMongo.makeMongoAggregate(inputSql, {
database: dbDialect,
unwindJoins: unwindJoins,
optimizeJoins: optimizeJoins,
});
} else {
noqlOutput = SqlToMongo.parseSQL(inputSql, {database: dbDialect});
noqlOutput = SqlToMongo.parseSQL(inputSql, {
database: dbDialect,
unwindJoins: unwindJoins,
optimizeJoins: optimizeJoins,
});
}

if (noqlOutput.type === 'aggregate' && noqlOutput.pipeline) {
optimizedPipeline = SqlToMongo.optimizeMongoAggregate(
noqlOutput.pipeline,
{}
);
}

shellQuery = constructShellQuery(noqlOutput);
nodeQuery = constructNodeQuery(noqlOutput);

document.getElementById('playground-noql-result').textContent =
JSON.stringify(noqlOutput, null, 4);
document.getElementById('playground-mongo-result').textContent =
shellQuery;
document.getElementById('playground-node-result').textContent =
nodeQuery;
document.getElementById(
'playground-noql-optimized-result'
).textContent = optimizedPipeline
? JSON.stringify(optimizedPipeline, null, 4)
: '';

document.getElementById('playground-output-container').style.display =
'block';
document.getElementById('playground-output-container').scrollIntoView({
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/overrides/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ <h2>
src="assets/sql-database-generic-svgrepo-com.svg"
width="36px"
/>
mySQL or Postgres
Postgres Syntax
</h2>
<p>
Write in mySQL or Postgres dialects. Use the language you already
Use the language you already
know to generate MongoDB queries. You don't need to figure out Mongo
query syntax to use Mongo!
</p>
Expand Down
30 changes: 21 additions & 9 deletions docs/docs/playground/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ Enter a SQL statement below to see NoQL's output, as well as the equivalent Mong

<div>
<div class="admonition example">
<p class="admonition-title">Choose your dialect:
<input type="radio" id="dialect-postgres" name="dialect" value="postgresql" checked="checked">
  <label for="postgres">Postgresql</label>
<input type="radio" id="dialect-mysql" name="dialect" value="mysql">
  <label for="mysql">mySQL</label>
&nbsp;|&nbsp;
<input type="checkbox" id="force-aggregate" name="force-aggregate">
<label for="force-aggregate">Alway create an aggregate</label>
</p>
<div style="display: flex; align-items: center; gap:1rem;margin-bottom: 0.5rem;margin-top:0.5rem">
<div style="display: flex; align-items: center; gap:0.25rem;">
<input type="checkbox" id="force-aggregate" name="force-aggregate">
<label for="force-aggregate">Always create an aggregate</label>
</div>
<div style="display: flex; align-items: center; gap:0.25rem;">
<input type="checkbox" id="unwind-joins" name="unwind-joins">
<label for="unwind-joins">Automatically Unwind Joins</label>
</div>
<div style="display: flex; align-items: center; gap:0.25rem;">
<input type="checkbox" id="optimize-joins" name="unwind-joins">
<label for="optimize-joins">Optimize Joins</label>
</div>
</div>
<div class="playground-code-input" id="playground-sql-input">SELECT * FROM rockets</div>
</div>
<button class="md-button md-button--primary" id="submit-sql">Convert</button>
Expand All @@ -42,10 +47,12 @@ Enter a SQL statement below to see NoQL's output, as well as the equivalent Mong
<input checked="checked" id="mongo-shell-output" name="__tabbed_5" type="radio">
<input id="node-code-output" name="__tabbed_5" type="radio">
<input id="noql-output" name="__tabbed_5" type="radio">
<input id="noql-optimized-output" name="__tabbed_5" type="radio">
<div class="tabbed-labels tabbed-labels--linked">
<label for="mongo-shell-output">Mongo Shell Query</label>
<label for="node-code-output">Node.js Code</label>
<label for="noql-output">NoQL Output</label>
<label for="noql-optimized-output">Optimized Pipeline</label>
</div>
<div class="tabbed-content">
<div class="tabbed-block">
Expand All @@ -63,6 +70,11 @@ Enter a SQL statement below to see NoQL's output, as well as the equivalent Mong
<pre><code class="playground-code-output language-javascript hljs" id="playground-noql-result"></code></pre>
</div>
</div>
<div class="tabbed-block">
<div class="language-javascript highlight">
<pre><code class="playground-code-output language-javascript hljs" id="playground-noql-optimized-result"></code></pre>
</div>
</div>
</div>
<div class="tabbed-control tabbed-control--prev" hidden=""><button class="tabbed-button" tabindex="-1"
aria-hidden="true"></button></div>
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/sql-syntax/aggregates.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Returns the distinct count of a specific field in the given group.

```sql
SELECT
COUNT(DISTINCT `Address.Town`) AS countVal
COUNT(DISTINCT "Address.Town") AS countVal
,`Address.City` AS City
FROM
`customers`
Expand Down
42 changes: 28 additions & 14 deletions docs/docs/sql-syntax/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Using '$$ROOT' in sub select promotes the field to the root value of the array

```sql
SELECT
(SELECT filmId AS '$$ROOT' FROM Rentals WHERE staffId=2) AS t
(SELECT filmId AS `$$ROOT` FROM Rentals WHERE staffId=2) AS t
FROM
`customers`
```
Expand Down Expand Up @@ -103,10 +103,24 @@ Returns true when all elements in the array are true.

```sql
SELECT id,
(CASE WHEN ALL_ELEMENTS_TRUE(Rentals) THEN Yes ELSE ‘No’ END) AS test
(CASE WHEN ALL_ELEMENTS_TRUE(Rentals) THEN 'Yes' ELSE 'No' END) AS test
FROM `customers`;
```

### JOIN

`JOIN(array expr, delimiter)`

Joins all values into a string.

???+ example "Example `JOIN` usage"

```sql
SELECT id,
JOIN((SELECT Name FROM Rentals),',') AS RentalNames
FROM customers;
```

### ANY_ELEMENT_TRUE

`ANY_ELEMENT_TRUE(array expr)`
Expand All @@ -117,7 +131,7 @@ Returns true when any element in the array is true.

```sql
SELECT id,
(CASE WHEN ANY_ELEMENT_TRUE(Rentals) THEN Yes ELSE ‘No’ END) AS test
(CASE WHEN ANY_ELEMENT_TRUE(Rentals) THEN 'Yes' ELSE 'No' END) AS test
FROM `customers`;
```

Expand Down Expand Up @@ -173,7 +187,7 @@ Concatenate the provided list of arrays.

```sql
SELECT id,
CONCAT_ARRAYS((SELECT `Film Title` AS $$ROOT FROM `Rentals`), ARRAY_RANGE(0,10,2)) AS test
CONCAT_ARRAYS((SELECT `Film Title` AS `$$ROOT` FROM `Rentals`), ARRAY_RANGE(0,10,2)) AS test
FROM `customers`;
```

Expand Down Expand Up @@ -201,7 +215,7 @@ Returns the index of the value in the array.

```sql
SELECT id,
INDEXOF_ARRAY((SELECT `Film Title` AS $$ROOT FROM `Rentals`),5) AS test
INDEXOF_ARRAY((SELECT `Film Title` AS `$$ROOT` FROM `Rentals`),5) AS test
FROM `customers`;
```

Expand All @@ -215,7 +229,7 @@ Returns true when the field is an array.

```sql
SELECT id,
(CASE WHEN IS_ARRAY(Rentals) THEN Yes ELSE ‘No’ END) AS test
(CASE WHEN IS_ARRAY(Rentals) THEN 'Yes' ELSE 'No' END) AS test
FROM `customers`;
```

Expand Down Expand Up @@ -271,7 +285,7 @@ Returns an array as the difference of the provided arrays.

```sql
SELECT id,
SET_DIFFERENCE((SELECT `Film Title` AS $$ROOT FROM `Rentals`), PARSE_JSON([ 1,2,3,4])) AS test
SET_DIFFERENCE((SELECT `Film Title` AS `$$ROOT` FROM `Rentals`), PARSE_JSON('[ 1,2,3,4]')) AS test
FROM `customers`;
```

Expand All @@ -285,7 +299,7 @@ Returns true or false if the arrays are equal.

```sql
SELECT id,
SET_EQUALS((SELECT `Film Title` AS $$ROOT FROM `Rentals`), PARSE_JSON([ 1,2,3,4])) AS test
SET_EQUALS((SELECT `Film Title` AS `$$ROOT` FROM `Rentals`), PARSE_JSON('[ 1,2,3,4]')) AS test
FROM `customers`;
```

Expand All @@ -299,7 +313,7 @@ Returns an array as the difference of the provided arrays.

```sql
SELECT id,
SET_INTERSECTION((SELECT filmId AS $$ROOT FROM `Rentals`), PARSE_JSON([ 1,2,3,4])) AS
SET_INTERSECTION((SELECT filmId AS `$$ROOT` FROM `Rentals`), PARSE_JSON('[ 1,2,3,4]')) AS
test FROM `customers`;
```

Expand All @@ -313,7 +327,7 @@ Returns whether an array is a subset of another.

```sql
SELECT id,
SET_IS_SUBSET((SELECT filmId AS $$ROOT FROM `Rentals`), PARSE_JSON(‘[ 1,2,3,4] ‘)) AS test
SET_IS_SUBSET((SELECT filmId AS `$$ROOT` FROM `Rentals`), PARSE_JSON(‘[ 1,2,3,4] ‘)) AS test
FROM `customers`;
```

Expand All @@ -327,7 +341,7 @@ Returns an array as the union of the provided arrays.

```sql
SELECT id,
SET_UNION((SELECT filmId AS $$ROOT FROM `Rentals`), PARSE_JSON(‘[ 1,2,3,4] ‘)) AS test
SET_UNION((SELECT filmId AS `$$ROOT` FROM `Rentals`), PARSE_JSON(‘[ 1,2,3,4] ‘)) AS test
FROM `customers`;
```

Expand Down Expand Up @@ -355,7 +369,7 @@ Sums the values in an array given an array field or sub-select and the field to

```sql
SELECT
SUM_ARRAY(`Rentals`, staffId) AS totalStaffIds
SUM_ARRAY(`Rentals`, 'staffId') AS totalStaffIds
FROM `customers`;
```

Expand All @@ -382,7 +396,7 @@ Averages the values in an array given an array field or sub-select and the field

```sql
SELECT
AVG_ARRAY(`Rentals`, staffId) AS avgStaffIds
AVG_ARRAY(`Rentals`, 'staffId') AS avgStaffIds
FROM `customers`;
```

Expand All @@ -397,6 +411,6 @@ Transposes an array of input arrays so that the first element of the output arra
```sql
SELECT id,
ZIP_ARRAY(
(SELECT `Film Title` AS $$ROOT FROM `Rentals`),ARRAY_RANGE(0,10,2)) AS test
(SELECT `Film Title` AS `$$ROOT` FROM `Rentals`),ARRAY_RANGE(0,10,2)) AS test
FROM `customers`;
```
25 changes: 25 additions & 0 deletions docs/docs/sql-syntax/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,28 @@ Creates an empty object.
END AS addressStatus
FROM `customers`;
```

[//]: # (todo add back when flatten implemented)
[//]: # (### FLATTEN)

[//]: # ()
[//]: # (`FLATTEN&#40;field, prefix&#41;`)

[//]: # ()
[//]: # (Flattens an object into a set of fields.)

[//]: # ()
[//]: # (???+ example "Example `FLATTEN` usage")

[//]: # ()
[//]: # ( ```sql)

[//]: # ( SELECT)

[//]: # ( id,)

[//]: # ( FLATTEN&#40;`address`,'addr_'&#41;)

[//]: # ( FROM `customers`;)

[//]: # ( ```)
Loading
Loading