Class: MassInsert::Builder::Adapters::Adapter
- Inherits:
-
Object
- Object
- MassInsert::Builder::Adapters::Adapter
- Includes:
- Helpers::AbstractQuery
- Defined in:
- lib/mass_insert/builder/adapters/adapter.rb
Direct Known Subclasses
Mysql2Adapter, PostgreSQLAdapter, SQLServerAdapter, SQLite3Adapter
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
-
#columns ⇒ Object
Returns an array according to the options with the column names that will be included in the queries.
-
#initialize(values, options) ⇒ Adapter
constructor
A new instance of Adapter.
-
#method_missing(method, *args) ⇒ Object
Returns the options according to the method that wasn’t found.
-
#sanitized_columns ⇒ Object
Prepare array with the column names according to the options.
-
#timestamp ⇒ Object
Returns the timestamp value according to the correct timestamp format to that database engine.
-
#timestamp? ⇒ Boolean
Returns true o false if the database table has timestamp columns.
-
#timestamp_format ⇒ Object
Returns timestamp format according to the database adapter.
-
#timestamp_hash ⇒ Object
Returns the timestamp hash to be merge into row values that will be saved in the database.
-
#values_per_insertion ⇒ Object
Returns the amount of records to each query.
Methods included from Helpers::AbstractQuery
#begin_string, #execute, #string_columns, #string_rows_values, #string_single_row_values, #string_single_value, #string_values
Constructor Details
#initialize(values, options) ⇒ Adapter
Returns a new instance of Adapter.
9 10 11 12 |
# File 'lib/mass_insert/builder/adapters/adapter.rb', line 9 def initialize values, @values = values @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Returns the options according to the method that wasn’t found.
15 16 17 |
# File 'lib/mass_insert/builder/adapters/adapter.rb', line 15 def method_missing method, *args @options.has_key?(method) ? @options[method] : super end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/mass_insert/builder/adapters/adapter.rb', line 7 def @options end |
#values ⇒ Object
Returns the value of attribute values.
7 8 9 |
# File 'lib/mass_insert/builder/adapters/adapter.rb', line 7 def values @values end |
Instance Method Details
#columns ⇒ Object
Returns an array according to the options with the column names that will be included in the queries.
21 22 23 |
# File 'lib/mass_insert/builder/adapters/adapter.rb', line 21 def columns @columns ||= sanitized_columns end |
#sanitized_columns ⇒ Object
Prepare array with the column names according to the options.
26 27 28 29 30 |
# File 'lib/mass_insert/builder/adapters/adapter.rb', line 26 def sanitized_columns columns = class_name.column_names columns.delete(class_name.primary_key) unless primary_key columns.map(&:to_sym) end |
#timestamp ⇒ Object
Returns the timestamp value according to the correct timestamp format to that database engine.
45 46 47 |
# File 'lib/mass_insert/builder/adapters/adapter.rb', line 45 def Time.now.strftime() end |
#timestamp? ⇒ Boolean
Returns true o false if the database table has timestamp columns.
33 34 35 |
# File 'lib/mass_insert/builder/adapters/adapter.rb', line 33 def columns.include?(:created_at) && columns.include?(:updated_at) end |
#timestamp_format ⇒ Object
Returns timestamp format according to the database adapter. This function can be overwrite in database adapters classes.
39 40 41 |
# File 'lib/mass_insert/builder/adapters/adapter.rb', line 39 def "%Y-%m-%d %H:%M:%S.%6N" end |
#timestamp_hash ⇒ Object
Returns the timestamp hash to be merge into row values that will be saved in the database.
51 52 53 54 |
# File 'lib/mass_insert/builder/adapters/adapter.rb', line 51 def = {:created_at => , :updated_at => } end |
#values_per_insertion ⇒ Object
Returns the amount of records to each query. Tries to take the each_slice option value or the length of values.
58 59 60 |
# File 'lib/mass_insert/builder/adapters/adapter.rb', line 58 def values_per_insertion each_slice || @values.count end |