active_record_temptable 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/active_record_temptable.rb +2 -18
- data/lib/active_record_temptable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a7c686e6c4732aa2ed0372acb25adc642f2d454c9cc0df3433a81ea5b352293
|
4
|
+
data.tar.gz: 3b6ac5aa2a1e820d24d41eb6c331262aa51d024a2909037b27a48b50b9fa7618
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78f2f76fc2df5fceb415f150e6aca8e67159c13c8d11976a8034bb91e8b38ca8944e047f19f378c9f9bfb1588f4ed0ac6e5ae88e8e089f062564481187dfcd6a
|
7
|
+
data.tar.gz: 202cef478c39d7e7239bb880ec821a6f50eab951ad792dc24acee6d3118d99636a15e4acfefc4991e269bcb136593360bf7554f1d40e9ffd5854388bfe619bdf
|
data/Gemfile.lock
CHANGED
@@ -19,8 +19,8 @@ module ActiveRecordTemptable
|
|
19
19
|
ActiveRecord::Base.connection_pool.with_connection do |connection|
|
20
20
|
connection.transaction do
|
21
21
|
begin
|
22
|
-
create_table(
|
23
|
-
create_indexes(connection, table_name, indexes)
|
22
|
+
connection.create_table(table_name, temporary: true, as: relation.to_sql)
|
23
|
+
create_indexes(connection, table_name, indexes)
|
24
24
|
klass = relation.klass
|
25
25
|
yield klass.unscoped.from("#{table_name} AS #{klass.table_name}") if block_given?
|
26
26
|
ensure
|
@@ -30,16 +30,6 @@ module ActiveRecordTemptable
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
# Creates temp table and loads provided relation into it
|
34
|
-
#
|
35
|
-
# @param connection [ActiveRecord::ConnectionAdapters]
|
36
|
-
# @param relation [ActiveRecord::Relation]
|
37
|
-
# @param table_name [String] name of table
|
38
|
-
# @return [void]
|
39
|
-
def create_table(connection, relation, table_name)
|
40
|
-
connection.execute(new_table_command(relation, table_name))
|
41
|
-
end
|
42
|
-
|
43
33
|
# Calls add_index for every element in array
|
44
34
|
#
|
45
35
|
# @param connection [ActiveRecord::ConnectionAdapters]
|
@@ -51,10 +41,4 @@ module ActiveRecordTemptable
|
|
51
41
|
connection.add_index(table_name, fields, options || {})
|
52
42
|
end
|
53
43
|
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def new_table_command(relation, table_name)
|
58
|
-
"CREATE TEMPORARY TABLE #{table_name} AS #{relation.to_sql}"
|
59
|
-
end
|
60
44
|
end
|