Can I use lambda to create a query in SQLAlchemy?
I need to implement a function that takes a lambda as the argument and queries the database. I use SQLAlchemy for ORM. Is there a way to pass the lambda, that my function receives, to SQLAlchemy to开发者_JAVA百科 create a query?
Sincerely, Roman Prykhodchenko
I guess you want to filter the data with the lambda, like a WHERE clause? Well, no, functions nor lambdas cannot be turned into a SQL query. Sure, you could just fetch all the data and filter it in Python, but that completely defeats the purpose of the database.
You'll need to recreate the logic you put into the lambda with SQLAlchemy.
精彩评论