-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add trackSql action to handle generated sql and params #1
Open
igor-dv
wants to merge
6
commits into
shopyourway:master
Choose a base branch
from
igor-dv:track-sql
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
89df7f9
Add trackSql action
igor-dv e88dd4d
Add parameters to the trackSql func as well
igor-dv 708af3f
Add SqlDescriptor class and use it in trackSql func instead of the fl…
igor-dv 4efc720
Extract TrackSql and suppress exception if it happens
igor-dv a3fb301
Add to Sanity
igor-dv edffb07
Bump minor
igor-dv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,14 +19,16 @@ public static T GetById<T>(this IDbConnection connection, object id) | |
return Run<T>(connection, sql, parameters, generator.GetColumns()).FirstOrDefault(); | ||
} | ||
|
||
public static long Count<T>(this IDbConnection connection, Action<IRestrictable<T>> restrictions = null) | ||
public static long Count<T>(this IDbConnection connection, Action<IRestrictable<T>> restrictions = null, Action<string> trackSql = null) | ||
where T : class, new() | ||
{ | ||
var countByQuery = new CountByQuery<T>(); | ||
|
||
var parameters = new List<object>(); | ||
var sql = countByQuery.GetSql(restrictions, parameters); | ||
|
||
trackSql?.Invoke(sql); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing the parameters |
||
|
||
using (var command = connection.CreateCommand()) | ||
{ | ||
command.CommandText = sql; | ||
|
@@ -35,30 +37,33 @@ public static long Count<T>(this IDbConnection connection, Action<IRestrictable< | |
} | ||
} | ||
|
||
public static IEnumerable<T> Query<T>(this IDbConnection connection, Action<IQueryBuilder<T>> query = null) | ||
public static IEnumerable<T> Query<T>(this IDbConnection connection, Action<IQueryBuilder<T>> query = null, Action<string> trackSql = null) | ||
where T : class, new() | ||
{ | ||
var builder = new QueryBuilder<T>(); | ||
if (query != null) | ||
query(builder); | ||
query?.Invoke(builder); | ||
|
||
var parameters = new List<object>(); | ||
var sql = builder.Build(parameters); | ||
|
||
trackSql?.Invoke(sql); | ||
|
||
return Run<T>(connection, sql, parameters, builder.Properties); | ||
} | ||
|
||
public static IEnumerable<QueryResult<T>> QueryAggregated<T>(this IDbConnection connection, Action<IQueryBuilder<T>> query = null) | ||
public static IEnumerable<QueryResult<T>> QueryAggregated<T>(this IDbConnection connection, Action<IQueryBuilder<T>> query = null, Action<string> trackSql = null) | ||
where T : class, new() | ||
{ | ||
var builder = new QueryBuilder<T>(); | ||
if (query != null) | ||
query(builder); | ||
query?.Invoke(builder); | ||
|
||
builder.RowCount(); | ||
|
||
var parameters = new List<object>(); | ||
var sql = builder.Build(parameters); | ||
|
||
trackSql?.Invoke(sql); | ||
|
||
using (var command = connection.CreateCommand()) | ||
{ | ||
command.CommandText = sql; | ||
|
@@ -127,7 +132,7 @@ private static IEnumerable<T> Run<T>(IDbConnection connection, string sql, List< | |
} | ||
} | ||
|
||
private static void HandleSetValueException<T>(string sql, List<object> parameters, IDataReader reader, IDbConnection connection, Exception ex) | ||
private static void HandleSetValueException<T>(string sql, IList<object> parameters, IDataReader reader, IDbConnection connection, Exception ex) | ||
where T : class, new() | ||
{ | ||
Exception e; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets use an object instead of string + list of obj - it will enable us to extend it later without breaking the contract