AshClickhouse.Identifier (AshClickhouse v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

Quotes an identifier with backticks, escaping any embedded backticks.

Sanitizes an identifier, raising ArgumentError if it is invalid.

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

Validates a database name, raising ArgumentError if invalid.

Validates a table name, raising ArgumentError if invalid.

Functions

quote_name(name)

@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`"

sanitize!(name)

@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?(name)

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

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

validate_database!(database)

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

Validates a database name, raising ArgumentError if invalid.

validate_table!(table)

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

Validates a table name, raising ArgumentError if invalid.