Skip to content

Comparison Operators

Laran Evans edited this page Mar 29, 2016 · 3 revisions
GQL JSON SQL meaning
: $eq = equals
> $gt > is greater than
>= $gte >= is greater than or equal to
< $lt < is less than
<= $lte <= is less than or equal to
~ $like LIKE is like (used with % in the attribute value)

Examples

GQL JSON SQL
published_at:>\'2016-03-04\' {published_at: {$gt: '2016-03-04'}} WHERE published_at > '2016-03-04'

Date values in GQL

Date values can be represented as either LITERALS or STRINGS.

For example: created_at:\'2016-03-01\' and created_at:2016-03-01 are equivalent and both are valid.

Date values in the JSON API

Date values are supported as values via the JSON API to the extent that Knex supports them. Issues around timezones, etc. should be handled however Knex requires them to be handled.

Dates as strings can be converted to Date objects using transformers.

Like comparisons

GQL JSON SQL Meaning
foo:~%bar% {foo: {$like: '%bar%'}} WHERE foo LIKE '%bar%' foo contains 'bar' (anywhere)
foo:~%bar {foo: {$like: '%bar'}} WHERE foo LIKE '%bar' foo ends with 'bar'
foo:~bar% {foo: {$like: 'bar%'}} WHERE foo LIKE 'bar%' foo starts with 'bar'

IN comparisons

IN clauses are indicated by a Value that is an array.

Examples

GQL JSON SQL
title:[introduction, overview] {title: ['introduction', 'overview']} WHERE title IN ('introduction', 'overview')

Read about how to Negate a comparison.

Clone this wiki locally