Sha256: 3da29bf66feacf9ae3dcf3a282e8a814bd2b829d4641fc034f5f2c92454544ab
Contents?: true
Size: 604 Bytes
Versions: 3
Compression:
Stored size: 604 Bytes
Contents
module PostgresCopy module WithTempTable def self.generate(connection = ActiveRecord::Base.connection, base_klass: ActiveRecord::Base, temp_table_name: nil, create_table_opts: {id: :bigint}) raise "You have to pass a table schema definition block!" unless block_given? table_name = temp_table_name || "temp_table_#{SecureRandom.hex}" connection.create_table table_name, temporary: true, **create_table_opts do |t| yield t end klass = Class.new(base_klass) do acts_as_copy_target self.table_name = table_name end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
postgres-copy-1.7.2 | lib/postgres-copy/with_temp_table.rb |
postgres-copy-1.7.1 | lib/postgres-copy/with_temp_table.rb |
postgres-copy-1.7.0 | lib/postgres-copy/with_temp_table.rb |