<commit_before># frozen_string_literal: true

require 'sequel'
require 'forwardable'

module Tzispa
  module Data

    class AdapterPool
      include Enumerable
      extend Forwardable

      def_delegators :@pool, :has_key?, :keys
      attr_reader :default

      def initialize(config, default = nil)
        setup_sequel
        @default = default || config.first[0]
        @pool = {}.tap do |hsh|
          config.each do |k, v|
            conn = Sequel.connect "#{v.adapter}://#{v.database}"
            if v.connection_validation
              conn.extension(:connection_validator)
              conn.pool.connection_validation_timeout = v.validation_timeout || DEFAULT_TIMEOUT
            end
            hsh[k.to_sym] = conn
          end
        end
      end

      def [](name = nil)
        @pool[name&.to_sym || default]
      end

      def setup_sequel
        Sequel.extension :core_extensions
        Sequel.default_timezone = :utc
        Sequel.datetime_class = DateTime
      end

      DEFAULT_TIMEOUT = 3600
    end

  end
end
<commit_msg>setup sequel extensions individualy for adapter_pool connections<commit_after># frozen_string_literal: true

require 'sequel'
require 'forwardable'

module Tzispa
  module Data

    class AdapterPool
      include Enumerable
      extend Forwardable

      def_delegators :@pool, :has_key?, :keys
      attr_reader :default_repo

      def initialize(config, default = nil)
        setup_sequel
        @default_repo = default || config.first[0]
        @pool = {}.tap do |hsh|
          config.each { |kid, vc| hsh[kid.to_sym] = connect(vc) }
        end
      end

      def connect(config)
        Sequel.connect("#{config.adapter}://#{config.database}").tap do |conn|
          if config.connection_validation
            conn.extension(:connection_validator)
            conn.pool.connection_validation_timeout = config.validation_timeout || DEFAULT_TIMEOUT
          end
          if config.respond_to? :extensions
            config.extensions.split(',').each { |ext| conn.extension ext.to_sym }
          end
        end
      end

      def [](name = nil)
        @pool[name&.to_sym || default_repo]
      end

      def default
        @pool[default_repo]
      end

      def setup_sequel
        Sequel.extension :core_extensions
        Sequel.default_timezone = :utc
        Sequel.datetime_class = DateTime
      end

      DEFAULT_TIMEOUT = 3600
    end

  end
end

{'fraction_non_alphanumeric': 0.085002043318349, 'fraction_numerical': 0.004086636697997548, 'mean_word_length': 2.158709677419355, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '339883', 'n_tokens_mistral': 727, 'n_tokens_neox': 704, 'n_words': 168}