jasonmk / datastax_rails

A Ruby-on-Rails interface to Datastax Enterprise. Replaces the majority of ActiveRecord functionality.
MIT License
23 stars 9 forks source link

capability to create via INSERT (for cql) #19

Closed trushkevich closed 10 years ago

trushkevich commented 10 years ago

Hi Jason. I was unable to create a record using current implementation via UPDATE for Cassandra 2, it just fails. So I adjusted the code a bit to be able to use INSERT instead of default UPDATE.

As for me, I'd implement Model.create strictly via INSERT, but it's sure up to you to decide. Oh, and my text editor removed trailing whitespaces :)

jasonmk commented 10 years ago

I'll take a look. In the past, insert and update were the exact same thing under the covers. I'm not on Cassandra 2 yet though so something might have changed. What error did it give you? I'm not opposed to using insert, there was just no reason to in the past.

trushkevich commented 10 years ago

Here is the error (btw I'm using one of my columns as a primary key and don't generate UUIDs):

CassandraCQL::Error::InvalidRequestException: PRIMARY KEY part token found in SET part from /home/antoha/.rvm/gems/ruby-2.1.1/bundler/gems/cassandra-cql-8fb9e0eafdb4/lib/cassandra-cql/database.rb:126:in 'rescue in execute_cql_query' from /home/antoha/.rvm/gems/ruby-2.1.1/bundler/gems/cassandra-cql-8fb9e0eafdb4/lib/cassandra-cql/database.rb:115:in 'execute_cql_query' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/cql/base.rb:25:in 'execute' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/persistence.rb:124:in 'write_with_cql' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/persistence.rb:71:in 'block (2 levels) in write' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/notifications.rb:161:in 'instrument' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/persistence.rb:67:in 'block in write' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/persistence.rb:66:in 'tap' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/persistence.rb:66:in 'write' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/persistence.rb:247:in '_write' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/persistence.rb:234:in '_create' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/datastax_rails-1.2.3/lib/datastax_rails/callbacks.rb:33:in 'block in _create' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:113:in 'call' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:113:in 'call' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:166:in 'block in halting' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:86:in 'call' ... 13 levels... from /home/antoha/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/console.rb:9:in 'start' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:69:in 'console' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:40:in 'run_command!' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/commands.rb:17:in '[top (required)]' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in 'require' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in 'block in require' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in 'load_dependency' from /home/antoha/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in 'require'