It was obvious when I looked at the official documentation. filter_by(),filter() In conclusion, fileter_by () seems to have the advantage of shorter code.
filter (): {model}. {variable name} can add table column value to search condition filter_by (): Column value can be added to the search condition only with {variable name} without model
It is easy to understand if you look at the code, so if you specify it
# filter()Description example when using
session.query(MyClass).\
filter(MyClass.name == 'some name', MyClass.id > 5)
# filter_by()Description example when using
session.query(MyClass).\
filter_by(name = 'some name', id > 5)
Personally, fileter_by can be written shorter, so I thought it would be convenient.
If anyone knows how to use filter (), which is useful when saying this, I would be grateful if you could let me know in the comments.
Recommended Posts