Gorm: Add database backend support for CockroachDB

Created on 24 Nov 2015  Â·  12Comments  Â·  Source: go-gorm/gorm

While in first development stages, the design, features and algorithms of Cockroach look highly promising. Open source, scalable, geo-replicated, ACID compliant. It is inspired by the Google Spanner database system. It is better than the FoundationDB supported by GORM, which was taken down by Apple.

Cockroach looks like a successor to FoundationDB. Also written in Go and implementing SQL, CockroachDB would be a great match and good addition for GORM.

See here:

Please add database connector for CockroachDB.

feature

Most helpful comment

GORM and CockroachDB seem to interoperate just fine to me. A common sticking point is that you need to create the database ahead of time, just like you would in PostgreSQL. The example you link contains instructions to create the database - if you do that first, things will work just fine.

Thanks! Let me know if you have more issues, we really want to make sure CockroachDB and GORM work well together.

All 12 comments

  • 1

Any news on this? Is it planned? Just wondering :)

i am using cockroach and its amazing.. Still some loose edges but really impressive compared to postresql.
So yes +1 so i can use it with GORM.

I'm working on implementing cockroach here: https://github.com/d4l3k/gorm

There are a number of things that make it hard to integrate with gorm:

  • Since it's a distributed database there is no auto increment option. Instead, it has experimental_unique_int(), which generates a random uint64. This means that you can't have shorter primary keys since it truncates the key and thus will be less random (if short enough, 1).
  • Cockroach doesn't support "RETURNING" statements. So creating a new entry involves a select statement to make a new unique id, and then a second to insert the record.
  • Cockroach client returns sql.ErrNoRows for operations that doesn't modify rows.
  • null has to be typed when being set (null::int).
  • strings aren't automatically cast into dates
  • This error message: TODO(pmattis): unsupported FROM: FROM level1 INNER JOIN level1_level2 ON level1_level2.level1_id = level1.id. FROM isn't supported thus a huge amount of gorm breaks.

I've gotten a lot of the tests passing, but there's still quite a few errors that need to be taken care of.

There's also a lot of tests that fail because the DB doesn't support something like automatic typecasting.

Currently failing tests (errors omitted), mostly related to FROM

--- FAIL: TestManyToMany (0.19s)
--- FAIL: TestSelectWithCreate (0.02s)
--- FAIL: TestManyToManyWithCustomizedColumn (0.61s)
--- FAIL: TestJoinTable (1.08s)
--- FAIL: TestJoins (0.01s)
--- FAIL: TestJoinsWithSelect (0.01s)
--- FAIL: TestManyToManyWithMultiPrimaryKeys (0.50s)
--- FAIL: TestManyToManyWithCustomizedForeignKeys (0.55s)
--- FAIL: TestManyToManyWithCustomizedForeignKeys2 (0.90s)
--- FAIL: TestManyToManyPreloadWithMultiPrimaryKeys (0.49s)
--- FAIL: TestManyToManyPreloadForPointer (0.63s)
--- FAIL: TestManyToManyPreloadForNestedPointer (1.01s)
--- FAIL: TestNestedManyToManyPreload (1.12s)
--- FAIL: TestNestedManyToManyPreload2 (0.44s)
--- FAIL: TestFirstAndLast (0.09s)
--- FAIL: TestSearchWithPlainSQL (0.07s)
--- FAIL: TestScannableSlices (0.02s)

The cockroach guy will be open to helping I suspect

@joeblew99 Are you interfacing with Cockroach through golang? If so, can you point me to some reference documents to get started?

In the cockroach/client repo it says to use a postgres driver, is this how it is to be done at the moment?

Thanks :)

(I would have DM'd you but github for some reason doesn't have this feature.)

Yep that's exactly it.
Use postresql driver and your good.
It's awesome. Later I expect they will extend beyond that but that's for
future stuff.

Joe

On Wed, 3 Feb 2016, 08:25 Paul Mauviel [email protected] wrote:

@joeblew99 https://github.com/joeblew99 Are you interfacing with
Cockroach through golang? If so, can you point me to some reference
documents to get started?

In the cockroach/client repo it says to use a postgres driver, is this how
it is to be done at the moment?

Thanks :)

(I would have DM'd you but github for some reason doesn't have this
feature.)

—
Reply to this email directly or view it on GitHub
https://github.com/jinzhu/gorm/issues/740#issuecomment-179084541.

Thanks!

I hear you've been talking to faddat. I'm the guy working with him. If you have time to chat get in contact through him, I'd like to pick your brain :)

-Paul

Hey Paul,

Sure just hook me up, as I am not sure I know his contacts. Happy to chat / help.

Hello, any update on this? :)
Even by following the guide on cockroach website, it seems not working. I have a bunch of errors like:

(pq: relation "books" does not exist)

GORM and CockroachDB seem to interoperate just fine to me. A common sticking point is that you need to create the database ahead of time, just like you would in PostgreSQL. The example you link contains instructions to create the database - if you do that first, things will work just fine.

Thanks! Let me know if you have more issues, we really want to make sure CockroachDB and GORM work well together.

We think GORM works pretty well with CockroachDB. Is there anything else you think needs to be added on your end or ours?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Quentin-M picture Quentin-M  Â·  3Comments

pjebs picture pjebs  Â·  3Comments

alanyuen picture alanyuen  Â·  3Comments

Ganitzsh picture Ganitzsh  Â·  3Comments

satb picture satb  Â·  3Comments