Support queries in patterns

closes #11