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

Enhancement: Introduce the formatters for the QueryField class #899

Closed
mikependon opened this issue Sep 16, 2021 · 1 comment
Closed

Enhancement: Introduce the formatters for the QueryField class #899

mikependon opened this issue Sep 16, 2021 · 1 comment
Assignees
Labels
deployed Feature or bug is deployed at the current release enhancement New feature or request fixed The bug, issue, incident has been fixed. todo Things to be done in the future

Comments

@mikependon
Copy link
Owner

mikependon commented Sep 16, 2021

Describe the enhancement

The object QueryField is being used as a class for the conditional query (i.e.: WHERE [Column] = 'Value'). The current limitation to this object is it cannot use the existing underlying provided RDMBS functions (i.e.: LEFT, RIGHT, UPPER, LOWER, TRIM, etc).

This enhancement would at least enable us to extend the QueryField object to be able the user to customize the string generations with the proper usage of the database functions.

Currently, if you use the QueryField object like below.

var where = new LenQueryField("ColumnName", "VALUE");

It will generate the string below.

WHERE ([ColumnName] = @ColumnName);

The target is to override that string generation. Let us say, we have implemented a new object named LenQueryField that uses the LEN function of the underlying RDBMS (see a sample code below).

var where = new LenQueryField("ColumnName", 3);
var connection = connection.Query<Entity>(where);

Then it should be able to generate the string below.

WHERE (LEN([ColumnName]) = @ColumnName);

And below is for the UPPER function.

var where = new UpperQueryField("ColumnName", "VALUE");
var connection = connection.Query<Entity>(where);

Which would generate the string below.

WHERE (UPPER([ColumnName]) = @ColumnName);

Additional Context

It is also very good if we can extend this logic for the users point of view. They might be interested on creating their own logic on top of it, of course with the proper formatting on the function.

Let us say we have this base class within RepoDB library.

public class FunctionalQueryField
{
     public TrimQueryField(string fieldName, string value, string formattedFunction)
     {
          ...
     }
}

Then the user should be able to inherit to provide their own logic. Below is a sample implementation.

public class TrimQueryField : FunctionalQueryField
{
     public TrimQueryField(string fieldName, string value)
     { }
     : base(fieldName, value, "TRIM{0}")
}

And they can use their own custom code.

var where = new TrimQueryField("ColumnName", "VALUE");
var connection = connection.Query<Entity>(where);

With this, the users can also create a much more advance/complex string generations.

public class ConvertQueryField : FunctionalQueryField
{
     public TrimQueryField(string fieldName, string value, Type targetType)
     { }
     : base(fieldName, value, "CONVERT({(new ClientTypeToDbTypeConverter().Resolve(targetType))}, {0})")
}
@mikependon mikependon added enhancement New feature or request todo Things to be done in the future labels Sep 16, 2021
@mikependon mikependon self-assigned this Sep 16, 2021
mikependon added a commit that referenced this issue Sep 16, 2021
mikependon added a commit that referenced this issue Sep 16, 2021
#899 Added the GetHashCode() methods. Renamed the functional classes …
mikependon added a commit that referenced this issue Sep 16, 2021
mikependon added a commit that referenced this issue Sep 18, 2021
#899 - place all the QueryField objects back into the Core library.
mikependon added a commit that referenced this issue Sep 19, 2021
#899 Added the Unit Tests for the newly created functional QueryField objects.
mikependon added a commit that referenced this issue Sep 23, 2021
#899 Added the FluentMapper.PropertyHandlerAttributes() Unit Tests.
@mikependon mikependon added deployed Feature or bug is deployed at the current release fixed The bug, issue, incident has been fixed. labels Sep 23, 2021
@mikependon
Copy link
Owner Author

This is now available on release v1.12.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed Feature or bug is deployed at the current release enhancement New feature or request fixed The bug, issue, incident has been fixed. todo Things to be done in the future
Projects
None yet
Development

No branches or pull requests

1 participant