-
-_name = object()
-def get_all(session, table, order=_name):
- """Shortcut to get an ordered query from table.
-
- session: The session to use
- table: The table to select from
- order: A clause to order by, or None for no ordering.
- The default is to order by name; this can also be specified explicitly
- with the table's name property (e.g. tables.Pokemon.name). Be aware
- that the query's order_by will not order by name this way.
- """
- query = session.query(table)
- if order is table.name or order is _name:
- query = order_by_name(query, table)
- elif order is not None:
- query = query.order_by(order)
- return query
-
-### Shortcuts
-
-def pokemon(session, order=tables.Pokemon.id):
- """Return a query for all base form pokemon, ordered by id by default
-
- See get_all for the session and order arguments (but note the default for
- pokemon is to order by id).
- """
- query = get_all(session, tables.Pokemon, order=order)
- query = query.filter(tables.Pokemon.forms.any())
- return query
-
-def moves(session, order=_name):
- """Return a query for moves in the mainline games (i.e. no Shadow moves)
-
- See get_all for the session and order arguments.
- """
- return get_all(session, tables.Move, order=order).filter(tables.Move.id < 10000)
-
-def types(session, order=_name):
- """Return a query for sane types (i.e. not ???, Shadow)
-
- See get_all for the session and order arguments.
- """
- return get_all(session, tables.Type, order=order).filter(tables.Type.id < 10000)
-
-def items(session, order=_name):
- """Return a query for items
-
- See get_all for the session and order arguments.
- """
- return get_all(session, tables.Item, order=order)