Skip to content
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
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

igor-dv
Copy link

@igor-dv igor-dv commented Jan 25, 2018

What I did

I've added an optional Action<string, IList<object>> trackSql = null argument to the QueryExt methods

TBD - tests.

@@ -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)
Copy link
Contributor

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);
Copy link
Contributor

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));
Copy link
Contributor

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

Copy link
Contributor

@ysa23 ysa23 left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants