Created
September 14, 2012 15:47
-
-
Save tell-k/3722779 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# AND OR とかも直感的に使える | |
from sqlalchemy.sql.expression import * | |
# AND | |
Entry.query.filter(and_(Entry.id == 1, Entry.text == "entry")).all() | |
# => SELECT * FROM entries WHERE entries.id = 1 AND entries.text = "entry" | |
# OR | |
Entry.query.filter(or_(Entry.id == 1, Entry.text == "entry")).all() | |
# => SELECT * FROM entries WHERE entries.id = 1 OR entries.text = "entry" | |
# IN | |
Entry.query.filter(Entry.id.in_([1, 2, 3])).all() | |
# => SELECT * FROM entries WHERE entries.id IN (1, 2, 3) | |
# NOT IN | |
Entry.query.filter(not_(Entry.id.in_([1, 2, 3]))).all() | |
# => SELECT * FROM entries WHERE entries.id NOT IN (1, 2, 3) | |
# LIKE | |
Entry.query.filter(Entry.text.like("ent%")).all() | |
# => SELECT * FROM entries WHERE entries.id LIKE "ent%" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment