Class: Charrington::CreatePostgresTable
- Inherits:
-
Object
- Object
- Charrington::CreatePostgresTable
- Includes:
- LogStash::Util::Loggable, Service
- Defined in:
- lib/logstash/outputs/charrington/create_postgres_table.rb
Overview
This service will create a table dynamically based on the JSON structure. This is potentially called from Insert when an insert fails.
Constant Summary collapse
- TIMESTAMP_COLUMNS =
%w[published_at sent_at original_timestamp received_at timestamp].freeze
- Error =
Class.new(StandardError)
- CreateFailed =
Class.new(Error)
Instance Attribute Summary collapse
-
#column_types ⇒ Object
Returns the value of attribute column_types.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
-
#transformer ⇒ Object
readonly
Returns the value of attribute transformer.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(connection, event, schema, table_name, columns, opts = {}) ⇒ CreatePostgresTable
constructor
rubocop:disable Metrics/ParameterLists.
Methods included from Service
Constructor Details
#initialize(connection, event, schema, table_name, columns, opts = {}) ⇒ CreatePostgresTable
rubocop:disable Metrics/ParameterLists
19 20 21 22 23 24 25 26 27 |
# File 'lib/logstash/outputs/charrington/create_postgres_table.rb', line 19 def initialize(connection, event, schema, table_name, columns, opts = {}) # rubocop:disable Metrics/ParameterLists @connection = connection @event = event.to_hash @table_name = table_name @schema = schema @columns = columns @transformer = opts[:transformer] @column_types = initial_columns end |
Instance Attribute Details
#column_types ⇒ Object
Returns the value of attribute column_types.
14 15 16 |
# File 'lib/logstash/outputs/charrington/create_postgres_table.rb', line 14 def column_types @column_types end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
13 14 15 |
# File 'lib/logstash/outputs/charrington/create_postgres_table.rb', line 13 def columns @columns end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
13 14 15 |
# File 'lib/logstash/outputs/charrington/create_postgres_table.rb', line 13 def connection @connection end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
13 14 15 |
# File 'lib/logstash/outputs/charrington/create_postgres_table.rb', line 13 def event @event end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
13 14 15 |
# File 'lib/logstash/outputs/charrington/create_postgres_table.rb', line 13 def opts @opts end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
13 14 15 |
# File 'lib/logstash/outputs/charrington/create_postgres_table.rb', line 13 def schema @schema end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
13 14 15 |
# File 'lib/logstash/outputs/charrington/create_postgres_table.rb', line 13 def table_name @table_name end |
#transformer ⇒ Object (readonly)
Returns the value of attribute transformer.
13 14 15 |
# File 'lib/logstash/outputs/charrington/create_postgres_table.rb', line 13 def transformer @transformer end |
Instance Method Details
#call ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/logstash/outputs/charrington/create_postgres_table.rb', line 29 def call set_column_types create_table true rescue StandardError => e raise CreateFailed, e. ensure @column_types.clear if @column_types.is_a? Array end |