Warn on SubQuery (#378)

This commit is contained in:
Steve Faulkner 2021-01-12 13:53:15 -06:00 committed by GitHub
parent 3effbe6991
commit 9d20a13dd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -11,6 +11,17 @@
Start by writing a Mongo query, for example: <strong>{'id':'foo'}</strong> or <strong>{ }</strong> to get all the Start by writing a Mongo query, for example: <strong>{'id':'foo'}</strong> or <strong>{ }</strong> to get all the
documents. documents.
</div> </div>
<div class="warningErrorContainer" aria-live="assertive" data-bind="visible: maybeSubQuery">
<div class="warningErrorContent">
<span><img class="paneErrorIcon" src="/info_color.svg" alt="Error"/></span>
<span class="warningErrorDetailsLinkContainer">
We have detected you may be using a subquery. Non-correlated subqueries are not currently supported.
<a href="https://docs.microsoft.com/en-us/azure/cosmos-db/sql-query-subquery"
>Please see Cosmos sub query documentation for further information</a
>
</span>
</div>
</div>
<div class="queryEditorWithSplitter" data-bind="attr: { id: queryEditorId }"> <div class="queryEditorWithSplitter" data-bind="attr: { id: queryEditorId }">
<editor <editor
class="queryEditor" class="queryEditor"

View File

@ -1,5 +1,4 @@
import * as ko from "knockout"; import * as ko from "knockout";
import Q from "q";
import * as Constants from "../../Common/Constants"; import * as Constants from "../../Common/Constants";
import * as DataModels from "../../Contracts/DataModels"; import * as DataModels from "../../Contracts/DataModels";
import * as ViewModels from "../../Contracts/ViewModels"; import * as ViewModels from "../../Contracts/ViewModels";
@ -7,7 +6,6 @@ import { Action } from "../../Shared/Telemetry/TelemetryConstants";
import TabsBase from "./TabsBase"; import TabsBase from "./TabsBase";
import { HashMap } from "../../Common/HashMap"; import { HashMap } from "../../Common/HashMap";
import * as HeadersUtility from "../../Common/HeadersUtility"; import * as HeadersUtility from "../../Common/HeadersUtility";
import * as Logger from "../../Common/Logger";
import { Splitter, SplitterBounds, SplitterDirection } from "../../Common/Splitter"; import { Splitter, SplitterBounds, SplitterDirection } from "../../Common/Splitter";
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
import ExecuteQueryIcon from "../../../images/ExecuteQuery.svg"; import ExecuteQueryIcon from "../../../images/ExecuteQuery.svg";
@ -31,6 +29,7 @@ export default class QueryTab extends TabsBase implements ViewModels.WaitsForTem
public fetchNextPageButton: ViewModels.Button; public fetchNextPageButton: ViewModels.Button;
public saveQueryButton: ViewModels.Button; public saveQueryButton: ViewModels.Button;
public initialEditorContent: ko.Observable<string>; public initialEditorContent: ko.Observable<string>;
public maybeSubQuery: ko.Computed<boolean>;
public sqlQueryEditorContent: ko.Observable<string>; public sqlQueryEditorContent: ko.Observable<string>;
public selectedContent: ko.Observable<string>; public selectedContent: ko.Observable<string>;
public sqlStatementToExecute: ko.Observable<string>; public sqlStatementToExecute: ko.Observable<string>;
@ -120,6 +119,11 @@ export default class QueryTab extends TabsBase implements ViewModels.WaitsForTem
return (container && (container.isPreferredApiDocumentDB() || container.isPreferredApiGraph())) || false; return (container && (container.isPreferredApiDocumentDB() || container.isPreferredApiGraph())) || false;
}); });
this.maybeSubQuery = ko.computed<boolean>(function() {
const sql = this.sqlQueryEditorContent();
return sql && /.*\(.*SELECT.*\)/i.test(sql);
}, this);
this.saveQueryButton = { this.saveQueryButton = {
enabled: this._isSaveQueriesEnabled, enabled: this._isSaveQueriesEnabled,
visible: this._isSaveQueriesEnabled visible: this._isSaveQueriesEnabled