{"id":20285446,"url":"https://github.com/mramshaw/restful-cockroach","last_synced_at":"2026-05-07T13:47:35.068Z","repository":{"id":92906138,"uuid":"127979402","full_name":"mramshaw/RESTful-Cockroach","owner":"mramshaw","description":"An experiment with using CockroachDB as a drop-in replacement for PostgreSQL","archived":false,"fork":false,"pushed_at":"2019-02-27T20:13:34.000Z","size":92,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-04T03:44:34.130Z","etag":null,"topics":["cockroachdb","docker","docker-compose","go","golang","restful","tdd"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mramshaw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-03T23:15:45.000Z","updated_at":"2020-11-09T12:54:48.000Z","dependencies_parsed_at":"2023-04-29T00:55:15.456Z","dependency_job_id":null,"html_url":"https://github.com/mramshaw/RESTful-Cockroach","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mramshaw/RESTful-Cockroach","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FRESTful-Cockroach","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FRESTful-Cockroach/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FRESTful-Cockroach/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FRESTful-Cockroach/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mramshaw","download_url":"https://codeload.github.com/mramshaw/RESTful-Cockroach/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mramshaw%2FRESTful-Cockroach/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261495834,"owners_count":23167382,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cockroachdb","docker","docker-compose","go","golang","restful","tdd"],"created_at":"2024-11-14T14:26:44.342Z","updated_at":"2026-05-07T13:47:33.048Z","avatar_url":"https://github.com/mramshaw.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RESTful Cockroach\n\nAn experiment with using [CockroachDB](https://github.com/cockroachdb/cockroach/) as\na drop-in replacement for PostgreSQL.\n\nThis builds on my [RESTful-Recipes](https://github.com/mramshaw/RESTful-Recipes) repo,\nwhich stores data in [PostgreSQL](https://www.postgresql.org/). As CockroachDB uses both\nthe PostgreSQL wire protocol and the Golang driver - while RESTFul-Recipes has acceptance\ntests - this is an effort to see how easy it is to use CockroachDB instead of PostgreSQL.\n\nAll dependencies are handled via [Docker](https://www.docker.com/products/docker) and __docker-compose__.\n\nTDD (Test-Driven Development) is implemented; the build will fail if the tests do not pass.\n\nLikewise the build will fail if either __golint__ or __go vet__ fails.\n\nEnforces industry-standard __gofmt__ code formatting.\n\nAll testing can be done with [curl](CURLs.txt).\n\n\n## Features\n\n- uses [Gorilla MUX](https://github.com/Gorilla/mux)\n- uses [Pure Go postgres driver](https://github.com/lib/pq)\n\n\n## CockroachDB\n\nAccording to [Cockroach Labs](https://www.cockroachlabs.com/), cockroach was designed to\nbe a distributed, fault-tolerant database along the lines of Google's Cloud Spanner.\n\nCertainly replicating databases in the cloud is a non-trivial exercise, so this sounded\nlike an interesting product to have a look at. As this is purely a compatibility exercise,\nthere will be no database replication.\n\n\n## Getting familiar with CockroachDB\n\nThe following link will probably be very helpful:\n\n    https://www.cockroachlabs.com/docs/stable/start-a-local-cluster-in-docker.html#os-linux\n\nIt seems that the master node is started with `start --insecure` (we are using insecure mode for testing)\nwhile the slave nodes are started with `start --insecure --join=xxxxxx`. And that's it!\n\nThe results should look as follows:\n\n    $ docker ps\n    CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                                              NAMES\n    30fe256e9301        cockroachdb/cockroach:v1.1.7   \"/cockroach/cockroac…\"   2 seconds ago       Up 2 seconds        8080/tcp, 26257/tcp                                roach3\n    01d7db6e5f9a        cockroachdb/cockroach:v1.1.7   \"/cockroach/cockroac…\"   28 seconds ago      Up 28 seconds       8080/tcp, 26257/tcp                                roach2\n    5f0e3afea0a8        cockroachdb/cockroach:v1.1.7   \"/cockroach/cockroac…\"   10 minutes ago      Up 10 minutes       0.0.0.0:8080-\u003e8080/tcp, 0.0.0.0:26257-\u003e26257/tcp   roach1\n    $\n\nInsert into master (the performance stats are a nice touch):\n\n    $ docker exec -it roach1 ./cockroach sql --insecure\n    # Welcome to the cockroach SQL interface.\n    # All statements must be terminated by a semicolon.\n    # To exit: CTRL + D.\n    #\n    # Server version: CockroachDB CCL v1.1.7 (linux amd64, built 2018/03/26 15:56:41, go1.8.3) (same version as client)\n    # Cluster ID: d9d00482-ea21-4cc1-b0e5-481e2cca8022\n    #\n    # Enter \\? for a brief introduction.\n    #\n    root@:26257/\u003e CREATE DATABASE bank;\n    CREATE DATABASE\n    \n    Time: 291.557247ms\n    \n    root@:26257/\u003e CREATE TABLE bank.accounts (id INT PRIMARY KEY, balance DECIMAL);\n    CREATE TABLE\n    \n    Time: 254.09533ms\n    \n    root@:26257/\u003e INSERT INTO bank.accounts VALUES (1, 1000.50);\n    INSERT 1\n    \n    Time: 270.104136ms\n    \n    root@:26257/\u003e SELECT * FROM bank.accounts;\n    +----+---------+\n    | id | balance |\n    +----+---------+\n    |  1 | 1000.50 |\n    +----+---------+\n    (1 row)\n    \n    Time: 1.295917ms\n    \n    root@:26257/\u003e \\q\n    $\n\nQuery a replica:\n\n    $ docker exec -it roach2 ./cockroach sql --insecure\n    # Welcome to the cockroach SQL interface.\n    # All statements must be terminated by a semicolon.\n    # To exit: CTRL + D.\n    #\n    # Server version: CockroachDB CCL v1.1.7 (linux amd64, built 2018/03/26 15:56:41, go1.8.3) (same version as client)\n    # Cluster ID: d9d00482-ea21-4cc1-b0e5-481e2cca8022\n    #\n    # Enter \\? for a brief introduction.\n    #\n    root@:26257/\u003e SELECT * FROM bank.accounts;\n    +----+---------+\n    | id | balance |\n    +----+---------+\n    |  1 | 1000.50 |\n    +----+---------+\n    (1 row)\n    \n    Time: 128.987392ms\n    \n    root@:26257/\u003e \\q\n    $\n\nCockroach comes with a sweet UI (which uses port 8080):\n\n![Cockroach_UI](images/Cockroach_UI.png)\n\n\n## To Run\n\nThe command to run:\n\n    $ docker-compose up -d\n\nFor the first run, there will be a warning as `mramshaw4docs/golang-alpine-cockroach:1.8` must be built.\n\nThis image will contain all of the Go dependencies and should only need to be built once.\n\nFor the very first run, `golang` may fail as it takes `cockroach` some time to ramp up.\n\nA successful `golang` startup should show the following as the last line of `docker-compose logs golang`:\n\n    golang_1    | 2018/02/24 18:38:01 Now serving recipes ...\n\nIf this line does not appear, repeat the `docker-compose up -d` command (there is no penalty for this).\n\n\n## To Build:\n\nThe command to run:\n\n    $ docker-compose up -d\n\nOnce `make` indicates that `restful_cockroach` has been built, can change `docker-compose.yml` as follows:\n\n1) Comment `command: make`\n\n2) Uncomment `command: ./restful_cockroach`\n\n\n## For testing:\n\n[Optional] Start cockroach:\n\n    $ docker-compose up -d cockroach\n\nStart golang [if cockroach is not running, this step will start it]:\n\n    $ docker-compose run --publish 80:8100 golang make\n\nSuccessful startup will be indicated as follows:\n\n    2018/02/24 16:27:10 Now serving recipes ...\n\nThis should make the web service available at:\n\n    http://localhost/v1/recipes\n\nOnce the service is running, it is possible to `curl` it. Check `CURLs.txt` for examples.\n\n\n## See what's running:\n\nThe command to run:\n\n    $ docker ps\n\n\n## View the build and/or execution logs\n\nThe command to run:\n\n    $ docker-compose logs golang\n\n\n## To Shutdown:\n\nThe command to run:\n\n    $ docker-compose down\n\n\n## Clean Up\n\nThe command to run:\n\n    $ docker-compose run golang make clean\n\n\n## Results\n\nAt least with the current release (v1.1.7) of CockroachDB, the features I use are not all there:\n\n    $ docker-compose up golang\n    restfulcockroach_cockroach_1 is up-to-date\n    Starting restfulcockroach_golang_1 ... \n    Starting restfulcockroach_golang_1 ... done\n    Attaching to restfulcockroach_golang_1\n    golang_1     | GOPATH=/go GOOS=linux GOARCH=amd64 gofmt -d -e -s -w *.go\n    golang_1     | GOPATH=/go GOOS=linux GOARCH=amd64 gofmt -d -e -s -w application/*.go\n    golang_1     | GOPATH=/go GOOS=linux GOARCH=amd64 gofmt -d -e -s -w recipes/*.go\n    golang_1     | GOPATH=/go GOOS=linux GOARCH=amd64 gofmt -d -e -s -w test/*.go\n    golang_1     | GOPATH=/go GOOS=linux GOARCH=amd64 golint -set_exit_status *.go\n    golang_1     | GOPATH=/go GOOS=linux GOARCH=amd64 golint -set_exit_status ./...\n    golang_1     | GOPATH=/go GOOS=linux GOARCH=amd64 go tool vet *.go\n    golang_1     | GOPATH=/go GOOS=linux GOARCH=amd64 go tool vet application/*.go\n    golang_1     | GOPATH=/go GOOS=linux GOARCH=amd64 go tool vet recipes/*.go\n    golang_1     | GOPATH=/go GOOS=linux GOARCH=amd64 go tool vet test/*.go\n    golang_1     | GOPATH=/go GOOS=linux GOARCH=amd64 go test -v test\n    golang_1     | 2018/04/03 20:38:00 pq: unimplemented at or near \"cascade\"\n    golang_1     | exit status 1\n    golang_1     | FAIL\ttest\t0.010s\n    golang_1     | make: *** [Makefile:33: test] Error 1\n    restfulcockroach_golang_1 exited with code 2\n    $\n\nI thought my SQL was pretty vanilla, but it seems cascading deletes are not available.\n\nEven so, it does seem that \"ON DELETE CASCADE\" is on the radar for the future.\n\n\n## To Do\n\n- [ ] Upgrade to latest Go\n- [ ] Fix database initialization script (currently must run manually)\n- [ ] Try again with the next point release of CockroachDB\n- [ ] Investigate the feature roadmap of CockroachDB\n\n\n## Credits\n\nThis exercise was inspired by the following episode of __Go Time__:\n\n    https://changelog.com/gotime/73\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmramshaw%2Frestful-cockroach","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmramshaw%2Frestful-cockroach","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmramshaw%2Frestful-cockroach/lists"}