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, #search_path, #username
Instance Method Details
#_create ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 28
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
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 42
def _drop
if _is_sqlite?
return if in_memory?
FileUtils.rm db_name if File.exist? 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
56
57
58
59
60
61
62
63
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 56
def _dump(filename)
if _is_postgres?
adapter = ::SequelRails::Storage::Postgres.new(config)
adapter._dump(filename)
else
raise NotImplementedError
end
end
|
#_is_mysql? ⇒ Boolean
4
5
6
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 4
def _is_mysql?
config['adapter'].start_with?('jdbc:mysql')
end
|
#_is_postgres? ⇒ Boolean
8
9
10
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 8
def _is_postgres?
config['adapter'].start_with?('jdbc:postgresql')
end
|
#_is_sqlite? ⇒ Boolean
12
13
14
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 12
def _is_sqlite?
config['adapter'].start_with?('jdbc:sqlite')
end
|
#_load(filename) ⇒ Object
65
66
67
68
69
70
71
72
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 65
def _load(filename)
if _is_postgres?
adapter = ::SequelRails::Storage::Postgres.new(config)
adapter._load(filename)
else
raise NotImplementedError
end
end
|
#_params ⇒ Object
24
25
26
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 24
def _params
config['url'].scan(/\?.*$/).first
end
|
#_root_url ⇒ Object
16
17
18
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 16
def _root_url
config['url'].scan(%r{^jdbc:mysql://[\w\.]*:?\d*}).first
end
|
#db_name ⇒ Object
20
21
22
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 20
def db_name
config['database']
end
|
74
75
76
77
78
79
80
|
# File 'lib/sequel_rails/storage/jdbc.rb', line 74
def schema_information_dump(migrator, sql_dump)
if _is_postgres?
schema_information_dump_with_search_path(migrator, sql_dump)
else
super
end
end
|