Method: Sequel::Dataset#returning
- Defined in:
- lib/sequel/dataset/query.rb
#returning(*values) ⇒ Object
Modify the RETURNING clause, only supported on a few databases. If returning is used, instead of insert returning the autogenerated primary key or update/delete returning the number of modified rows, results are returned using fetch_rows
.
DB[:items].returning # RETURNING *
DB[:items].returning(nil) # RETURNING NULL
DB[:items].returning(:id, :name) # RETURNING id, name
DB[:items].returning.insert(a: 1) do |hash|
# hash for each row inserted, with values for all columns
end
DB[:items].returning.update(a: 1) do |hash|
# hash for each row updated, with values for all columns
end
DB[:items].returning.delete(a: 1) do |hash|
# hash for each row deleted, with values for all columns
end
884 885 886 887 888 889 890 891 892 893 894 895 |
# File 'lib/sequel/dataset/query.rb', line 884 def returning(*values) if values.empty? return self if opts[:returning] == EMPTY_ARRAY cached_dataset(:_returning_ds) do raise Error, "RETURNING is not supported on #{db.database_type}" unless supports_returning?(:insert) clone(:returning=>EMPTY_ARRAY) end else raise Error, "RETURNING is not supported on #{db.database_type}" unless supports_returning?(:insert) clone(:returning=>values.freeze) end end |