Class: Rails::Sequel::Storage::Jdbc

Inherits:
Rails::Sequel::Storage show all
Defined in:
lib/sequel-rails/storage.rb

Instance Attribute Summary

Attributes inherited from Rails::Sequel::Storage

#config

Instance Method Summary collapse

Methods inherited from Rails::Sequel::Storage

#charset, #create, create_all, create_environment, #database, #drop, drop_all, drop_environment, #host, #initialize, new, #owner, #password, #port, #username

Constructor Details

This class inherits a constructor from Rails::Sequel::Storage

Instance Method Details

#_createObject



196
197
198
199
200
201
202
# File 'lib/sequel-rails/storage.rb', line 196

def _create
  if _is_mysql?
    ::Sequel.connect("#{_root_url}#{_params}") do |db|
      db.execute("CREATE DATABASE IF NOT EXISTS `#{db_name}` DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}")
    end
  end
end

#_dropObject



204
205
206
207
208
209
210
# File 'lib/sequel-rails/storage.rb', line 204

def _drop
  if _is_mysql?
    ::Sequel.connect("#{_root_url}#{_params}") do |db|
      db.execute("DROP DATABASE IF EXISTS `#{db_name}`")
    end
  end
end

#_is_mysql?Boolean

Returns:

  • (Boolean)


180
181
182
# File 'lib/sequel-rails/storage.rb', line 180

def _is_mysql?
  database.match(/^jdbc:mysql/)
end

#_paramsObject



192
193
194
# File 'lib/sequel-rails/storage.rb', line 192

def _params
  database.scan /\?.*$/
end

#_root_urlObject



184
185
186
# File 'lib/sequel-rails/storage.rb', line 184

def _root_url
  database.scan /^jdbc:mysql:\/\/\w*:?\d*/
end

#db_nameObject



188
189
190
# File 'lib/sequel-rails/storage.rb', line 188

def db_name
  database.scan(/^jdbc:mysql:\/\/\w+:?\d*\/(\w+)/).flatten.first
end