Class: DataDuck::PostgresqlSource

Inherits:
SqlDbSource show all
Defined in:
lib/dataduck/postgresql_source.rb

Instance Attribute Summary

Attributes inherited from SqlDbSource

#database, #host, #password, #port, #username

Attributes inherited from Database

#name

Instance Method Summary collapse

Methods inherited from SqlDbSource

#connection, #initialize, #query, #table_names

Methods inherited from Source

load_config!, only_source, #schema, skip_these_table_names, source, source_config

Methods inherited from Database

#connection, #initialize, #query, #table_names

Constructor Details

This class inherits a constructor from DataDuck::SqlDbSource

Instance Method Details

#data_size_for_table(table_name) ⇒ Object



23
24
25
26
27
# File 'lib/dataduck/postgresql_source.rb', line 23

def data_size_for_table(table_name)
  size_in_bytes = self.query("SELECT pg_total_relation_size('#{ table_name }')").first.to_i
  size_in_gb = size_in_bytes / 1_000_000_000.0
  size_in_gb
end

#db_typeObject



7
8
9
# File 'lib/dataduck/postgresql_source.rb', line 7

def db_type
  'postgres'
end

#dbconsole(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dataduck/postgresql_source.rb', line 11

def dbconsole(options = {})
  args = []
  args << "--host=#{ self.host }"
  args << "--username=#{ self.username }"
  args << "--dbname=#{ self.database }"
  args << "--port=#{ self.port }"

  ENV['PGPASSWORD'] = self.password

  self.find_command_and_execute("psql", *args)
end

#escape_charObject



29
30
31
# File 'lib/dataduck/postgresql_source.rb', line 29

def escape_char
  '"'
end