# 查詢 (https://nolantw.github.io/tdx/reference/query/)

## `Query`

```python
class Query:
    filters: tuple[Filter[M], ...]
    orders: tuple[Order[M], ...]
    spatial: str | None
```

一個模型的 OData 查詢。

### `where`

```python
def where(*filters: Filter[M]) -> Self
```

只保留符合所有條件的資料。

### `order_by`

```python
def order_by(*orders: Order[M]) -> Self
```

依指定順序排序。

### `near`

```python
def near(
    position: FieldPath[M],
    *,
    longitude: float,
    latitude: float,
    radius: float,
) -> Self
```

只保留座標 `radius` 公尺內的資料。

### `to_params`

```python
def to_params() -> dict[str, str]
```

轉換為 OData 查詢參數。

## `QueryParams`

```python
type QueryParams = Mapping[str, str | int | float | bool] | httpx2.QueryParams
```

## `Filter`

```python
class Filter:
    expression: str
```

條件，可用 `&`、`|`、`~` 組合。

## `Order`

```python
class Order:
    expression: str
```

## `FieldPath`

```python
class FieldPath:
    path: str
```

欄位在資料中的位置。

### `is_null`

```python
def is_null() -> Filter[M]
```

### `asc`

```python
def asc() -> Order[M]
```

### `desc`

```python
def desc() -> Order[M]
```

### `child`

```python
def child(name: str) -> str
```

取得下一層欄位的位置。

## `BooleanField`

```python
class BooleanField(FieldPath[M]):
    ...
```

布林欄位。

### `eq`

```python
def eq(value: bool) -> Filter[M]
```

## `TextField`

```python
class TextField(FieldPath[M]):
    ...
```

文字欄位。

### `eq`

```python
def eq(value: str) -> Filter[M]
```

### `ne`

```python
def ne(value: str) -> Filter[M]
```

### `one_of`

```python
def one_of(*values: str) -> Filter[M]
```

### `contains`

```python
def contains(value: str) -> Filter[M]
```

### `startswith`

```python
def startswith(value: str) -> Filter[M]
```

### `endswith`

```python
def endswith(value: str) -> Filter[M]
```

### `gt`

```python
def gt(value: str) -> Filter[M]
```

### `ge`

```python
def ge(value: str) -> Filter[M]
```

### `lt`

```python
def lt(value: str) -> Filter[M]
```

### `le`

```python
def le(value: str) -> Filter[M]
```

## `NumberField`

```python
class NumberField(FieldPath[M]):
    ...
```

數值欄位。

### `eq`

```python
def eq(value: float) -> Filter[M]
```

### `ne`

```python
def ne(value: float) -> Filter[M]
```

### `one_of`

```python
def one_of(*values: float) -> Filter[M]
```

### `gt`

```python
def gt(value: float) -> Filter[M]
```

### `ge`

```python
def ge(value: float) -> Filter[M]
```

### `lt`

```python
def lt(value: float) -> Filter[M]
```

### `le`

```python
def le(value: float) -> Filter[M]
```

## `TimeField`

```python
class TimeField(FieldPath[M]):
    ...
```

時間欄位。

### `eq`

```python
def eq(value: datetime) -> Filter[M]
```

### `gt`

```python
def gt(value: datetime) -> Filter[M]
```

### `ge`

```python
def ge(value: datetime) -> Filter[M]
```

### `lt`

```python
def lt(value: datetime) -> Filter[M]
```

### `le`

```python
def le(value: datetime) -> Filter[M]
```

## `Boolean`

```python
class Boolean:
    ...
```

## `Text`

```python
class Text:
    ...
```

## `Number`

```python
class Number:
    ...
```

## `Time`

```python
class Time:
    ...
```

## `CollectionField`

```python
class CollectionField:
    ...
```

陣列欄位。

### `any`

```python
def any(condition: Callable[[F], Filter[M]]) -> Filter[M]
```

至少一個元素符合條件。

### `all`

```python
def all(condition: Callable[[F], Filter[M]]) -> Filter[M]
```

所有元素都符合條件。