Method: Sequel::Dataset#delete
- Defined in:
- lib/sequel/dataset/actions.rb
#delete(&block) ⇒ Object
Deletes the records in the dataset, returning the number of records deleted.
DB[:table].delete # DELETE * FROM table
# => 3
Some databases support using multiple tables in a DELETE query. This requires multiple FROM tables (JOINs can also be used). As multiple FROM tables use an implicit CROSS JOIN, you should make sure your WHERE condition uses the appropriate filters for the FROM tables:
DB.from(:a, :b).join(:c, :d=>Sequel[:b][:e]).where{{a[:f]=>b[:g], a[:id]=>c[:h]}}.
delete
# DELETE FROM a
# USING b
# INNER JOIN c ON (c.d = b.e)
# WHERE ((a.f = b.g) AND (a.id = c.h))
163 164 165 166 167 168 169 170 |
# File 'lib/sequel/dataset/actions.rb', line 163 def delete(&block) sql = delete_sql if uses_returning?(:delete) returning_fetch_rows(sql, &block) else execute_dui(sql) end end |