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

added about_equal function for sqlalchemy #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dmtvanzanten
Copy link

I created this PR mostly to share my code and not so much as to have it actually implemented into the master. I the knowledge to write the same implementation for the SQL and Django backends and I realize that that is a requirement for this functionality to be considered. I hope someone will be able to add this functionality for those backends as well.

For now I will just proceed using

from odata_query.grammar import ODataParser, ODataLexer, ODATA_FUNCTIONS
from odata_query.sqlalchemy.common import _CommonVisitors
from odata_query import ast
from sqlalchemy import func
from sqlalchemy.sql import functions
import operator

ODATA_FUNCTIONS['aboutequal'] = 3

def func_aboutequal(self, field: ast._Node, value: ast._Node, tolerance: ast._Node) -> functions.Function:
    ":meta private:"
    field = self.visit(field)
    value = self.visit(value)
    tolerance = self.visit(tolerance)
    return operator.lt(func.abs(operator.sub(field, value)), tolerance)  

_CommonVisitors.func_aboutequal = func_aboutequal

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.

1 participant