General

Introduction to BrewwQL

25min

What is BrewwQL?

We designed BrewwQL to help users simply and powerfully filter their data in Breww.

With a few simple operators, you can now easily create simple or complex filters to drill down deeper and more easily into your Breww data.

BrewwQL can seem daunting at first, especially if you're new to "query languages", but the doors it opens to both reporting and customisability in Breww make it worth reading on! If you've built reporting using SQL before, then you'll be right at home.

Examples

Basic examples

To best understand BrewwQL, it's helpful to see some simple examples.

Let's say we wanted to see all of our customers whose delivery address was in London. In the customer filter form, we would type:

BrewwQL


And that's it. The autocomplete will show every option as you go, making it really straightforward to put together queries and view available options.

If we want to drill down deeper, we can. From those customers, maybe we only want to see those whose average order value is greater than £250. For this we would chain two statements together with the and operator.

BrewwQL


Perhaps we are wondering which of those customers have lapsed, as we might want to contact them about reordering. So let's narrow the search for only customers who haven't ordered in the last 90 days.

BrewwQL


Now let's say we are doing some admin, and we wanted to see all customers who we haven't entered a contact for yet. In the customer filter box, we would type:

BrewwQL


Advanced examples

BrewwQL allows us to traverse through attributes of what we are searching through. For example if we wanted to see customers who are part of a customer group with a billing address in London we would write:

BrewwQL


The . between customer_group and invoice_address_city is used in BrewwQL as a way of traversing through attributes of attributes.

We can also use brackets to add more complexity to our searches.

BrewwQL


The above statement will be analysed from left to right, and statements in brackets will be evaluated as a single attribute. So the query will retrieve all customers whose delivery address city is London OR who has an average order value greater than £250 ONLY if they also have a last order date more recent than 90 days ago.

We can also nest brackets within brackets. The below query will return either customers who are in London AND are Pubs, OR those whose average order value is greater than £250, as long as their last order date is more recent than 90 days ago.

BrewwQL


Using the same attribute multiple times

This can be a little confusing at first. Each statement between operators, must be complete and be able to work on its own. This means that if you're joining multiple filters together with and or or, like STATEMENT and STATEMENT, both statements must be complete on their own.

We'll walk through an example - when looking at product filtering, you could filter the type of product to only include casks with:

BrewwQL


Or you could filter kegs only with:

BrewwQL


Now, if you wanted to include both casks and kegs, you might be tempted (and understandably so), to do this:

BrewwQL


However, this is incorrect on two counts. The first being that each statement (each side of the and) must be a complete statement. Here, the type = "Cask" is perfect, but the second statement being just "Keg" is meaningless on its own, and so will not work. So, you can correct this to:

BrewwQL


This is much closer (and hopefully explains what's meant by each statement being a complete statement when looked at on its own). However, in this particular case, this isn't what's needed. We're looking for both cask and keg products, but this will be checked against each individual product, and any single product cannot be both a cask and a keg. The above is filtering on products which are both casks and kegs (which is impossible), so what we really need to check is if the product is either a cask or the product is a keg. And that can be done with:

BrewwQL


Success! The above would give the desired result or finding both cask products and keg products. If you wanted to make this a little neater (and maybe more readable), you could instead use the in operator to check if the product's type is in the list of options given. This would be done with:

BrewwQL


This is certainly more readable if the number of options were to increase from two to four (or even more):

BrewwQL


verses the more verbose:

BrewwQL


Dates

BrewwQL allows you to filter on dates and has a powerful natural language understanding. For example, if you'd like all customers who have ordered since the 1st January 2021, you can simply enter:

BrewwQL


or:

BrewwQL


or even:

BrewwQL


BrewwQL also understands relative dates, so you can filter on the last 30 days with:

BrewwQL


or filter on the last two months with:

BrewwQL


Some other useful options for date filtering include the phrases:

BrewwQL

BrewwQL

BrewwQL

BrewwQL

BrewwQL

BrewwQL

BrewwQL

BrewwQL

BrewwQL

BrewwQL


A date is greater > than another if it is more recent, and less < than another if it is older.

You can think of this as if someone started counting at the beginning of time. The number they had counted to last week is less than the number they have counted to right now.

To filter on a range of dates, you can use the same field twice:

BrewwQL


Case-sensitivity

Do capitals matter in my searches? No, a search for:

BrewwQL


and

BrewwQL


will return the same results.

Operator reference

Operator

Meaning

Example

Verbose

=

Equal to

name = "The Shop"

Where the name is equal to "The Shop"

!=

Not equal to

name != "The Shop"

Where the name is not equal to "The Shop"

~

Contains

name ~ "The"

Where the name contains "The"

!~

Does not contain

name !~ "The"

Where the name does not contain "The"

>

Greater than

average_order_value > 100

Where the average order value is greater than 100

>=

Greater than or equal to

average_order_value >= 100

Where the average order value is greater than or equal to 100

<

Less than

average_order_value < 100

Where the average order value is less than 100

<=

Less than or equal to

average_order_value <= 100

Where the average order value is less than or equal to 100

in

In

name in ("The Shop", "The Pub", "The Restaurant")

Where the name is either "The Shop" or "The Pub" or "The Restaurant"

not in

Not in

name not in ("The Shop", "The Pub", "The Restaurant")

Where the name is not "The Shop" and not "The Pub" and not "The Restaurant"