From 268acbf38916a0f76c18a5ee0c3ee39acd4837db Mon Sep 17 00:00:00 2001 From: XmasApple Date: Tue, 14 Nov 2023 18:30:03 +0300 Subject: [PATCH] QueryService: move Query method overload without return type to NonQuery method --- examples/src/QueryExample/QueryExample.cs | 16 +++------------- src/Ydb.Sdk/src/Services/Query/QueryClient.cs | 2 +- src/Ydb.Sdk/src/Services/Query/Tx.cs | 2 +- .../tests/Query/TestQueryIntegration.cs | 19 +++++++------------ 4 files changed, 12 insertions(+), 27 deletions(-) diff --git a/examples/src/QueryExample/QueryExample.cs b/examples/src/QueryExample/QueryExample.cs index 02809ac0..8f1a6f67 100644 --- a/examples/src/QueryExample/QueryExample.cs +++ b/examples/src/QueryExample/QueryExample.cs @@ -68,14 +68,6 @@ public static async Task Run( }; - private static async Task EmptyStreamFunc(ExecuteQueryStream stream) - { - while (await stream.Next()) - { - } - } - - private async Task SchemeQuery() { var createQuery = @$" @@ -136,10 +128,9 @@ REPLACE INTO episodes SELECT * FROM AS_TABLE($episodesData); "; - var response = await Client.Query( + var response = await Client.NonQuery( queryString: query, parameters: DataUtils.GetDataParams(), - func: EmptyStreamFunc, txModeSettings: new TxModeSerializableSettings(), executeQuerySettings: DefaultQuerySettings ); @@ -209,7 +200,7 @@ UPSERT INTO series (series_id, title, release_date) VALUES { "$release_date", YdbValue.MakeDate(date) } }; - var response = await Client.Query( + var response = await Client.NonQuery( query, parameters ); @@ -271,9 +262,8 @@ UPSERT INTO seasons (series_id, season_id, first_aired) VALUES { "$air_date", YdbValue.MakeDate(newAired) } }; - var response2 = await tx.Query(query2, parameters2, EmptyStreamFunc); + var response2 = await tx.NonQuery(query2, parameters2); response2.EnsureSuccess(); - return response2; } ); doTxResponse.EnsureSuccess(); diff --git a/src/Ydb.Sdk/src/Services/Query/QueryClient.cs b/src/Ydb.Sdk/src/Services/Query/QueryClient.cs index 99548b03..eb1208f0 100644 --- a/src/Ydb.Sdk/src/Services/Query/QueryClient.cs +++ b/src/Ydb.Sdk/src/Services/Query/QueryClient.cs @@ -616,7 +616,7 @@ public async Task> Query( retrySettings); } - public async Task Query(string queryString, + public async Task NonQuery(string queryString, Dictionary? parameters = null, Func? func = null, ITxModeSettings? txModeSettings = null, diff --git a/src/Ydb.Sdk/src/Services/Query/Tx.cs b/src/Ydb.Sdk/src/Services/Query/Tx.cs index 7ef43c1f..6bc57fcb 100644 --- a/src/Ydb.Sdk/src/Services/Query/Tx.cs +++ b/src/Ydb.Sdk/src/Services/Query/Tx.cs @@ -138,7 +138,7 @@ public async Task> Query(string queryString, Func< return await Query(queryString, new Dictionary(), func, executeQuerySettings); } - public async Task Query(string queryString, + public async Task NonQuery(string queryString, Dictionary? parameters = null, Func? func = null , ExecuteQuerySettings? executeQuerySettings = null) diff --git a/src/Ydb.Sdk/tests/Query/TestQueryIntegration.cs b/src/Ydb.Sdk/tests/Query/TestQueryIntegration.cs index 43907a81..1ecbbb4f 100644 --- a/src/Ydb.Sdk/tests/Query/TestQueryIntegration.cs +++ b/src/Ydb.Sdk/tests/Query/TestQueryIntegration.cs @@ -31,9 +31,9 @@ public async Task TestSchemeQuery() await using var driver = await Driver.CreateInitialized(_driverConfig, _loggerFactory); using var client = new QueryClient(driver); - var createResponse = await client.Query("CREATE TABLE demo_table (id Int32, data Text, PRIMARY KEY(id));"); + var createResponse = await client.NonQuery("CREATE TABLE demo_table (id Int32, data Text, PRIMARY KEY(id));"); Assert.Equal(StatusCode.Success, createResponse.Status.StatusCode); - var dropResponse = await client.Query("DROP TABLE demo_table;"); + var dropResponse = await client.NonQuery("DROP TABLE demo_table;"); Assert.Equal(StatusCode.Success, dropResponse.Status.StatusCode); } @@ -111,8 +111,8 @@ public async Task TestSimpleCrud() { new(1, "entity 1", Array.Empty(), true), new(2, "entity 2", Array.Empty(), true), - new(3, "entity 3", new byte[] { 0x00, 0x22 }, false), - new(3, "dublicate", new byte[] { 0x00, 0x22 }, true), + new(3, "entity 3", new byte[] { 0x00, 0x22 }, true), + new(3, "duplicate", new byte[] { 0x00, 0x22 }, false), new(5, "entity 5", new byte[] { 0x12, 0x23, 0x34, 0x45, 0x56 }, false) }; @@ -130,7 +130,7 @@ public async Task TestSimpleCrud() { "$payload", YdbValue.MakeString(entity.Payload) }, { "$is_valid", (YdbValue)entity.IsValid } }; - var upsertResponse = await client.Query(upsertQuery, parameters); + var upsertResponse = await client.NonQuery(upsertQuery, parameters); Assert.Equal(StatusCode.Success, upsertResponse.Status.StatusCode); } @@ -163,11 +163,7 @@ ORDER BY name DESC return result; }); Assert.Equal(StatusCode.Success, selectResponse.Status.StatusCode); - if (!selectResponse.Status.IsSuccess) - { - return selectResponse; - } - + var entityToDelete = selectResponse.Result![0]; const string deleteQuery = @$" @@ -180,9 +176,8 @@ DELETE FROM {tableName} { "$id", (YdbValue)entityToDelete.Id } }; - var deleteResponse = await tx.Query(deleteQuery, deleteParameters); + var deleteResponse = await tx.NonQuery(deleteQuery, deleteParameters); Assert.Equal(StatusCode.Success, deleteResponse.Status.StatusCode); - return deleteResponse; } ); Assert.Equal(StatusCode.Success, response.Status.StatusCode);