News for hackers. Stuff that matters.
Re:A DSL in 5 Languages: Ruby, Python, PHP, C#, Java by i2 on Tuesday August 03, 2010 @01:51PM (#1572014)
You can make it without any 'weaknesses' in Python:

  collection = Transaction.search(
      order_id__starts_with='a2d',
      customer_website__ends_with='.com',
      billing__first_name__exact='John',
      status__in=[
        Transaction.Status.Authorized,
        Transaction.Status.Settled
      ],
      amount__between=("10.00", "20.00")
  )
the implementation could look like this:

  def search(**kwargs):
      for arg, value in kwargs.items():
          action = arg.split('__')
          attr = getattr(self, action[0])
          if len(action) == 2:
              method = getattr(attr, action[1])
              method(value)
          etc.
          .....
EDIT: removed unneeded quotes, thanks for correction, postfuturist
Re:A DSL in 5 Languages: Ruby, Python, PHP, C#, Java by drewolson on Wednesday August 04, 2010 @02:40PM (#1575381)
When we began building our Python library, we looked at both django[1] and sqlalchemy[2] for inspiration in designing our search DSL. Your example seems to closely match the django style. We preferred the sqlalchemy style, but both are solid choices.

[1]http://docs.djangoproject.com/en/1.2/topics/db/queries/#chai... [2]http://www.sqlalchemy.org/docs/ormtutorial.html#common-filte...

Re:A DSL in 5 Languages: Ruby, Python, PHP, C#, Java by postfuturist on Tuesday August 03, 2010 @02:47PM (#1572217)
Good suggestion. Also, the quotes aren't necessary on the keys of the keyword arguments:

  collection = Transaction.search(
      order_id__starts_with='a2d',
      customer_website__ends_with='.com',
      billing__first_name__exact='John',
      status__in=[
        Transaction.Status.Authorized,
        Transaction.Status.Settled
      ],
      amount__between=("10.00", "20.00")
  )
Re:A DSL in 5 Languages: Ruby, Python, PHP, C#, Java by koenigdavidmj on Wednesday August 04, 2010 @02:19AM (#1573808)
Is that really idiomatic other than for people used to Django's ORM?