Class: Turboquery::Connection
- Inherits:
-
Object
- Object
- Turboquery::Connection
- Defined in:
- lib/turboquery/connection.rb
Defined Under Namespace
Modules: PsqlEnv
Class Method Summary collapse
Instance Method Summary collapse
- #after_fork ⇒ Object
- #config ⇒ Object
- #copy_s3_to_table(_key, _table) ⇒ Object
- #copy_table_to_s3(_table) ⇒ Object
- #dump_table_ddl(table) ⇒ Object
- #execute(*args, &block) ⇒ Object
- #set_env ⇒ Object
- #table_exists?(table = nil) ⇒ Boolean
Class Method Details
.after_fork ⇒ Object
45 46 47 |
# File 'lib/turboquery/connection.rb', line 45 def self.after_fork AR.establish_connection end |
Instance Method Details
#after_fork ⇒ Object
41 42 43 |
# File 'lib/turboquery/connection.rb', line 41 def after_fork self.class.after_fork end |
#config ⇒ Object
33 34 35 |
# File 'lib/turboquery/connection.rb', line 33 def config connection.instance_variable_get(:@config) end |
#copy_s3_to_table(_key, _table) ⇒ Object
25 26 27 |
# File 'lib/turboquery/connection.rb', line 25 def copy_s3_to_table(_key, _table) fail 'Not implemented' end |
#copy_table_to_s3(_table) ⇒ Object
21 22 23 |
# File 'lib/turboquery/connection.rb', line 21 def copy_table_to_s3(_table) fail 'Not implemented' end |
#dump_table_ddl(table) ⇒ Object
15 16 17 18 19 |
# File 'lib/turboquery/connection.rb', line 15 def dump_table_ddl(table) set_env schema = `pg_dump -i -s -x -o -O --no-tablespaces --no-security-labels -t #{Shellwords.escape(table)} #{Shellwords.escape(config[:database])}` schema.empty? ? '' : schema.match(/CREATE TABLE[^;]+;/)[0] end |
#execute(*args, &block) ⇒ Object
29 30 31 |
# File 'lib/turboquery/connection.rb', line 29 def execute(*args, &block) connection.execute(*args, &block) end |
#set_env ⇒ Object
37 38 39 |
# File 'lib/turboquery/connection.rb', line 37 def set_env PsqlEnv.set(config) end |
#table_exists?(table = nil) ⇒ Boolean
5 6 7 8 9 10 11 12 13 |
# File 'lib/turboquery/connection.rb', line 5 def table_exists?(table = nil) return false if table.nil? connection.execute(" SELECT 1 AS exists FROM information_schema.tables WHERE table_schema = 'public' AND table_name = '#{table}'; ").count == 1 end |