Skip to content

Commit

Permalink
fix: overloads in Delete
Browse files Browse the repository at this point in the history
  • Loading branch information
phnx47 committed Oct 16, 2022
1 parent 0cddedf commit e6736f4
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 21 deletions.
64 changes: 51 additions & 13 deletions src/MicroOrm.Dapper.Repositories/DapperRepository.Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ public partial class DapperRepository<TEntity>
where TEntity : class
{
/// <inheritdoc />
public virtual bool Delete(TEntity instance, IDbTransaction? transaction = null, TimeSpan? timeout = null)
public virtual bool Delete(TEntity instance)
{
return Delete(instance, null, null);
}

/// <inheritdoc />
public virtual bool Delete(TEntity instance, TimeSpan? timeout)
{
return Delete(instance, null, timeout);
}

/// <inheritdoc />
public virtual bool Delete(TEntity instance, IDbTransaction? transaction, TimeSpan? timeout)
{
var queryResult = SqlGenerator.GetDelete(instance);
int? commandTimeout = null;
Expand All @@ -25,42 +37,68 @@ public virtual bool Delete(TEntity instance, IDbTransaction? transaction = null,
}

/// <inheritdoc />
public virtual Task<bool> DeleteAsync(TEntity instance, IDbTransaction? transaction, TimeSpan? timeout)
public virtual bool Delete(Expression<Func<TEntity, bool>>? predicate)
{
return DeleteAsync(instance, transaction, timeout, default(CancellationToken));
return Delete(predicate, null, null);
}

/// <inheritdoc />
public virtual async Task<bool> DeleteAsync(TEntity instance, IDbTransaction? transaction = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
public virtual bool Delete(Expression<Func<TEntity, bool>>? predicate, TimeSpan? timeout)
{
var queryResult = SqlGenerator.GetDelete(instance);
return Delete(predicate, null, timeout);
}

/// <inheritdoc />
public virtual bool Delete(Expression<Func<TEntity, bool>>? predicate, IDbTransaction? transaction, TimeSpan? timeout)
{
var queryResult = SqlGenerator.GetDelete(predicate);
int? commandTimeout = null;
if (timeout.HasValue)
commandTimeout = timeout.Value.Seconds;
var deleted = await Connection.ExecuteAsync(new CommandDefinition(queryResult.GetSql(), queryResult.Param, transaction, commandTimeout,
cancellationToken: cancellationToken)) > 0;
var deleted = Connection.Execute(queryResult.GetSql(), queryResult.Param, transaction, commandTimeout) > 0;
return deleted;
}

/// <inheritdoc />
public virtual bool Delete(Expression<Func<TEntity, bool>>? predicate, IDbTransaction? transaction = null, TimeSpan? timeout = null)
public virtual Task<bool> DeleteAsync(TEntity instance, CancellationToken cancellationToken = default)
{
var queryResult = SqlGenerator.GetDelete(predicate);
return DeleteAsync(instance, null, null, cancellationToken);
}

/// <inheritdoc />
public virtual Task<bool> DeleteAsync(TEntity instance, TimeSpan? timeout, CancellationToken cancellationToken = default)
{
return DeleteAsync(instance, null, timeout, cancellationToken);
}


/// <inheritdoc />
public virtual async Task<bool> DeleteAsync(TEntity instance, IDbTransaction? transaction, TimeSpan? timeout, CancellationToken cancellationToken = default)
{
var queryResult = SqlGenerator.GetDelete(instance);
int? commandTimeout = null;
if (timeout.HasValue)
commandTimeout = timeout.Value.Seconds;
var deleted = Connection.Execute(queryResult.GetSql(), queryResult.Param, transaction, commandTimeout) > 0;
var deleted = await Connection.ExecuteAsync(new CommandDefinition(queryResult.GetSql(), queryResult.Param, transaction, commandTimeout,
cancellationToken: cancellationToken)) > 0;
return deleted;
}

/// <inheritdoc />
public virtual Task<bool> DeleteAsync(Expression<Func<TEntity, bool>>? predicate, IDbTransaction? transaction, TimeSpan? timeout)
public virtual Task<bool> DeleteAsync(Expression<Func<TEntity, bool>>? predicate, CancellationToken cancellationToken = default)
{
return DeleteAsync(predicate, transaction, timeout, default);
return DeleteAsync(predicate, null, null, cancellationToken);
}

/// <inheritdoc />
public virtual async Task<bool> DeleteAsync(Expression<Func<TEntity, bool>>? predicate, IDbTransaction? transaction = null, TimeSpan? timeout = null,
public virtual Task<bool> DeleteAsync(Expression<Func<TEntity, bool>>? predicate, TimeSpan? timeout, CancellationToken cancellationToken = default)
{
return DeleteAsync(predicate, null, timeout, cancellationToken);
}


/// <inheritdoc />
public virtual async Task<bool> DeleteAsync(Expression<Func<TEntity, bool>>? predicate, IDbTransaction? transaction, TimeSpan? timeout,
CancellationToken cancellationToken = default)
{
var queryResult = SqlGenerator.GetDelete(predicate);
Expand Down
49 changes: 41 additions & 8 deletions src/MicroOrm.Dapper.Repositories/IDapperRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,63 @@ public interface IDapperRepository<TEntity> : IReadOnlyDapperRepository<TEntity>
/// <summary>
/// Delete object from DB
/// </summary>
bool Delete(TEntity instance, IDbTransaction? transaction = null, TimeSpan? timeout = null);
bool Delete(TEntity instance);

/// <summary>
/// Delete object from DB
/// </summary>
Task<bool> DeleteAsync(TEntity instance, IDbTransaction? transaction, TimeSpan? timeout);
bool Delete(TEntity instance, TimeSpan? timeout);

/// <summary>
/// Delete object from DB
/// </summary>
Task<bool> DeleteAsync(TEntity instance, IDbTransaction? transaction = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default);
bool Delete(TEntity instance, IDbTransaction? transaction, TimeSpan? timeout);

/// <summary>
/// Delete objects from DB
/// </summary>
bool Delete(Expression<Func<TEntity, bool>>? predicate, IDbTransaction? transaction = null, TimeSpan? timeout = null);
bool Delete(Expression<Func<TEntity, bool>>? predicate);

/// <summary>
/// Delete objects from DB
/// </summary>
Task<bool> DeleteAsync(Expression<Func<TEntity, bool>>? predicate, IDbTransaction? transaction, TimeSpan? timeout);
bool Delete(Expression<Func<TEntity, bool>>? predicate, TimeSpan? timeout);

/// <summary>
/// Delete objects from DB
/// </summary>
Task<bool> DeleteAsync(Expression<Func<TEntity, bool>>? predicate, IDbTransaction? transaction = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default);
bool Delete(Expression<Func<TEntity, bool>>? predicate, IDbTransaction? transaction, TimeSpan? timeout);

/// <summary>
/// Delete object from DB
/// </summary>
Task<bool> DeleteAsync(TEntity instance, CancellationToken cancellationToken = default);

/// <summary>
/// Delete object from DB
/// </summary>
Task<bool> DeleteAsync(TEntity instance, TimeSpan? timeout, CancellationToken cancellationToken = default);


/// <summary>
/// Delete object from DB
/// </summary>
Task<bool> DeleteAsync(TEntity instance, IDbTransaction? transaction, TimeSpan? timeout, CancellationToken cancellationToken = default);

/// <summary>
/// Delete objects from DB
/// </summary>
Task<bool> DeleteAsync(Expression<Func<TEntity, bool>>? predicate, CancellationToken cancellationToken = default);

/// <summary>
/// Delete objects from DB
/// </summary>
Task<bool> DeleteAsync(Expression<Func<TEntity, bool>>? predicate, TimeSpan? timeout, CancellationToken cancellationToken = default);

/// <summary>
/// Delete objects from DB
/// </summary>
Task<bool> DeleteAsync(Expression<Func<TEntity, bool>>? predicate, IDbTransaction? transaction, TimeSpan? timeout, CancellationToken cancellationToken = default);

/// <summary>
/// Insert object to DB
Expand Down Expand Up @@ -145,7 +176,8 @@ public interface IDapperRepository<TEntity> : IReadOnlyDapperRepository<TEntity>
/// <summary>
/// Update object in DB
/// </summary>
Task<bool> UpdateAsync(Expression<Func<TEntity, bool>>? predicate, TEntity instance, CancellationToken cancellationToken, params Expression<Func<TEntity, object>>[] includes);
Task<bool> UpdateAsync(Expression<Func<TEntity, bool>>? predicate, TEntity instance, CancellationToken cancellationToken,
params Expression<Func<TEntity, object>>[] includes);

/// <summary>
/// Update object in DB
Expand All @@ -160,7 +192,8 @@ public interface IDapperRepository<TEntity> : IReadOnlyDapperRepository<TEntity>
/// <summary>
/// Update object in DB
/// </summary>
Task<bool> UpdateAsync(Expression<Func<TEntity, bool>>? predicate, TEntity instance, IDbTransaction? transaction, CancellationToken cancellationToken, params Expression<Func<TEntity, object>>[] includes);
Task<bool> UpdateAsync(Expression<Func<TEntity, bool>>? predicate, TEntity instance, IDbTransaction? transaction, CancellationToken cancellationToken,
params Expression<Func<TEntity, object>>[] includes);

/// <summary>
/// Bulk Update objects to DB
Expand Down

0 comments on commit e6736f4

Please sign in to comment.