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 support for check constraints #24

Open
lycantropos opened this issue Sep 27, 2019 · 1 comment
Open

Add support for check constraints #24

lycantropos opened this issue Sep 27, 2019 · 1 comment
Assignees

Comments

@lycantropos
Copy link
Owner

We should add support for check constraints (both their generating & handling in records creation).

@lycantropos lycantropos added this to the Constraints support milestone Sep 27, 2019
@lycantropos lycantropos self-assigned this Sep 27, 2019
@lycantropos
Copy link
Owner Author

lycantropos commented Sep 28, 2019

I can see that like:

  1. If constraint's sqltext field is an SQLAlchemy expression, we can convert it to plaint string based on dialect using statement compiler like
dialect.statement_compiler(dialect, None).process(constraint.sqltext, 
                                                  include_table=False,
                                                  literal_binds=True)
  1. We need to parse string and obtain SQL AST (e.g. there are lark parser generator and SQL language BNF).
  2. Transform SQL AST to Python AST (e.g. x BETWEEN start AND end will become start <= x <= end).
  3. Build AST.Lambda with parameters corresponding to columns using compile.
  4. Use built lambda in strategy.filter.

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

No branches or pull requests

1 participant