-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Very early prototype of ExplainOptions for Datastore
This is just an attempt at the shape of things. Still to do: - Naming! - Documentation - Testing - We can refactor a lot of other code to use AdvancedQuery - Aggregation queries - Transactions (hopefully put transaction ID support into AdvancedQuery and then just add overloads)
- Loading branch information
Showing
9 changed files
with
275 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
apis/Google.Cloud.Datastore.V1/Google.Cloud.Datastore.V1/AdvancedQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"): | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using static Google.Cloud.Datastore.V1.ReadOptions.Types; | ||
|
||
namespace Google.Cloud.Datastore.V1; | ||
|
||
/// <summary> | ||
/// Prototype only! | ||
/// </summary> | ||
public class AdvancedQuery | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public GqlQuery GqlQuery { get; set; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public Query Query { get; set; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public ExplainOptions ExplainOptions { get; set; } | ||
|
||
/// <summary> | ||
/// | ||
/// </summary> | ||
public ReadConsistency? ReadConsistency { get; set; } | ||
|
||
internal RunQueryRequest ToRequest(string projectId, string databaseId, PartitionId partitionId) | ||
{ | ||
var request = new RunQueryRequest | ||
{ | ||
ProjectId = projectId, | ||
DatabaseId = databaseId, | ||
PartitionId = partitionId, | ||
ReadOptions = GetReadOptions(ReadConsistency), | ||
ExplainOptions = ExplainOptions | ||
}; | ||
// TODO: Validation of exactly one being set, or make the properties behave like a oneof. | ||
if (GqlQuery is not null) | ||
{ | ||
request.GqlQuery = GqlQuery; | ||
} | ||
if (Query is not null) | ||
{ | ||
request.Query = Query; | ||
} | ||
return request; | ||
} | ||
|
||
private static ReadOptions GetReadOptions(ReadConsistency? readConsistency) => | ||
readConsistency == null ? null : new ReadOptions { ReadConsistency = readConsistency.Value }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.