cequel/cequel — pull request #201 by outoftime (2014-11-27 00:54:44+00:00)
Title: Key collision detection

This pull request adds a new `on_duplicate_key` class macro that enables duplicate key detection at record creation time (`IF NOT EXISTS`) and allows the user to specify the behavior if a duplicate key is detected, e.g.:

```ruby
class Post
belongs_to :blog
key :permalink, :text
on_duplicate_key :error
end
```

In this case, attempts to overwrite an existing permalink will throw an error at creation time. Allowed arguments to `on_duplicate_key` are:

* `:overwrite`: this is the default. No lightweight transaction, no error, duplicates are overwritten
* `:error`: use a lightweight transaction and throw an error if there is a collision
* `:ignore`: use a lightweight transaction and allow creation to fail silently if there is a collision

A few other things going on in this pull request:

* `INSERT` statements for new records now provide values for all columns; unset columns write `NULL`, which is the same as a column deletion. The effect is that overwriting a column is always a complete overwrite.
* The `Metal::Deleter` class now has a very small job: just performing full-row deletions. All operations that make discrete modifications to an existing row, or the collections therein, are handled by `Updater`, and performed using an `UPDATE` statement. This is possible in CQL3.1 thanks to `NULL` and new syntax for removing keys from maps in an `UPDATE`.
* Cequel::Record no longer automatically initiates batches in any situation. It is not legal to have `on_duplicate_key :error` behavior when saving in a batch, since we can't give immediate feedback. Since there are *some* situations in which it would be bad to automatically buffer operations in a batch, for consistency we simply never automatically buffer operations in a batch.