Class: TableCopy::PG::Source
- Inherits:
-
Object
- Object
- TableCopy::PG::Source
- Defined in:
- lib/table_copy/pg/source.rb
Instance Attribute Summary collapse
-
#conn_method ⇒ Object
readonly
Returns the value of attribute conn_method.
-
#infer_pk_proc ⇒ Object
readonly
Returns the value of attribute infer_pk_proc.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
- #copy_from(fields_list_arg, where = nil) ⇒ Object
- #fields ⇒ Object
- #fields_ddl ⇒ Object
- #indexes ⇒ Object
-
#initialize(args) ⇒ Source
constructor
A new instance of Source.
- #primary_key ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(args) ⇒ Source
Returns a new instance of Source.
9 10 11 12 13 |
# File 'lib/table_copy/pg/source.rb', line 9 def initialize(args) @table_name = args[:table_name] @conn_method = args[:conn_method] @infer_pk_proc = args[:infer_pk_proc] end |
Instance Attribute Details
#conn_method ⇒ Object (readonly)
Returns the value of attribute conn_method.
7 8 9 |
# File 'lib/table_copy/pg/source.rb', line 7 def conn_method @conn_method end |
#infer_pk_proc ⇒ Object (readonly)
Returns the value of attribute infer_pk_proc.
7 8 9 |
# File 'lib/table_copy/pg/source.rb', line 7 def infer_pk_proc @infer_pk_proc end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
7 8 9 |
# File 'lib/table_copy/pg/source.rb', line 7 def table_name @table_name end |
Instance Method Details
#copy_from(fields_list_arg, where = nil) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/table_copy/pg/source.rb', line 31 def copy_from(fields_list_arg, where=nil) with_conn do |conn| conn.copy_data("copy (select #{fields_list_arg} from #{table_name} #{where}) to stdout csv") do yield conn end end end |
#fields ⇒ Object
39 40 41 |
# File 'lib/table_copy/pg/source.rb', line 39 def fields fields_objects.map(&:name) end |
#fields_ddl ⇒ Object
23 24 25 |
# File 'lib/table_copy/pg/source.rb', line 23 def fields_ddl fields_objects.map(&:ddl).join(",\n ") end |
#indexes ⇒ Object
27 28 29 |
# File 'lib/table_copy/pg/source.rb', line 27 def indexes viable_index_columns.map { |name, columns| TableCopy::PG::Index.new(table_name, name, columns) } end |
#primary_key ⇒ Object
19 20 21 |
# File 'lib/table_copy/pg/source.rb', line 19 def primary_key @primary_key ||= get_primary_key end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/table_copy/pg/source.rb', line 15 def to_s table_name end |