2
votes

CockroachDB is a very interesting distributed SQL db, which exposes PostgreSQL wire protocol. So I tried to connect a new Rails project to CockroachDB using the classic pg gem. Unfortunately, a simple rails db:create gave:

/home/fengye87/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:671: warning: Failed to set the default_internal encoding to UTF8: 'ERROR:  unknown variable: "CLIENT_ENCODING"
'
invalid encoding name: unicode

So I guess it indicates that CockroachDB doesn't support CLIENT_ENCODING variable. The question is: is it possible to bypass setting these variables in pg? Does anyone managed to connect Rails to CockroachDB ever? Thanks!

4
An alternative may be to use Sequel in place of ActiveRecord with Rails. Don't know if CockroachDB will work with Sequel but it's another path to possibly sooner support.karmakaze

4 Answers

1
votes

CockroachDB does support client_encoding but the only value supported right now is "utf8".

Since that's rather straightforward to modify you could either manually change the value used in the pg gem or you could file a CockroachDB issue to the project's GitHub: http://github.com/cockroachdb/cockroach/issues/

1
votes

CockroachDB does not currently work with ActiveRecord, but we are looking to support it in the near future. We are tracking issues related to ORM functionality on GitHub.

1
votes

To add to Nathan's answer that CockroachDB does not yet work with ActiveRecord, it's worth mentioning that CockroachDB is currently usable via lower-level clients, such as Ruby's pg client.