Module: ActiveRecord::Import::AbstractAdapter::InstanceMethods
- Included in:
- ConnectionAdapters::AbstractAdapter
- Defined in:
- lib/activerecord-import/adapters/abstract_adapter.rb
Instance Method Summary collapse
-
#after_import_synchronize(instances) ⇒ Object
Synchronizes the passed in ActiveRecord instances with the records in the database by calling
reload
on each instance. -
#insert_many(sql, values, *args) ⇒ Object
:nodoc:.
-
#max_allowed_packet ⇒ Object
Returns the maximum number of bytes that the server will allow in a single packet.
- #next_value_for_sequence(sequence_name) ⇒ Object
-
#post_sql_statements(table_name, options) ⇒ Object
Returns an array of post SQL statements given the passed in options.
- #pre_sql_statements(options) ⇒ Object
- #supports_on_duplicate_key_update? ⇒ Boolean
Instance Method Details
#after_import_synchronize(instances) ⇒ Object
Synchronizes the passed in ActiveRecord instances with the records in the database by calling reload
on each instance.
40 41 42 |
# File 'lib/activerecord-import/adapters/abstract_adapter.rb', line 40 def after_import_synchronize( instances ) instances.each(&:reload) end |
#insert_many(sql, values, *args) ⇒ Object
:nodoc:
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/activerecord-import/adapters/abstract_adapter.rb', line 7 def insert_many( sql, values, *args ) # :nodoc: number_of_inserts = 1 base_sql, post_sql = if sql.is_a?( String ) [sql, ''] elsif sql.is_a?( Array ) [sql.shift, sql.join( ' ' )] end sql2insert = base_sql + values.join( ',' ) + post_sql insert( sql2insert, *args ) [number_of_inserts, []] end |
#max_allowed_packet ⇒ Object
Returns the maximum number of bytes that the server will allow in a single packet
67 68 69 |
# File 'lib/activerecord-import/adapters/abstract_adapter.rb', line 67 def max_allowed_packet NO_MAX_PACKET end |
#next_value_for_sequence(sequence_name) ⇒ Object
3 4 5 |
# File 'lib/activerecord-import/adapters/abstract_adapter.rb', line 3 def next_value_for_sequence(sequence_name) %(#{sequence_name}.nextval) end |
#post_sql_statements(table_name, options) ⇒ Object
Returns an array of post SQL statements given the passed in options.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/activerecord-import/adapters/abstract_adapter.rb', line 45 def post_sql_statements( table_name, ) # :nodoc: post_sql_statements = [] if supports_on_duplicate_key_update? if [:on_duplicate_key_ignore] && respond_to?(:sql_for_on_duplicate_key_ignore) post_sql_statements << sql_for_on_duplicate_key_ignore( table_name, [:on_duplicate_key_ignore] ) elsif [:on_duplicate_key_update] post_sql_statements << sql_for_on_duplicate_key_update( table_name, [:on_duplicate_key_update] ) end end # custom user post_sql post_sql_statements << [:post_sql] if [:post_sql] # with rollup post_sql_statements << rollup_sql if [:rollup] post_sql_statements end |
#pre_sql_statements(options) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/activerecord-import/adapters/abstract_adapter.rb', line 22 def pre_sql_statements() sql = [] sql << [:pre_sql] if [:pre_sql] sql << [:command] if [:command] sql << "IGNORE" if [:ignore] # add keywords like IGNORE or DELAYED if [:keywords].is_a?(Array) sql.concat([:keywords]) elsif [:keywords] sql << [:keywords].to_s end sql end |
#supports_on_duplicate_key_update? ⇒ Boolean
71 72 73 |
# File 'lib/activerecord-import/adapters/abstract_adapter.rb', line 71 def supports_on_duplicate_key_update? false end |