Class: ClickHouse::SQL::Fragment
- Inherits:
-
Object
- Object
- ClickHouse::SQL::Fragment
- Includes:
- Part
- Defined in:
- lib/clickhouse/sql/fragment.rb
Instance Method Summary collapse
-
#initialize(sql, bindings = {}, fills: []) ⇒ ClickHouse::SQL::Fragment
constructor
Builds a composable SQL fragment with typed placeholders and slots.
-
#placeholder_types ⇒ Hash{Symbol=>String}
Returns ClickHouse placeholder types from this fragment and nested slots.
-
#placeholders ⇒ Hash{Symbol=>Object}
Returns typed placeholder values from this fragment and nested slots.
-
#to_redacted_sql(bind_index_manager = ClickHouse::SQL::BindIndexManager.new) ⇒ String
Renders the fragment with typed placeholders replaced by bind markers.
-
#to_sql ⇒ String
Renders the fragment with ClickHouse typed placeholders intact.
Constructor Details
#initialize(sql, bindings = {}, fills: []) ⇒ ClickHouse::SQL::Fragment
Builds a composable SQL fragment with typed placeholders and slots.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/clickhouse/sql/fragment.rb', line 16 def initialize(sql, bindings = {}, fills: []) raise Error, "Empty SQL fragment given" if ValueNormalization.blank_string?(sql) @sql = sql.to_s @bindings = ValueNormalization.symbolize_keys(bindings || {}) @fills = Array(fills) @placeholders = ClickHouse::SQL.parse_placeholders(@sql) validate_fills! validate_bindings! end |
Instance Method Details
#placeholder_types ⇒ Hash{Symbol=>String}
Returns ClickHouse placeholder types from this fragment and nested slots.
53 54 55 |
# File 'lib/clickhouse/sql/fragment.rb', line 53 def placeholder_types ClickHouse::SQL.merge_placeholder_types!(@placeholder_types.dup, nested_placeholder_types) end |
#placeholders ⇒ Hash{Symbol=>Object}
Returns typed placeholder values from this fragment and nested slots.
46 47 48 |
# File 'lib/clickhouse/sql/fragment.rb', line 46 def placeholders ClickHouse::SQL.merge_placeholders!(@typed_placeholder_values.dup, nested_placeholders) end |
#to_redacted_sql(bind_index_manager = ClickHouse::SQL::BindIndexManager.new) ⇒ String
Renders the fragment with typed placeholders replaced by bind markers.
39 40 41 |
# File 'lib/clickhouse/sql/fragment.rb', line 39 def to_redacted_sql(bind_index_manager = ClickHouse::SQL::BindIndexManager.new) render(redacted: true, bind_index_manager:) end |
#to_sql ⇒ String
Renders the fragment with ClickHouse typed placeholders intact.
31 32 33 |
# File 'lib/clickhouse/sql/fragment.rb', line 31 def to_sql render(redacted: false) end |