Sha256: 038f688bfcd7378d967de9ff1cdfd27e90d92af4f2fd187da2603aa0d33a42ac

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

module EventSource
  module Postgres
    class Get
      class Last
        class SelectStatement
          include Log::Dependency

          initializer :stream

          def stream_name
            stream.name
          end

          def self.build(stream_name)
            stream = Stream.new(stream_name)
            new(stream)
          end

          def sql
            logger.trace(tag: :sql) { "Composing select statement (Stream: #{stream_name})" }

            statement = <<-SQL
              SELECT
                id::varchar,
                stream_name::varchar,
                position::int,
                type::varchar,
                global_position::bigint,
                data::varchar,
                metadata::varchar,
                time::timestamp
              FROM
                events
              WHERE
                stream_name = '#{stream_name}'
              ORDER BY
                position DESC
              LIMIT
                1
              ;
            SQL

            logger.debug(tag: :sql) { "Composed select statement (Stream: #{stream_name})" }
            logger.debug(tags: [:data, :sql]) { "Statement: #{statement}" }

            statement
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
evt-event_source-postgres-0.13.1.0 lib/event_source/postgres/get/last/select_statement.rb