LunaQL docs are incomplete.
How To
Operators

Operators

Operators allow you to control how you query your documents. You can use these operators to filter out documents.

We can use these operators in conjunction with the where clause or the having clause:

posts.lunaql
query({
	from({
		posts: {
			where(["created_at", ">=", "2022"]);
		};
	});
});

In the example above, we're using the >= operator to fetch all posts that were created in 2022 or after that.

Comparison Operators

Equal To

To check if a value is matches specified value, you can use the =, == or === operators:

users.lunaql
query({
	from({
		users: {
			where(["first_name", "==", "Donald"]);
		};
	});
});

This will return all the user documents where the first_name is "Donald".

OptionTypeDescription
=string | numberEqual to (type safe).
===string | numberEqual to (type safe).
==string | numberEqual to (type unsafe).

Not Equal To

To check if a value does not match specified value, you can use the !=, !== or <> operators:

users.lunaql
query({
	from({
		users: {
			where(["city", "!==", "Cape Town"]);
		};
	});
});

This will return all user documents where the city is not "Cape Town".

OptionTypeDescription
!=string | numberNot equal to (type safe).
!==string | numberNot equal to (type safe).
<>string | numberNot equal to (type unsafe).

Geater Than

To check if a value is greater than another value, you can use the > or >= operators:

users.lunaql
query({
	from({
		users: {
			where(["age", ">", 17]);
		};
	});
});

This will return all user documents where the age is greater than "17".

OptionTypeDescription
>number | timestampGreater than.
>=string | numberGreater than or equals to.

Less Than

To check if a value is less than another value, you can use the < or <= operators:

users.lunaql
query({
	from({
		users: {
			where(["created_at", "<=", 2020]);
		};
	});
});

This will return all user documents that where created before "2021".

OptionTypeDescription
<number | timestampLess than.
<=number | timestampLess than or equals to.

Logical Operators

Like

To check if a value partially matches another value, you can use the LIKE, or NOT LIKE operators:

cities.lunaql
query({
	from({
		cities: {
			where(["name", "LIKE", "C%"]);
		};
	});
});

This will return all city documents where the name starts with the letter "C".

OptionTypeDescription
LIKEstring | numberWhere value is like.
NOT LIKEstring | numberWhere value is not like.

In

To check if a value matches a list of values, you can use the IN, or NOT IN operators:

users.lunaql
query({
	from({
		users: {
			where(["name", "IN", ["Donald", "Luna"]]);
		};
	});
});

This will return all user documents where the name is either "Donald" or "Luna".

OptionTypeDescription
INstring[] | number[]Where value is in a list.
NOT INstring[] | number[]Where value is not in a list.

Between

To check if a value is in between 2 values, you can use the BETWEEN, or NOT BETWEEN operators:

users.lunaql
query({
	from({
		users: {
			where(["age", "BETWEEN", [17, 26]]);
		};
	});
});

This will return all user documents where the age is between "17" and "26".

OptionTypeDescription
BETWEENnumber[]Where value is between a list.
NOT BETWEENnumber[]Where value is not between a list.