-
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
base: master
Are you sure you want to change the base?
Conversation
@@ -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) |
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
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the parameters
where T : class, new() | ||
{ | ||
trackSql?.Invoke(new SqlDescriptor(sql, parameters)); |
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.
extract to method and add try-catch to invocation - since this is an artifact and should not prevent the query to run
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.
Please update the minor version
What I did
I've added an optional
Action<string, IList<object>> trackSql = null
argument to theQueryExt
methodsTBD - tests.