fengye87
fengye87

Reputation: 2543

Connect Rails to CockroachDB

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!

Upvotes: 2

Views: 741

Answers (4)

Greg Goodman
Greg Goodman

Reputation: 41

CockroachDB is now compatible with Active Record:

https://www.cockroachlabs.com/blog/build-an-app-with-active-record-cockroachdb/

Upvotes: 1

Alex Robinson
Alex Robinson

Reputation: 13387

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.

Upvotes: 1

Nathan VanBenschoten
Nathan VanBenschoten

Reputation: 494

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.

Upvotes: 1

kena
kena

Reputation: 119

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/

Upvotes: 1

Related Questions