Skip to content

Instantly share code, notes, and snippets.

@numberoverzero
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save numberoverzero/3e397b26134c0a0121f8 to your computer and use it in GitHub Desktop.

Select an option

Save numberoverzero/3e397b26134c0a0121f8 to your computer and use it in GitHub Desktop.
Sample syntax for various query operations
# Single hash key, multiple filters
# =================================
# Pure condition syntax, no **kwargs overloading
# ----------------------------------------------
q = engine.query(Forum)
.key(Forum.name == "S3")
.filter(Forum.subscribers > MIN_SUBSCRIBERS,
Forum.views >= MIN_VIEWS)
# Only overload **kwargs, no condition syntax
#--------------------------------------------
q = engine.query(Forum)
.key(name="S3")
.filter(subscribers=GT(MIN_SUBSCRIBERS),
views=GE(MIN_VIEWS))
# Hash and Range keys, single filter
# =================================
# Pure condition syntax, no **kwargs overloading
# ----------------------------------------------
q = engine.query(Thread)
.key(Thread.forum_name == "S3",
Thread.subject.between("Hello", "World"))
.filter(Thread.replies >= MIN_REPLIES)
# Only overload **kwargs, no condition syntax
#--------------------------------------------
q = engine.query(Thread)
.key(forum_name="S3",
subject=between("Hello", "World"))
.filter(replies=GE(MIN_REPLIES))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment