---
schema_version: "1"
id: 5ca5b47f7d6e58a9bd5be69118198a1dc8c160bdc79a00fd17a59e1172bd4f12
title: Transforming an OData Request to a SQL Query
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/apikit/latest/apikit-odatav4-transform-to-sql-operation.md
canonical_url: https://docs.mulesoft.com/apikit/latest/apikit-odatav4-transform-to-sql-operation
source_site: docs.mulesoft.com
content_type: documentation
content_hash: efbd6b1a4e674f2f244be5f8182739cbae28973f31214c58d6bd8537d6736fce
description: MuleSoft Documentation Site
release: 4.x
latest: true
---
---
product: APIkit
version: 4.x
is-latest-version: true
---

# Transforming an OData Request to a SQL Query

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

The `Transform to SQL Select` operation turns an inbound OData `GET` into an SQL `SELECT` with bound
parameters you pass to the Database Connector. Pair it with the connector’s `select` operation to
expose relational data through OData v4 without hand-writing SQL for every query. The message
payload is the prepared statement text; attributes carry the parameter map the database driver
expects.

![\*Transform to SQL select\* element and \*Entity set name\* field highlighted](/mulesoft/current/en-us/apikit/latest/_images/transform-to-sql-transformer.png)

The output payload is a prepared statement and the attributes are a map of prepared statement
parameters.

![\*Select database\* and \*Input Parameters\* field highlighted](/mulesoft/current/en-us/apikit/latest/_images/add-db-transform-to-sql.png)

You can use this operation with the Database connector to expose databases that use OData V4.

![\*Serialized entity\* element and the \*Inbound content\* field highlighted](/mulesoft/current/en-us/apikit/latest/_images/serialize-transform-to-sql.png)

APIkit supports these OData request elements:

- System query options:

  - $filter

  - $select

  - $search

  - $orderby

  - $skip

  - $top

- Single entity

- Entity relation

- Server-side pagination

APIkit does not support:

- Parameter Aliases

- Built-in Filter Operations:

  - has

  - divby

- Built-in Query Functions, all except:

  - contains

  - startswith

  - endwith

- $apply

- $compute

- $expand

## Transform to SQL Select Operation in OData V4

The OData protocol defines a series of conventions that enable clients to query identified resources
by using URLs. The list of queryable entities, their fields, and the relationships between them are
defined in a data model by using HTTP messages. OData shares some similarities with Java database
connectivity (JDBC). The `transform-to-sql-select` operation uses such similarities to help you
create SQL queries for the resources. The operation results in a message that has a prepared
statement with the SQL `select` sentence as the payload and the parameters name and values map as
the attributes.

## Implement the Transform to SQL Select Operation by Using APIkit for OData V4

You can implement the transform to SQL operation by using the
`<apikit-odata:transform-to-sql-select>` XML element, which has the following parameters:

<table><colgroup><col> <col></colgroup><thead><tr><th>Parameter name</th><th>Description</th></tr></thead><tbody><tr><td><p>Display name</p></td><td><p>Name of the operation.</p></td></tr><tr><td><p>Module configuration</p></td><td><p>Name of the related-module configuration.</p></td></tr><tr><td><p>Entity set name</p></td><td><p>Name of the entity set to fetch #[attributes.entitySetName].</p></td></tr><tr><td><p>Page size</p></td><td><p>Number that defines the amount of results per page during server-side pagination.</p></td></tr><tr><td><p>Entity type name</p></td><td><p>String obtained from the OData request by using #[attributes.odataRequestAttributes], which the entity data model specifies.</p></td></tr><tr><td><p>Entity type fields</p></td><td><p>Array of strings obtained from the OData request by using #[attributes.odataRequestAttributes], which provides the list of property fields obtained from the entity type.</p></td></tr><tr><td><p>Entity type keys</p></td><td><p>Object obtained from the OData request by using #[attributes.odataRequestAttributes], which provides a map of entity key names and values.</p></td></tr><tr><td><p>System query options</p></td><td><p>Parameter obtained from the OData request by using #[attributes.odataRequestAttributes].</p></td></tr><tr><td><p>Search transformation enabled</p></td><td><p>If <code>true</code>, this option enables the $search transformation option for a WHERE clause.</p></td></tr><tr><td><p>Strict search term match</p></td><td><p>If <code>true</code>, this option enables full term matching for $search. If enabled, terms in the WHERE clause aren’t enclosed between '%'.</p></td></tr><tr><td><p>SQL identifiers delimiter</p></td><td><div><div><p>Option that delimits identifiers in the generated SQL statement (Options: DOUBLE_QUOTES, BRACKETS, and BACK_TICKS).</p></div><div><p>Examples:</p></div><div><ul><li><p>DOUBLE_QUOTES: <code>SELECT "TrackId", "Name" FROM "Tracks"</code></p></li><li><p>BRACKETS: <code>SELECT [TrackId], [Name] FROM [Tracks]</code></p></li><li><p>BACK_TICKS: <code>SELECT `TrackId`, `Name` FROM `Tracks`</code></p></li></ul></div></div></td></tr><tr><td><p>SQL limit rows</p></td><td><div><div><p>Option that limits the numbers of rows (Options: LIMIT and FETCH_NEXT_ROWS_ONLY).</p></div><div><p>Examples:</p></div><div><ul><li><p>LIMIT: <code>SELECT OrderID, ShippedDate, ShipCountry FROM Orders LIMIT :parameter1</code></p></li><li><p>FETCH_NEXT_ROWS_ONLY: <code>SELECT OrderID, ShippedDate, ShipCountry FROM Orders ORDER BY OrderID ASC OFFSET :parameter2 ROWS FETCH NEXT :parameter1 ROWS ONLY</code></p></li></ul></div><div><p><code>ORDER BY</code> is automatically included if not present in the request by using the entity key defined in CSDL.</p></div></div></td></tr><tr><td><p>Date Transform Type</p></td><td><div><div><p>Values provided, one of:</p></div><div><ul><li><p>String: <code>Date</code> or <code>DateTimeOffset</code> parameters pass as <code>string</code> (default value).</p></li><li><p>java.time - LocalDate and LocalDateTime: <code>Date</code> or <code>DateTimeOffset</code> parameters pass as objects of <code>java.time</code> package classes <code>LocalDate</code> and <code>LocalDateTime</code>. This option enables most DB drivers -such as MySQL- to identify and process <code>Date/DateTime</code> parameters and return the correct result.</p></li><li><p>java.time - LocalDate and OffsetDateTime: <code>Date</code> or <code>DateTimeOffset</code> parameters pass as objects of <code>java.time</code> package classes <code>LocalDate</code> and <code>OffsetDateTime</code>. This option enables most DB drivers -such as Oracle- to identify and process <code>Date</code>, <code>Timestamp</code>, and <code>Timestamp with Time Zone</code> parameters and return the correct result.</p></li></ul></div><div><p>This operation takes the <code>Date/DateTime</code> values as strings by default. Select one of the <code>java.time object</code> options to output it as a corresponding <code>Date</code> or <code>DateTime</code> object in the <code>java.time</code> package.</p></div></div></td></tr></tbody></table>

## $filter Expressions in OData V4

​​The OData `$filter` expression uses comparison, logical, arithmetic, and grouping operators. For a
list of operators and their meaning, see
[the OData4 Specification](https://docs.oasis-open.org/odata/odata/v4.01/cs01/part1-protocol/odata-v4.01-cs01-part1-protocol.html).

APIkit does not support the `has` and `divby` operators.

## Expressions Supported by Transform to SQL Select

For the filtering expressions that OData supports, see the
[specification](https://docs.oasis-open.org/odata/odata/v4.01/cs01/part1-protocol/odata-v4.01-cs01-part1-protocol.html).

The `transform-to-sql-select` operation supports the following subset of unary and binary operators,
and the following method operators.

<table><colgroup><col> <col></colgroup><thead><tr><th>OData Operator</th><th>SQL Operator</th></tr></thead><tbody><tr><td><p>add</p></td><td><p>+</p></td></tr><tr><td><p>and</p></td><td><p>AND</p></td></tr><tr><td><p>div</p></td><td><p>/</p></td></tr><tr><td><p>eq</p></td><td><p>=</p></td></tr><tr><td><p>ge</p></td><td><p>&gt;=</p></td></tr><tr><td><p>gt</p></td><td><p>&gt;</p></td></tr><tr><td><p>le</p></td><td><p>=&lt;</p></td></tr><tr><td><p>lt</p></td><td><p>&lt;</p></td></tr><tr><td><p>mod</p></td><td><p>%</p></td></tr><tr><td><p>mul</p></td><td><p>*</p></td></tr><tr><td><p>ne</p></td><td><p>&lt;&gt;</p></td></tr><tr><td><p>or</p></td><td><p>OR</p></td></tr><tr><td><p>sub</p></td><td><p>-</p></td></tr><tr><td><p>not</p></td><td><p>NOT</p></td></tr><tr><td><p>-</p></td><td><p>-</p></td></tr><tr><td><p>contains</p></td><td><p>LIKE %value%</p></td></tr><tr><td><p>startswith</p></td><td><p>LIKE value%</p></td></tr><tr><td><p>endswith</p></td><td><p>LIKE %value</p></td></tr></tbody></table>

## $search Support

This operation builds a `WHERE` clause based on the `$search` expression that the system query
option provides. The implementation selects all of the elements that have property values that match
the condition.

By default, a term matches if the field value contains the term. If the `strict search term match`
is set to `true` in the configuration, the `search` operation requires an exact match between the
field value and the search term.

The `search transformation enabled` and `strict search term match` parameters define the `$search`
feature.

## See Also

- [APIkit for OData v4 Module Reference](https://docs.mulesoft.com/apikit/latest/apikit-odatav4-extension-reference)

- [APIkit for OData v4 Error Handling Reference](https://docs.mulesoft.com/apikit/latest/apikit-odatav4-error-handling-reference)
