Sha256: f9ea31c1404b87edad6cdb349cd3a9783b991dde2487cdd68a256d8a76e1c2f6

Contents?: true

Size: 1.44 KB

Versions: 66

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module ActiveRecord
  module ConnectionAdapters
    module CipherStashPG
      class ExplainPrettyPrinter # :nodoc:
        # Pretty prints the result of an EXPLAIN in a way that resembles the output of the
        # PostgreSQL shell:
        #
        #                                     QUERY PLAN
        #   ------------------------------------------------------------------------------
        #    Nested Loop Left Join  (cost=0.00..37.24 rows=8 width=0)
        #      Join Filter: (posts.user_id = users.id)
        #      ->  Index Scan using users_pkey on users  (cost=0.00..8.27 rows=1 width=4)
        #            Index Cond: (id = 1)
        #      ->  Seq Scan on posts  (cost=0.00..28.88 rows=8 width=4)
        #            Filter: (posts.user_id = 1)
        #   (6 rows)
        #
        def pp(result)
          header = result.columns.first
          lines  = result.rows.map(&:first)

          # We add 2 because there's one char of padding at both sides, note
          # the extra hyphens in the example above.
          width = [header, *lines].map(&:length).max + 2

          pp = []

          pp << header.center(width).rstrip
          pp << "-" * width

          pp += lines.map { |line| " #{line}" }

          nrows = result.rows.length
          rows_label = nrows == 1 ? "row" : "rows"
          pp << "(#{nrows} #{rows_label})"

          pp.join("\n") + "\n"
        end
      end
    end
  end
end

Version data entries

66 entries across 32 versions & 1 rubygems

Version Path
activerecord-cipherstash-pg-adapter-0.8.5 lib/active_record/connection_adapters/6.1/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.8.5 lib/active_record/connection_adapters/7.0/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.8.5 lib/active_record/connection_adapters/7.1/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.8.4 lib/active_record/connection_adapters/7.0/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.8.4 lib/active_record/connection_adapters/6.1/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.8.4 lib/active_record/connection_adapters/7.1/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.8.3 lib/active_record/connection_adapters/7.0/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.8.3 lib/active_record/connection_adapters/7.1/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.8.3 lib/active_record/connection_adapters/6.1/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.8.2 lib/active_record/connection_adapters/7.0/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.8.2 lib/active_record/connection_adapters/6.1/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.8.2 lib/active_record/connection_adapters/7.1/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.8.1 lib/active_record/connection_adapters/7.0/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.8.1 lib/active_record/connection_adapters/6.1/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.8.0 lib/active_record/connection_adapters/6.1/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.8.0 lib/active_record/connection_adapters/7.0/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.7.19 lib/active_record/connection_adapters/6.1/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.7.19 lib/active_record/connection_adapters/7.0/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.7.18 lib/active_record/connection_adapters/7.0/cipherstash_pg/explain_pretty_printer.rb
activerecord-cipherstash-pg-adapter-0.7.18 lib/active_record/connection_adapters/6.1/cipherstash_pg/explain_pretty_printer.rb