Class: SequelRails::Storage::Postgres
- Inherits:
-
Abstract
- Object
- Abstract
- SequelRails::Storage::Postgres
show all
- Defined in:
- lib/sequel_rails/storage/postgres.rb
Instance Attribute Summary
Attributes inherited from Abstract
#config
Instance Method Summary
collapse
Methods inherited from Abstract
#charset, #create, #database, #drop, #host, #initialize, #owner, #password, #port, #username
Instance Method Details
#_create ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/sequel_rails/storage/postgres.rb', line 4
def _create
ENV["PGPASSWORD"] = password unless password.blank?
commands = ["createdb", "--encoding", charset]
commands << "--username" << username unless username.blank?
commands << "--owner" << owner unless owner.blank?
commands << "--port" << port.to_s unless port.blank?
commands << "--host" << host unless host.blank?
commands << database
res = system(*commands)
ENV["PGPASSWORD"] = nil unless password.blank?
res
end
|
#_drop ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/sequel_rails/storage/postgres.rb', line 17
def _drop
ENV["PGPASSWORD"] = password unless password.blank?
commands = ["dropdb"]
commands << "-U" << username unless username.blank?
commands << "--port" << port.to_s unless port.blank?
commands << "--host" << host unless host.blank?
commands << database
res = system(*commands)
ENV["PGPASSWORD"] = nil unless password.blank?
res
end
|
#close_connections ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/sequel_rails/storage/postgres.rb', line 29
def close_connections
begin
db = ::Sequel.connect(config)
pid_column = db.server_version < 90200 ? "procpid" : "pid"
db.execute <<-SQL.gsub(/^\s{12}/,'')
SELECT COUNT(pg_terminate_backend(#{pid_column}))
FROM pg_stat_activity
WHERE datname = '#{database}';
SQL
rescue => _
end
end
|