Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. ```python
  2.  
  3. q = QueryTool()
  4.  
  5. # Group filter
  6. # Using the same thing than SQL Alchemy
  7. q.filter_group("group1", "group2") # group1 AND group2
  8. q.filter_group(or_("group1", "group2")) # group1 OR group2
  9. q.filter_group(not_("group1")) # NOT group1
  10. # Is there a need to do group1 AND (group2 OR NOT group3) ?
  11.  
  12. # Node type filter: support of basic boolean expr ?
  13. q.filter_class(Calculation) # using class or string ?
  14. q.filter_class(not_(Calculation))
  15. q.filter_class(Calculation, ParameterData) # OR statement, AND doesn't make
  16. # sense here
  17.  
  18. # We either use kwargs to filter, or we implement custom method: filter_owner,
  19. # filter_time, filter_label. Might conflict if we implement querying on other
  20. # part of the DB later on.
  21. q.filter_node(type="..", owner="..") # Owner: using an user id, email, first/last name ?
  22. q.filter_node(label=or_("truc1", "truc2"), owner=or_("user1", "user2"))
  23. # Time
  24. q.filter_node(time=("from", "to"))
  25. q.filter_node(time=or_(("from", "to"), ("from", "to")))
  26. or q.filter_node(time(from=.., to=..))
  27. q.filter_node(or_(time(from=.., to=..), time(from=.., to=..)))
  28.  
  29. # Attribute filter (same for extra, but filter_extra instead)
  30. q.filter_attr("attr_name", "<=", 0., label=.., on="inputs", prefetch=True) # self explanatory
  31. q.filter_attr("attr_name", "<=", 0., on="parents", label=.., depth=5) # Filter with a max depth
  32.  
  33. # Prefetching
  34. q.prefetch("attr_name", on="relation") # Relation being input or output, that is
  35. # only one depth more. Still have to think what prefetching could look like with
  36. # more than 1 depth, if we allow more than one depth.
  37.  
  38. # Placeholder: used in selecting stuff like atoms.*.0, and disallow dots in the *
  39. # placeholder.
  40. q.filter_attr("atoms.*.0", "=", "O")
  41.  
  42. # Query chaining
  43. # Still have to define what it should be.
  44. q1 = QueryTool()
  45. # .. operations on q1
  46. q2 = QueryTool()
  47. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement