Skip to content

Commit

Permalink
rename deletion commands
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstonis committed Oct 1, 2021
1 parent a9d4c00 commit 2a5f046
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions Tycho/TychoDb.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
Expand Down Expand Up @@ -404,28 +404,30 @@ public ValueTask<bool> DeleteObjectAsync<T> (object key, string partition = null

try
{
using var selectCommand = conn.CreateCommand ();
using var deleteCommand = conn.CreateCommand ();

var commandBuilder = ReusableStringBuilder;

commandBuilder.Append (Queries.DeleteDataFromJsonValueWithKeyAndFullTypeName);

selectCommand.Parameters.Add (ParameterKey, SqliteType.Text).Value = key;
selectCommand.Parameters.Add (ParameterFullTypeName, SqliteType.Text).Value = typeof (T).FullName;
deleteCommand.Parameters.Add (ParameterKey, SqliteType.Text).Value = key;
deleteCommand.Parameters.Add (ParameterFullTypeName, SqliteType.Text).Value = typeof (T).FullName;

if (!string.IsNullOrEmpty (partition))
{
commandBuilder.Append (Queries.AndPartitionHasValue);
selectCommand.Parameters.Add (ParameterPartition, SqliteType.Text).Value = partition.AsValueOrDbNull ();
deleteCommand.Parameters.Add (ParameterPartition, SqliteType.Text).Value = partition.AsValueOrDbNull ();
}
else
{
commandBuilder.Append (Queries.AndPartitionIsNull);
}

selectCommand.CommandText = commandBuilder.ToString ();
deleteCommand.CommandText = commandBuilder.ToString ();

await deleteCommand.PrepareAsync(cancellationToken).ConfigureAwait(false);

var deletionCount = await selectCommand.ExecuteNonQueryAsync (cancellationToken).ConfigureAwait (false);
var deletionCount = await deleteCommand.ExecuteNonQueryAsync (cancellationToken).ConfigureAwait (false);

await transaction.CommitAsync ().ConfigureAwait (false);

Expand All @@ -450,18 +452,18 @@ public ValueTask<bool> DeleteObjectAsync<T> (object key, string partition = null

try
{
using var selectCommand = conn.CreateCommand ();
using var deleteCommand = conn.CreateCommand ();

var commandBuilder = ReusableStringBuilder;

commandBuilder.Append (Queries.DeleteDataFromJsonValueWithFullTypeName);

selectCommand.Parameters.Add (ParameterFullTypeName, SqliteType.Text).Value = typeof (T).FullName;
deleteCommand.Parameters.Add (ParameterFullTypeName, SqliteType.Text).Value = typeof (T).FullName;

if (!string.IsNullOrEmpty (partition))
{
commandBuilder.Append (Queries.AndPartitionHasValue);
selectCommand.Parameters.Add (ParameterPartition, SqliteType.Text).Value = partition.AsValueOrDbNull ();
deleteCommand.Parameters.Add (ParameterPartition, SqliteType.Text).Value = partition.AsValueOrDbNull ();
}
else
{
Expand All @@ -473,9 +475,11 @@ public ValueTask<bool> DeleteObjectAsync<T> (object key, string partition = null
filter.Build (commandBuilder);
}

selectCommand.CommandText = commandBuilder.ToString ();
deleteCommand.CommandText = commandBuilder.ToString ();

var deletionCount = await selectCommand.ExecuteNonQueryAsync (cancellationToken).ConfigureAwait (false);
await deleteCommand.PrepareAsync(cancellationToken).ConfigureAwait(false);

var deletionCount = await deleteCommand.ExecuteNonQueryAsync (cancellationToken).ConfigureAwait (false);

await transaction.CommitAsync ().ConfigureAwait (false);

Expand Down Expand Up @@ -596,27 +600,29 @@ public ValueTask<bool> DeleteBlobAsync(object key, string partition = null, Canc

try
{
using var selectCommand = conn.CreateCommand();
using var deleteCommand = conn.CreateCommand();

var commandBuilder = ReusableStringBuilder;

commandBuilder.Append(Queries.DeleteDataFromStreamValueWithKey);

selectCommand.Parameters.Add(ParameterKey, SqliteType.Text).Value = key;
deleteCommand.Parameters.Add(ParameterKey, SqliteType.Text).Value = key;

if (!string.IsNullOrEmpty(partition))
{
commandBuilder.Append(Queries.AndPartitionHasValue);
selectCommand.Parameters.Add(ParameterPartition, SqliteType.Text).Value = partition.AsValueOrDbNull();
deleteCommand.Parameters.Add(ParameterPartition, SqliteType.Text).Value = partition.AsValueOrDbNull();
}
else
{
commandBuilder.Append(Queries.AndPartitionIsNull);
}

selectCommand.CommandText = commandBuilder.ToString();
deleteCommand.CommandText = commandBuilder.ToString();

await deleteCommand.PrepareAsync(cancellationToken).ConfigureAwait(false);

var deletionCount = await selectCommand.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false);
var deletionCount = await deleteCommand.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false);

await transaction.CommitAsync().ConfigureAwait(false);

Expand Down

0 comments on commit 2a5f046

Please sign in to comment.