Skip to content

Commit

Permalink
QuerySingle<T7>(commandText, commandType, parameters, splitOn)
Browse files Browse the repository at this point in the history
  • Loading branch information
C0nquistadore committed Jun 2, 2022
1 parent 3ab5436 commit 40ab73b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/Dibix.Dapper/DapperDatabaseAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ protected override Task<IEnumerable<T>> QueryManyAsync<T>(string commandText, Co
return base.Connection.Query(commandText, map, CollectParameters(parameters), this._transaction, commandType: commandType, splitOn: splitOn);
}

protected override IEnumerable<TReturn> QueryMany<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(string commandText, CommandType commandType, ParametersVisitor parameters, Func<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn> map, string splitOn)
{
DecoratedTypeMap.Adapt<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh>();
return base.Connection.Query(commandText, map, CollectParameters(parameters), this._transaction, commandType: commandType, splitOn: splitOn);
}

protected override IEnumerable<TReturn> QueryMany<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TEighth, TNinth, TReturn>(string commandText, CommandType commandType, ParametersVisitor parameters, Func<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TEighth, TNinth, TReturn> map, string splitOn)
{
DecoratedTypeMap.Adapt<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TEighth, TNinth>();
Expand Down
9 changes: 9 additions & 0 deletions src/Dibix/Access/DatabaseAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ protected DatabaseAccessor(DbConnection connection, Action onDispose)
.Single();
});

public TReturn QuerySingle<TReturn, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh>(string commandText, CommandType commandType, ParametersVisitor parameters, string splitOn) where TReturn : new() => Execute(commandText, commandType, parameters, () =>
{
MultiMapper multiMapper = new MultiMapper();
return this.QueryMany<TReturn, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(commandText, commandType, parameters, (a, b, c, d, e, f, g) => multiMapper.MapRow<TReturn>(useProjection: false, a, b, c, d, e, f, g), splitOn)
.PostProcess(multiMapper)
.Single();
});

T IDatabaseAccessor.QuerySingleOrDefault<T>(string commandText, CommandType commandType, ParametersVisitor parameters) => Execute(commandText, commandType, parameters, () => this.QuerySingleOrDefault<T>(commandText, commandType, parameters).PostProcess());

IMultipleResultReader IDatabaseAccessor.QueryMultiple(string commandText, CommandType commandType, ParametersVisitor parameters) => Execute(commandText, commandType, parameters, () => this.QueryMultiple(commandText, commandType, parameters));
Expand All @@ -140,6 +148,7 @@ protected DatabaseAccessor(DbConnection connection, Action onDispose)
protected abstract IEnumerable<TReturn> QueryMany<TFirst, TSecond, TThird, TFourth, TFifth, TReturn>(string commandText, CommandType commandType, ParametersVisitor parameters, Func<TFirst, TSecond, TThird, TFourth, TFifth, TReturn> map, string splitOn);

protected abstract IEnumerable<TReturn> QueryMany<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TReturn>(string commandText, CommandType commandType, ParametersVisitor parameters, Func<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TReturn> map, string splitOn);
protected abstract IEnumerable<TReturn> QueryMany<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(string commandText, CommandType commandType, ParametersVisitor parameters, Func<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn> map, string splitOn);

protected abstract IEnumerable<TReturn> QueryMany<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TEighth, TNinth, TReturn>(string commandText, CommandType commandType, ParametersVisitor parameters, Func<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TEighth, TNinth, TReturn> map, string splitOn);

Expand Down
7 changes: 0 additions & 7 deletions src/Dibix/Access/DatabaseAccessorExtensions.QuerySingle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,5 @@ public static T QuerySingle<T>(this IDatabaseAccessor accessor, string commandTe
}, splitOn);
return cache.Single();
}

// OrderManagement (LoadOrder)
public static TReturn QuerySingle<TReturn, TSecond, TThird, TFourth, TFifth>(this IDatabaseAccessor accessor, string commandText, ParametersVisitor parameters, string splitOn) where TReturn : new()
{
Guard.IsNotNull(accessor, nameof(accessor));
return accessor.QuerySingle<TReturn, TSecond, TThird, TFourth, TFifth>(commandText, CommandType.Text, parameters, splitOn);
}
}
}
1 change: 1 addition & 0 deletions src/Dibix/Access/IDatabaseAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public interface IDatabaseAccessor : IDisposable
TReturn QuerySingle<TReturn, TSecond, TThird>(string commandText, CommandType commandType, ParametersVisitor parameters, string splitOn) where TReturn : new();
TReturn QuerySingle<TReturn, TSecond, TThird, TFourth>(string commandText, CommandType commandType, ParametersVisitor parameters, string splitOn) where TReturn : new();
TReturn QuerySingle<TReturn, TSecond, TThird, TFourth, TFifth>(string commandText, CommandType commandType, ParametersVisitor parameters, string splitOn) where TReturn : new();
TReturn QuerySingle<TReturn, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh>(string commandText, CommandType commandType, ParametersVisitor parameters, string splitOn) where TReturn : new();
T QuerySingleOrDefault<T>(string commandText, CommandType commandType, ParametersVisitor parameters);
IMultipleResultReader QueryMultiple(string commandText, CommandType commandType, ParametersVisitor parameters);
Task<IMultipleResultReader> QueryMultipleAsync(string commandText, CommandType commandType, ParametersVisitor parameters, CancellationToken cancellationToken);
Expand Down

0 comments on commit 40ab73b

Please sign in to comment.