class Hanami::Providers::DB::SQLAdapter

@api public @since 2.2.0

Constants

INSTRUMENTATION_PLUGIN_CONFIG

@api private

Public Instance Methods

clear() click to toggle source

@api public @since 2.2.0

Calls superclass method Hanami::Providers::DB::Adapter#clear
# File lib/hanami/providers/db/sql_adapter.rb, line 93
def clear
  config.extensions = nil
  super
end
configure_for_database(database_url) click to toggle source

@api private

# File lib/hanami/providers/db/sql_adapter.rb, line 40
def configure_for_database(database_url)
  return if skip_defaults?

  configure_plugins
  configure_extensions(database_url)
end
configure_from_adapter(other_adapter) click to toggle source

@api private

# File lib/hanami/providers/db/sql_adapter.rb, line 26
def configure_from_adapter(other_adapter)
  super

  return if skip_defaults?

  # As part of gateway configuration, every gateway will receive the "any adapter" here,
  # which is a plain `Adapter`, not an `SQLAdapter`. Its configuration will have been merged
  # by `super`, so no further work is required.
  return unless other_adapter.is_a?(self.class)

  extensions.concat(other_adapter.extensions).uniq! unless skip_defaults?(:extensions)
end
extension(*extensions) click to toggle source

@api public @since 2.2.0

# File lib/hanami/providers/db/sql_adapter.rb, line 15
def extension(*extensions)
  self.extensions.concat(extensions).uniq!
end
extensions() click to toggle source

@api public @since 2.2.0

# File lib/hanami/providers/db/sql_adapter.rb, line 21
def extensions
  config.extensions ||= []
end
gateway_options() click to toggle source

@api private

# File lib/hanami/providers/db/sql_adapter.rb, line 87
def gateway_options
  {extensions: extensions}
end

Private Instance Methods

configure_extensions(database_url) click to toggle source

@api private

# File lib/hanami/providers/db/sql_adapter.rb, line 65
        def configure_extensions(database_url)
  return if skip_defaults?(:extensions)

  # Extensions for all SQL databases
  extension(
    :caller_logging,
    :error_sql,
    :sql_comments
  )

  # Extensions for specific databases
  if database_url.to_s.start_with?(%r{postgres(ql)*://})
    extension(
      :pg_array,
      :pg_enum,
      :pg_json,
      :pg_range
    )
  end
end
configure_plugins() click to toggle source

@api private

# File lib/hanami/providers/db/sql_adapter.rb, line 48
        def configure_plugins
  return if skip_defaults?(:plugins)

  # Configure the plugin via a frozen proc, so it can be properly uniq'ed when configured
  # for multiple gateways. See `Hanami::Providers::DB::Config#each_plugin`.
  plugin(relations: :instrumentation, &INSTRUMENTATION_PLUGIN_CONFIG)

  plugin relations: :auto_restrictions
end