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



224
225
226
227
228
229
230
# File 'lib/sequel-rails/storage.rb', line 224

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



232
233
234
235
236
237
238
# File 'lib/sequel-rails/storage.rb', line 232

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)


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

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

#_paramsObject



220
221
222
# File 'lib/sequel-rails/storage.rb', line 220

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

#_root_urlObject



212
213
214
# File 'lib/sequel-rails/storage.rb', line 212

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

#db_nameObject



216
217
218
# File 'lib/sequel-rails/storage.rb', line 216

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