mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-13 03:28:37 -05:00
query/executeString (#217)
This is a small API addition that allows us to execute queries directly as strings. This will make it easier to execute queries outside the confines of a workspace like VS Code.
* Refactor execution requests and events are now named less redundantly and moved into a separate namespace for organization. This is the bulk of the changes.
* QueryExecuteBatchNotification -> ExecuteRequests/BatchEvents
* QueryExecuteMessageNotification -> ExecuteRequests/MessageEvent
* QueryExecuteCompleteNotification -> ExecuteRequests/QueryCompleteEvent
* QueryExecuteResultSetCompleteNotification -> ExecuteRequests/ResultSetEvents
* QueryExecuteSubsetRequest -> SubsetRequest.cs
* Creating an inheritance pattern where
* `ExecuteRequestParamsBase` has execution options and ID for a query execute request
* `ExecuteDocumentSelectionParams` inherits from `ExecuteRequestParamsBase` and provides a document selection
* `ExecuteStringParams` inherits from `ExecuteRequestParamsBase` and provides the query text
* Adding a helper method to get SQL text based on request type
* Through the AWESOME POWER OF POLYMORPHISM, we are able to create a request for executing straight SQL basically for free.
* **Breaking change:** query/execute => query/executeDocumentSelection to make it more obvious what is expected.
* Adding unit tests for the code that gets SQL text
* Refactoring of execute contracts into their own namespace
* Refactoring application
* Adding new request for executing queries as strings
* Adding forgotten string request
* Changing the logic for checking the request param types
* Removing redundant declarations
This commit is contained in:
@@ -4,13 +4,13 @@
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameters to be sent back as part of a QueryExecuteBatchCompleteEvent to indicate that a
|
||||
/// batch of a query completed.
|
||||
/// Parameters to be sent back as part of a batch start or complete event to indicate that a
|
||||
/// batch of a query started or completed.
|
||||
/// </summary>
|
||||
public class QueryExecuteBatchNotificationParams
|
||||
public class BatchEventParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary of the batch that just completed
|
||||
@@ -23,17 +23,17 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
public string OwnerUri { get; set; }
|
||||
}
|
||||
|
||||
public class QueryExecuteBatchCompleteEvent
|
||||
public class BatchCompleteEvent
|
||||
{
|
||||
public static readonly
|
||||
EventType<QueryExecuteBatchNotificationParams> Type =
|
||||
EventType<QueryExecuteBatchNotificationParams>.Create("query/batchComplete");
|
||||
EventType<BatchEventParams> Type =
|
||||
EventType<BatchEventParams>.Create("query/batchComplete");
|
||||
}
|
||||
|
||||
public class QueryExecuteBatchStartEvent
|
||||
public class BatchStartEvent
|
||||
{
|
||||
public static readonly
|
||||
EventType<QueryExecuteBatchNotificationParams> Type =
|
||||
EventType<QueryExecuteBatchNotificationParams>.Create("query/batchStart");
|
||||
EventType<BatchEventParams> Type =
|
||||
EventType<BatchEventParams>.Create("query/batchStart");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameters for executing a query from a document open in the workspace
|
||||
/// </summary>
|
||||
public class ExecuteDocumentSelectionParams : ExecuteRequestParamsBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The selection from the document
|
||||
/// </summary>
|
||||
public SelectionData QuerySelection { get; set; }
|
||||
}
|
||||
|
||||
public class ExecuteDocumentSelectionRequest
|
||||
{
|
||||
public static readonly
|
||||
RequestType<ExecuteDocumentSelectionParams, ExecuteRequestResult> Type =
|
||||
RequestType<ExecuteDocumentSelectionParams, ExecuteRequestResult>.Create("query/executeDocumentSelection");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic parameters that are required for executing a query
|
||||
/// </summary>
|
||||
public abstract class ExecuteRequestParamsBase
|
||||
{
|
||||
/// <summary>
|
||||
/// URI for the editor that is asking for the query execute
|
||||
/// </summary>
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Execution plan options
|
||||
/// </summary>
|
||||
public ExecutionPlanOptions ExecutionPlanOptions { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameters for the query execute result
|
||||
/// </summary>
|
||||
public class ExecuteRequestResult
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameters for executing a query directly
|
||||
/// </summary>
|
||||
public class ExecuteStringParams : ExecuteRequestParamsBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The query to execute
|
||||
/// </summary>
|
||||
public string Query { get; set; }
|
||||
}
|
||||
|
||||
public class ExecuteStringRequest
|
||||
{
|
||||
public static readonly
|
||||
RequestType<ExecuteStringParams, ExecuteRequestResult> Type =
|
||||
RequestType<ExecuteStringParams, ExecuteRequestResult>.Create("query/executeString");
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameters to be sent back with a message notification
|
||||
/// </summary>
|
||||
public class QueryExecuteMessageParams
|
||||
public class MessageParams
|
||||
{
|
||||
/// <summary>
|
||||
/// URI for the editor that owns the query
|
||||
@@ -23,10 +23,10 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
public ResultMessage Message { get; set; }
|
||||
}
|
||||
|
||||
public class QueryExecuteMessageEvent
|
||||
public class MessageEvent
|
||||
{
|
||||
public static readonly
|
||||
EventType<QueryExecuteMessageParams> Type =
|
||||
EventType<QueryExecuteMessageParams>.Create("query/message");
|
||||
EventType<MessageParams> Type =
|
||||
EventType<MessageParams>.Create("query/message");
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameters to be sent back with a query execution complete event
|
||||
/// </summary>
|
||||
public class QueryExecuteCompleteParams
|
||||
public class QueryCompleteParams
|
||||
{
|
||||
/// <summary>
|
||||
/// URI for the editor that owns the query
|
||||
@@ -23,10 +23,10 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
public BatchSummary[] BatchSummaries { get; set; }
|
||||
}
|
||||
|
||||
public class QueryExecuteCompleteEvent
|
||||
public class QueryCompleteEvent
|
||||
{
|
||||
public static readonly
|
||||
EventType<QueryExecuteCompleteParams> Type =
|
||||
EventType<QueryExecuteCompleteParams>.Create("query/complete");
|
||||
EventType<QueryCompleteParams> Type =
|
||||
EventType<QueryCompleteParams>.Create("query/complete");
|
||||
}
|
||||
}
|
||||
@@ -4,19 +4,22 @@
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests
|
||||
{
|
||||
public class QueryExecuteResultSetCompleteParams
|
||||
/// <summary>
|
||||
/// Parameters to return when a result set is started or completed
|
||||
/// </summary>
|
||||
public class ResultSetEventParams
|
||||
{
|
||||
public ResultSetSummary ResultSetSummary { get; set; }
|
||||
|
||||
public string OwnerUri { get; set; }
|
||||
}
|
||||
|
||||
public class QueryExecuteResultSetCompleteEvent
|
||||
public class ResultSetCompleteEvent
|
||||
{
|
||||
public static readonly
|
||||
EventType<QueryExecuteResultSetCompleteParams> Type =
|
||||
EventType<QueryExecuteResultSetCompleteParams>.Create("query/resultSetComplete");
|
||||
EventType<ResultSetEventParams> Type =
|
||||
EventType<ResultSetEventParams>.Create("query/resultSetComplete");
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameters for the query execute request
|
||||
/// </summary>
|
||||
public class QueryExecuteParams
|
||||
{
|
||||
/// <summary>
|
||||
/// The selection from the document
|
||||
/// </summary>
|
||||
public SelectionData QuerySelection { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// URI for the editor that is asking for the query execute
|
||||
/// </summary>
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Execution plan options
|
||||
/// </summary>
|
||||
public ExecutionPlanOptions ExecutionPlanOptions { get; set; }
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parameters for the query execute result
|
||||
/// </summary>
|
||||
public class QueryExecuteResult
|
||||
{
|
||||
}
|
||||
|
||||
public class QueryExecuteRequest
|
||||
{
|
||||
public static readonly
|
||||
RequestType<QueryExecuteParams, QueryExecuteResult> Type =
|
||||
RequestType<QueryExecuteParams, QueryExecuteResult>.Create("query/execute");
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
/// <summary>
|
||||
/// Parameters for a query result subset retrieval request
|
||||
/// </summary>
|
||||
public class QueryExecuteSubsetParams
|
||||
public class SubsetParams
|
||||
{
|
||||
/// <summary>
|
||||
/// URI for the file that owns the query to look up the results for
|
||||
@@ -44,7 +44,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
/// <summary>
|
||||
/// Parameters for the result of a subset retrieval request
|
||||
/// </summary>
|
||||
public class QueryExecuteSubsetResult
|
||||
public class SubsetResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Subset request error messages. Optional, can be set to null to indicate no errors
|
||||
@@ -57,10 +57,10 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||
public ResultSetSubset ResultSubset { get; set; }
|
||||
}
|
||||
|
||||
public class QueryExecuteSubsetRequest
|
||||
public class SubsetRequest
|
||||
{
|
||||
public static readonly
|
||||
RequestType<QueryExecuteSubsetParams, QueryExecuteSubsetResult> Type =
|
||||
RequestType<QueryExecuteSubsetParams, QueryExecuteSubsetResult>.Create("query/subset");
|
||||
RequestType<SubsetParams, SubsetResult> Type =
|
||||
RequestType<SubsetParams, SubsetResult>.Create("query/subset");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user