Please sign in to comment.
Add Dataset#for_update as a standard dataset method
Previously, Sequel only supported FOR UPDATE on PostgreSQL. This commit adds support for all databases, and has been tested on PostgreSQL, MySQL, SQLite (where it is ignored), H2, and MSSQL. Sequel's PostgreSQL adapter also supports for_share, but because it seems that most databases don't implement something similar, I chose not to add it as one of the standard dataset methods. I did add it to the MySQL adapter, where it uses LOCK IN SHARE MODE. I'm not sure if FOR SHARE on PostgreSQL is equivalent to LOCK IN SHARE MODE on MySQL, but considering that there are already substantial differences in how FOR UPDATE is handled, it's probably not a big deal. New to Sequel is Dataset#lock_style, which returns a cloned dataset with the given lock style, which can be either a symbol or a string. If a symbol and the symbol is recognized by the adapter, the appropriate locking style will be used for the query (most adapters only support :update). If a string, it is treated as a literal string. The MSSQL shared adapter changed from using :table_options to using :lock as the internal option name. If you were using :table_options manually, you'll need to switch to using :lock and include the starting WITH. Dataset#nolock on MSSQL was changed to use the new lock_style method.
- Loading branch information...
Showing with 134 additions and 32 deletions.
- +2 −0 CHANGELOG
- +15 −6 lib/sequel/adapters/shared/mssql.rb
- +12 −1 lib/sequel/adapters/shared/mysql.rb
- +7 −18 lib/sequel/adapters/shared/postgres.rb
- +5 −0 lib/sequel/adapters/shared/sqlite.rb
- +13 −0 lib/sequel/dataset/query.rb
- +12 −1 lib/sequel/dataset/sql.rb
- +4 −0 spec/adapters/mssql_spec.rb
- +4 −0 spec/adapters/mysql_spec.rb
- +55 −5 spec/adapters/postgres_spec.rb
- +5 −1 spec/integration/dataset_test.rb