> For the complete documentation index, see [llms.txt](https://mandarineframework.gitbook.io/mandarine-ts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mandarineframework.gitbook.io/mandarine-ts/mandarine-data/mandarine-query-language.md).

# Mandarine Query Language

{% hint style="info" %}
Understanding of [Mandarine's ORM concepts](https://mandarineframework.gitbook.io/mandarine-ts/mandarine-data/orm#concepts) is required for this article
{% endhint %}

## Main

Mandarine Query Language (MQL) serves as a helper to write queries. The main objective of MQL is to avoid the writing of SQL queries in your application's layer, and keep everything in a programatic environment. This is because, Mandarine.TS aims to respect [SOLID](https://en.wikipedia.org/wiki/SOLID) principles & follow MVC patterns as well as making your code as simple and readable as possible.

**Note** that MQL is written inside [repositories](https://mandarineframework.gitbook.io/mandarine-ts/mandarine-data/orm/repositories) &#x20;

## The lexical processor

MQL makes use of a lexical processor that will transform the names of your repositories' methods in *SQL & processable* queries.

```typescript
findByAirlineAndPassengerName(airline: string, passengerName: string)
```

Will be transformed into

```sql
SELECT * FROM MyTable WHERE airline = $1 AND passengerName = $2

# MyTable = Table of your model related to your repository 
# $1 = airline parameter
# $2 = passengerName parameter
```

## MQL Operators

Operators are keywords that will tell the *lexical processor* what type of operation is being requested at a SQL level.

Currently, MQL only supports the operators

* AND
* OR
* IsNotNull
* IsNull
* IsNotEmpty
* IsEmpty
* StartingWith
* EndsWith
* Like

Although, more operators are planned to be released. [Click here for more information](https://github.com/mandarineorg/mandarinets/issues/12).

## Definers

Definers are keywords that will shape your final SQL query. Definers are used for the lexical processor to identify what type of query is being or will be built.

### General definers

* `findAll`: Select all rows
* `deleteAll`: Delete all rows in entity
* `countAll`: Count all rows in entity
* `findBy...`: Creates & executes a select query
* `countBy...`: Creates & executes a select count query
* `existsBy...`: Creates & executes a verification statement
* `deleteBy...`: Creates & executes a delete query

### "Save" definer

In order to add ([or update](https://mandarineframework.gitbook.io/mandarine-ts/mandarine-data/orm/repositories/updating-data)) information to your entity in your database, MQL allows you to do so by using `save` [(Click here to see declaration) ](https://doc.deno.land/https/raw.githubusercontent.com/mandarineorg/mandarinets/master/orm-core/repository/mandarineRepository.ts#MandarineRepository)

* `save` is part of a native method of a mandarine repository.
* `save` takes one argument which will be a object of your repository's model with the data to be inserted

## Naming conventions

1. **Do** use camel case
2. **Do not** use underscores, or other characters that may affect readability.
3. The names of your columns **must** match the name of your parameter in your repository method. Otherwise, query execution will fail.
