Skip to content

Commit

Permalink
QueryService: move Query method overload without return type to NonQu…
Browse files Browse the repository at this point in the history
…ery method
  • Loading branch information
XmasApple committed Nov 14, 2023
1 parent a9fe3f6 commit 268acbf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 27 deletions.
16 changes: 3 additions & 13 deletions examples/src/QueryExample/QueryExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @$"
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Ydb.Sdk/src/Services/Query/QueryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ public async Task<QueryResponseWithResult<T>> Query<T>(
retrySettings);
}

public async Task<QueryResponse> Query(string queryString,
public async Task<QueryResponse> NonQuery(string queryString,
Dictionary<string, YdbValue>? parameters = null,
Func<ExecuteQueryStream, Task>? func = null,
ITxModeSettings? txModeSettings = null,
Expand Down
2 changes: 1 addition & 1 deletion src/Ydb.Sdk/src/Services/Query/Tx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public async Task<QueryResponseWithResult<T>> Query<T>(string queryString, Func<
return await Query(queryString, new Dictionary<string, YdbValue>(), func, executeQuerySettings);
}

public async Task<QueryResponse> Query(string queryString,
public async Task<QueryResponse> NonQuery(string queryString,
Dictionary<string, YdbValue>? parameters = null,
Func<ExecuteQueryStream, Task>? func = null
, ExecuteQuerySettings? executeQuerySettings = null)
Expand Down
19 changes: 7 additions & 12 deletions src/Ydb.Sdk/tests/Query/TestQueryIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -111,8 +111,8 @@ public async Task TestSimpleCrud()
{
new(1, "entity 1", Array.Empty<byte>(), true),
new(2, "entity 2", Array.Empty<byte>(), 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)
};

Expand All @@ -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);
}

Expand Down Expand Up @@ -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 = @$"
Expand All @@ -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);
Expand Down

0 comments on commit 268acbf

Please sign in to comment.