-
-
Notifications
You must be signed in to change notification settings - Fork 57
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 support for database functions #224
Comments
Currently, the only possible way to do this is by using Fragment in the query This could be a nice addition, maybe we need to think REL API (how to integrate it to existing api) to support them first, do you have anything in mind? |
Probably need to add something like // function could be subpackage like where currently is
function.Substring(rel.FilterField("field_name"), rel.FilterValue(1), rel.FilterValue(10)) rel.FilterField: return FilterQuery{
Type: FilterFieldOp,
Field: name,
} rel.FilterValue: return FilterQuery{
Type: FilterValueOp,
Value: value,
} rel.FilterFunction: return FilterQuery{
Type: FilterFunctionOp,
Field: name,
Inner: args,
} |
and in builder it would be needed some kind of callback like for column map that would provide arguments:
and callback function would return built SQL to be written in buffer |
btw
while this is possible also with |
I think specifying
this is actually possible, using fragment or not, just add |
But it will not escape at all rel.FilterFragment: https://github.com/go-rel/sql/blob/36066d80a50a7aaa9a4532df23de99e254a5310c/builder/filter.go#L45 it would be useful to HAVE a way to escape with |
while I agree this is verbose but it's most easiest way to implement and have flexibility that this provides. As you could have also complex expressions like: function.Upper(
function.Substring(
rel.FilterField("field_name"),
rel.FilterValue(1),
function.Least(rel.FilterField("some_other_field), rel.FilterValue(10)),
),
) |
I did something similar in the previous reincarnation of this library, and the code get messy easily I can't always control and suggest how other use the API, so I learn that I need to limit and teach it by design |
that might be an option |
Do I understand correctly that the main problem is maintaing the same type safe (more or less) API? Now that generics are out, they won't help that much, unfortunately. If we're striving for supporting something like However in case of non-variadic functions, we can parameterize by The multi-argument cases only could be handled with |
Would be nice to have ability to specify some common functions in filters and default values.
At least few I can think of:
substring ( string text [ FROM start integer ] [ FOR count integer ] )
substring ( expression, start, length )
Probably some others and have adapter to build them as on different databases this can be different
The text was updated successfully, but these errors were encountered: