Azure / Azure/data-api-builder

[Enh]: Add basic string $filter functions

Offen
#3,240 0 Kommentare 8 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
2.x graphql mcp-server rest
Vorherrschende Sprache
C#
Sterne
1.5k
Forks
370
Ø Merge
3 T. 22 Std.
Gemergte PRs (30 T.)
9

Beschreibung

## What?

DAB lacks common string filter functions that developers expect when querying text fields. This proposal introduces a minimal and consistent set of string filtering capabilities.

## Why?

Finding specific records today requires creating stored procedures to perform text filtering. This is unnecessary friction for basic scenarios such as searching titles, descriptions, or message content.

Adding these operators enables common filtering patterns without requiring custom SQL while keeping the same query semantics across REST, GraphQL, and MCP.

### Important

The MCP implementation is both in `read-records` and `aggregate-records`.

## How?

## Keywords

### contains

Returns rows where the column contains the specified substring.

REST
`GET /api/Articles?$filter=contains(title,'Fabric')`

GraphQL

```
query {
articles(filter: { title: { contains: "Fabric" } }) {
id
title
}
}
```

TSQL

```
SELECT id, title
FROM dbo.Articles
WHERE title LIKE '%Fabric%'
```

PostgreSQL

```
SELECT id, title
FROM "Articles"
WHERE title LIKE '%Fabric%'
```

MySQL

```
SELECT id, title
FROM Articles
WHERE title LIKE '%Fabric%'
```

Cosmos DB (NoSQL SQL API)

```
SELECT c.id, c.title
FROM c
WHERE CONTAINS(c.title, "Fabric")
```

### startsWith

Returns rows where the column begins with the specified substring.

REST
`GET /api/Articles?$filter=startswith(title,'Fabric')`

GraphQL

```
query {
articles(filter: { title: { startsWith: "Fabric" } }) {
id
title
}
}
```

TSQL

```
SELECT id, title
FROM dbo.Articles
WHERE title LIKE 'Fabric%'
```

PostgreSQL

```
SELECT id, title
FROM "Articles"
WHERE title LIKE 'Fabric%'
```

MySQL

```
SELECT id, title
FROM Articles
WHERE title LIKE 'Fabric%'
```

Cosmos DB (NoSQL SQL API)

```
SELECT c.id, c.title
FROM c
WHERE STARTSWITH(c.title, "Fabric")
```

### endsWith

Returns rows where the column ends with the specified substring.

REST
`GET /api/Articles?$filter=endswith(title,'SQL')`

GraphQL

```
query {
articles(filter: { title: { endsWith: "SQL" } }) {
id
title
}
}
```

TSQL

```
SELECT id, title
FROM dbo.Articles
WHERE title LIKE '%SQL'
```

PostgreSQL

```
SELECT id, title
FROM "Articles"
WHERE title LIKE '%SQL'
```

MySQL

```
SELECT id, title
FROM Articles
WHERE title LIKE '%SQL'
```

Cosmos DB (NoSQL SQL API)

```
SELECT c.id, c.title
FROM c
WHERE ENDSWITH(c.title, "SQL")
```

### regex

Returns rows where the column matches the specified regular expression pattern. SQL Server support exists in SQL Server 2025, Azure SQL Database, Azure SQL Managed Instance, and SQL database in Microsoft Fabric through `REGEXP_LIKE`, and it requires compatibility level 170. PostgreSQL supports POSIX regex with the `~` operator. MySQL supports regex with `REGEXP_LIKE()` and `REGEXP`/`RLIKE`. Azure Cosmos DB for NoSQL supports `RegexMatch()`. ([[Microsoft Learn](https://learn.microsoft.com/en-us/sql/t-sql/functions/regexp-like-transact-sql?view=sql-server-ver17&utm_source=chatgpt.com)][1])

REST
`GET /api/Articles?$filter=regex(title,'SQL$')`

GraphQL

```graphql
query {
articles(filter: { title: { regex: "SQL$" } }) {
id
title
}
}
```

TSQL

```sql
SELECT id, title
FROM dbo.Articles
WHERE REGEXP_LIKE(title, 'SQL$')
```

PostgreSQL

```sql
SELECT id, title
FROM "Articles"
WHERE title ~ 'SQL$'
```

MySQL

```sql
SELECT id, title
FROM Articles
WHERE REGEXP_LIKE(title, 'SQL$')
```

Cosmos DB (NoSQL SQL API)

```sql
SELECT c.id, c.title
FROM c
WHERE RegexMatch(c.title, "SQL$")
```

[1]: https://learn.microsoft.com/en-us/sql/t-sql/functions/regexp-like-transact-sql?view=sql-server-ver17&utm_source=chatgpt.com "REGEXP_LIKE (Transact-SQL) - SQL Server"

### Configuration

```json
{
"data-source": {
"options": {
"allow-regular-expressions": true // default: true
}
}
}
```

This property lets developers explicitly enable or disable regular expression support for filtering operations. The reason a developer might disable regex is to prevent expensive pattern matching queries that can create unpredictable performance or increase database load.

```
Regular expression filtering is not supported by the configured data source.
```

#### Important

In addition, during startup, the engine also validates the capabilities of the configured data source. If the connected database version does not support regular expressions, the runtime automatically **forces** this setting to `false` to prevent unsupported operations from being exposed.

### Command Line

```bash
dab configure --data-source.options.allow-regular-expressions true
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit nachzuverfolgen, wie Filter über die REST-, GraphQL- und MCP-Einstiegspunkte read-records und aggregate-records hinweg geparst und übersetzt werden. Prüfe die Validierung der Fähigkeiten der Datenquelle und das aufgeführte datenbankspezifische Abfrageverhalten, bevor du den Umfang der Operatoren und der Konfiguration festlegst. Erledigt ist die Aufgabe, wenn die dokumentierten Verhaltensweisen von contains, startsWith, endsWith und regex überall, wo sie unterstützt werden, konsistent funktionieren und die Regex-Konfiguration sowie die Behandlung nicht unterstützter Datenbanken durchgesetzt werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp, graphql, mysql, postgresql, sql
Bereich
api, backend-api-design, cli, databases
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.