Jump to content

I made a class for building the query strings


PeterH

Recommended Posts

I like the API but I'm not a huge fan of writing the queries as text, so I made something a while back using inspiration from SQLAlchemy.

As a very quick example, if the original code is this:

episode = session.query('Episode').first()
task_link = session.query('select link from Task where (name not like "%task%" or name is "new") and parent.id is "{}" order by name descending'.format(episode['id'])).first()

It would be constructed like this:

task_link = session.Task.where(
    or_(~entity.name.like('%task%'), name='new'),
    parent=session.Episode.first(),
).select(entity.link).sort(entity.name.desc()).first()

It's able to do everything I've come across so far, if anyone is interested in using it the github page is here.

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...