class RubyEventStore::ROM::SQL::SpecHelper

Attributes

env[R]

Public Class Methods

new(database_uri = ENV['DATABASE_URL']) click to toggle source
# File lib/ruby_event_store/rom/sql.rb, line 91
def initialize(database_uri = ENV['DATABASE_URL'])
  config = ::ROM::Configuration.new(
    :sql,
    database_uri,
    max_connections: database_uri =~ /sqlite/ ? 1 : 5,
    preconnect: :concurrently
    # sql_mode: %w[NO_AUTO_VALUE_ON_ZERO STRICT_ALL_TABLES]
  )
  # $stdout.sync = true
  # config.default.use_logger Logger.new(STDOUT)
  # config.default.connection.pool.send(:preconnect, true)
  config.default.run_migrations

  @env = ROM.setup(config)
end

Public Instance Methods

close_pool_connection() click to toggle source
# File lib/ruby_event_store/rom/sql.rb, line 133
def close_pool_connection
  gateway.connection.pool.disconnect
end
connection_pool_size() click to toggle source
# File lib/ruby_event_store/rom/sql.rb, line 129
def connection_pool_size
  gateway.connection.pool.size
end
gateway() click to toggle source
# File lib/ruby_event_store/rom/sql.rb, line 117
def gateway
  env.rom_container.gateways.fetch(:default)
end
gateway_type?(name) click to toggle source
# File lib/ruby_event_store/rom/sql.rb, line 121
def gateway_type?(name)
  gateway.connection.database_type.eql?(name)
end
has_connection_pooling?() click to toggle source
# File lib/ruby_event_store/rom/sql.rb, line 125
def has_connection_pooling?
  !gateway_type?(:sqlite)
end
run_lifecycle() { || ... } click to toggle source
# File lib/ruby_event_store/rom/sql.rb, line 107
def run_lifecycle
  establish_gateway_connection
  load_gateway_schema

  yield
ensure
  drop_gateway_schema
  close_gateway_connection
end
supports_upsert?() click to toggle source
# File lib/ruby_event_store/rom/sql.rb, line 137
def supports_upsert?
  SQL.supports_upsert?(gateway.connection)
end

Protected Instance Methods

close_gateway_connection() click to toggle source

See: github.com/rom-rb/rom-sql/blob/master/spec/shared/database_setup.rb

# File lib/ruby_event_store/rom/sql.rb, line 160
def close_gateway_connection
  gateway.connection.disconnect
  # Prevent the auto-reconnect when the test completed
  # This will save from hardly reproducible connection run outs
  gateway.connection.pool.available_connections.freeze
end
drop_gateway_schema() click to toggle source
# File lib/ruby_event_store/rom/sql.rb, line 153
def drop_gateway_schema
  gateway.connection.drop_table?('event_store_events')
  gateway.connection.drop_table?('event_store_events_in_streams')
  gateway.connection.drop_table?('schema_migrations')
end
establish_gateway_connection() click to toggle source
# File lib/ruby_event_store/rom/sql.rb, line 143
def establish_gateway_connection
  # Manually preconnect because disconnecting and reconnecting
  # seems to lose the "preconnect concurrently" setting
  gateway.connection.pool.send(:preconnect, true)
end
load_gateway_schema() click to toggle source
# File lib/ruby_event_store/rom/sql.rb, line 149
def load_gateway_schema
  gateway.run_migrations
end