Sha256: 599b4d409db6c093aee8244483aa695477d3e04ba8d5cc53fb9417f085ecc429
Contents?: true
Size: 1.37 KB
Versions: 3
Compression:
Stored size: 1.37 KB
Contents
module MassInsert module Adapters class SQLite3Adapter < Adapter MAX_VALUES_PER_INSERTION = 500 # This method is overwrite because the query string to the Sqlite3 # adapter is different. Then the method in the AbstractQuery module # is ignored. def string_values "SELECT #{string_rows_values};" end # This method is overwrite because the query string to complete the # string rows values is different. The separator to sqlite adapter is # 'UNION SELECT' instead of '), (' in other sql adapters. def string_rows_values values.map{ |row| string_single_row_values(row) }.join(" UNION SELECT ") end # This functions calls the necessary functions to create a complete # sqlite3 query to multiple insertion. The methods are in the Abstract # Query module. If some method is too specific to this database adapter # you can overwrite it. The values that the user gave will be treated # in batches of 500 items because sqlite database allows by default # batches of 500.and each batch will generate a query. This method will # generate an array with batch queries. def execute @values.each_slice(MAX_VALUES_PER_INSERTION).map do |slice| @values = slice "#{begin_string}#{string_columns}#{string_values}" end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mass_insert-0.0.3 | lib/mass_insert/adapters/sqlite3_adapter.rb |
mass_insert-0.0.2 | lib/mass_insert/adapters/sqlite3_adapter.rb |
mass_insert-0.0.1 | lib/mass_insert/adapters/sqlite3_adapter.rb |