# `AshClickhouse.Identifier`
[🔗](https://github.com/ohhi-vn/ash_clickhouse/blob/main/lib/ash_clickhouse/identifier.ex#L1)

Helpers for safely quoting and sanitizing ClickHouse identifiers.

ClickHouse identifiers (table names, column names, database names) may be
quoted with backticks. Unquoted identifiers are limited to a restricted set
of characters. This module provides validation and quoting helpers so the
data layer can build SQL safely without opening SQL-injection vectors.

# `quote_name`

```elixir
@spec quote_name(String.t() | atom()) :: String.t()
```

Quotes an identifier with backticks, escaping any embedded backticks.

## Examples

    iex> AshClickhouse.Identifier.quote_name("users")
    "`users`"

    iex> AshClickhouse.Identifier.quote_name("my`table")
    "`my``table`"

Column identifiers go through `quote_name/1` (backtick-escaping) rather than
the stricter `sanitize!/1` used for table/database names. This is intentional:
Ash attribute names are derived from atoms and are already safe, and
`quote_name/1` additionally tolerates arbitrary (e.g. expression-derived)
column labels without rejecting valid identifiers that merely fall outside the
`[a-zA-Z_][a-zA-Z0-9_]*` pattern. Table and database names, by contrast, are
developer-supplied strings validated up front by `sanitize!/1` so a bad name
fails loudly at DDL time rather than producing malformed SQL.

# `sanitize!`

```elixir
@spec sanitize!(String.t() | atom()) :: String.t()
```

Sanitizes an identifier, raising `ArgumentError` if it is invalid.

A valid ClickHouse identifier consists of letters, digits, and underscores,
and must not start with a digit.

# `valid_identifier?`

```elixir
@spec valid_identifier?(String.t() | atom()) :: boolean()
```

Returns true if the given identifier is a valid unquoted ClickHouse identifier.

# `validate_database!`

```elixir
@spec validate_database!(String.t() | nil) :: :ok
```

Validates a database name, raising `ArgumentError` if invalid.

# `validate_table!`

```elixir
@spec validate_table!(String.t()) :: :ok
```

Validates a table name, raising `ArgumentError` if invalid.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
