lycantropos / hypothesis_sqlalchemy

hypothesis strategies for generating SQLAlchemy objects
MIT License
28 stars 8 forks source link

Add support for check constraints #24

Open lycantropos opened 4 years ago

lycantropos commented 4 years ago

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

lycantropos commented 4 years ago

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)
  2. We need to parse string and obtain SQL AST (e.g. there are lark parser generator and SQL language BNF).
  3. Transform SQL AST to Python AST (e.g. x BETWEEN start AND end will become start <= x <= end).
  4. Build AST.Lambda with parameters corresponding to columns using compile.
  5. Use built lambda in strategy.filter.