Sha256: 79b9ded3bd55c8529e563497358f97816003faeca3dbf0eba07462a4243a6f63

Contents?: true

Size: 663 Bytes

Versions: 1

Compression:

Stored size: 663 Bytes

Contents

module SchemaPlusIndexes
  module Middleware
    module Schema
      module Sqlite3
        module Indexes

          def after(env)
            indexes = Hash[env.index_definitions.map{ |d| [d.name, d] }]

            env.connection.exec_query("SELECT name, sql FROM sqlite_master WHERE type = 'index'").map do |row|
              if (desc_columns = row['sql'].scan(/['"`]?(\w+)['"`]? DESC\b/).flatten).any?
                index = indexes[row['name']]
                index.orders = Hash[index.columns.map {|column| [column, desc_columns.include?(column) ? :desc : :asc]}]
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
schema_plus_indexes-0.1.2 lib/schema_plus_indexes/middleware/schema.rb