Module: ClickHouse::Client::Redactor

Defined in:
lib/click_house/client/redactor.rb

Class Method Summary collapse

Class Method Details

.redact(query_builder, bind_manager = ClickHouse::Client::BindIndexManager.new) ⇒ String

Redacts the SQL query represented by the query builder.

Example:

query_builder = ClickHouse::QueryBuilder.new('users').where(name: 'John Doe')
redacted_query = ClickHouse::Redactor.redact(query_builder)
# The redacted_query will contain the SQL query with values replaced by placeholders.
output: "SELECT * FROM \"users\" WHERE \"users\".\"name\" = $1"

Parameters:

  • query_builder (::ClickHouse::Querybuilder)

    The query builder object to be redacted.

Returns:

  • (String)

    The redacted SQL query as a string.

Raises:

  • (ArgumentError)

    when the condition in the query is of an unsupported type.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/click_house/client/redactor.rb', line 18

def redact(query_builder, bind_manager = ClickHouse::Client::BindIndexManager.new)
  redacted_constraints = query_builder.manager.constraints.map do |constraint|
    redact_constraint(constraint, bind_manager)
  end

  cloned_query_builder = query_builder.clone

  cloned_query_builder.manager.constraints.clear
  redacted_constraints.each do |constraint|
    cloned_query_builder.manager.where(constraint)
  end

  cloned_query_builder.to_sql
end