Class: SequelRails::Storage::Jdbc
Instance Attribute Summary
Attributes inherited from Abstract
#config
Instance Method Summary
collapse
Methods inherited from Abstract
#charset, #close_connections, #create, #database, #drop, #dump, #host, #initialize, #load, #owner, #password, #port, #username
Instance Method Details
#_create ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 29
def _create
if _is_sqlite?
return if in_memory?
::Sequel.connect config['url']
elsif _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
elsif _is_postgres?
adapter = ::SequelRails::Storage::Postgres.new(config)
adapter._create
end
end
|
#_drop ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 43
def _drop
if _is_sqlite?
return if in_memory?
FileUtils.rm db_name if File.exists? db_name
elsif _is_mysql?
::Sequel.connect("#{_root_url}#{_params}") do |db|
db.execute("DROP DATABASE IF EXISTS `#{db_name}`")
end
elsif _is_postgres?
adapter = ::SequelRails::Storage::Postgres.new(config)
adapter._drop
end
end
|
#_dump(filename) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 57
def _dump(filename)
if _is_postgres?
adapter = ::SequelRails::Storage::Postgres.new(config)
adapter._dump(filename)
else
raise NotImplementedError
end
end
|
#_is_mysql? ⇒ Boolean
5
6
7
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 5
def _is_mysql?
config['adapter'].match(/^jdbc:mysql/)
end
|
#_is_postgres? ⇒ Boolean
9
10
11
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 9
def _is_postgres?
config['adapter'].match(/^jdbc:postgresql/)
end
|
#_is_sqlite? ⇒ Boolean
13
14
15
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 13
def _is_sqlite?
config['adapter'].match(/^jdbc:sqlite/)
end
|
#_load(filename) ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 66
def _load(filename)
if _is_postgres?
adapter = ::SequelRails::Storage::Postgres.new(config)
adapter._load(filename)
else
raise NotImplementedError
end
end
|
#_params ⇒ Object
25
26
27
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 25
def _params
config['url'].scan(/\?.*$/).first
end
|
#_root_url ⇒ Object
17
18
19
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 17
def _root_url
config['url'].scan(/^jdbc:mysql:\/\/[\w\.]*:?\d*/).first
end
|
#db_name ⇒ Object
21
22
23
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 21
def db_name
config['database']
end
|