diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-03-10 01:53:48 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-03-17 05:20:46 +0900 |
commit | fdac932707fb16b7d074b1d0bc7c255157d72675 (patch) | |
tree | 7932190a3b429886c69e3209926ce766ebce0895 /activerecord/lib/active_record/connection_adapters/postgresql | |
parent | 1db05065434e1b5341e6748632e310060e92b80d (diff) | |
download | rails-fdac932707fb16b7d074b1d0bc7c255157d72675.tar.gz rails-fdac932707fb16b7d074b1d0bc7c255157d72675.tar.bz2 rails-fdac932707fb16b7d074b1d0bc7c255157d72675.zip |
Extract `truncate` and `truncate_tables` into database statements
This is to easier make `truncate_tables` to bulk statements.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb index 41633872e2..208934385f 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb @@ -143,6 +143,12 @@ module ActiveRecord end end + def truncate_tables(*table_names) # :nodoc: + unless table_names.empty? + execute "TRUNCATE TABLE #{table_names.map(&method(:quote_table_name)).join(", ")}" + end + end + # Begins a transaction. def begin_db_transaction execute "BEGIN" |