{"id":28763792,"url":"https://github.com/cockroachdb/examples-orms","last_synced_at":"2025-06-17T09:10:30.410Z","repository":{"id":9691658,"uuid":"61854737","full_name":"cockroachdb/examples-orms","owner":"cockroachdb","description":"Sample uses of CockroachDB with popular ORMs","archived":false,"fork":false,"pushed_at":"2025-01-30T22:36:02.000Z","size":768,"stargazers_count":82,"open_issues_count":16,"forks_count":36,"subscribers_count":55,"default_branch":"master","last_synced_at":"2025-06-13T14:02:32.247Z","etag":null,"topics":["cockroachdb","orm","sql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cockroachdb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2016-06-24T03:34:56.000Z","updated_at":"2025-02-05T07:25:01.000Z","dependencies_parsed_at":"2024-02-21T19:53:22.800Z","dependency_job_id":null,"html_url":"https://github.com/cockroachdb/examples-orms","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cockroachdb/examples-orms","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cockroachdb%2Fexamples-orms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cockroachdb%2Fexamples-orms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cockroachdb%2Fexamples-orms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cockroachdb%2Fexamples-orms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cockroachdb","download_url":"https://codeload.github.com/cockroachdb/examples-orms/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cockroachdb%2Fexamples-orms/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260326793,"owners_count":22992388,"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","orm","sql"],"created_at":"2025-06-17T09:10:28.238Z","updated_at":"2025-06-17T09:10:30.402Z","avatar_url":"https://github.com/cockroachdb.png","language":"Go","readme":"# Cockroach ORM examples\n\nThis repo contains example uses of CockroachDB with popular ORMs.\nEach example will implement the [sample application](#sample-app)\nspec presented below.\n\nSee the [CockroachDB ORM Compatibility Plan](https://docs.google.com/a/cockroachlabs.com/spreadsheets/d/17A0EflPqI9yhargK0n4tSw2WogQuVc5YeK-VFmKvXHM/edit?usp=sharing)\nfor a roadmap towards supporting various ORMs.\n\n## Installation\n\nClone this repo into your `$GOPATH` manually, e.g.,\n\n```bash\n$ cd ~/go/src/github.com/cockroachdb\n$ git clone https://github.com/cockroachdb/examples-orms\n```\n\nThis is required because this project uses Go to drive the automated tests, so it will look for things in your `$GOPATH`.  If you try to clone it to a non-`$GOPATH` directory, it will fail roughly as follows:\n\n```bash\n$ cd ~/some/random/dir/examples-orms\n$ make test\ngo test -v -i ./testing\ntesting/api_handler.go:13:2: cannot find package \"github.com/cockroachdb/examples-orms/go/gorm/model\" in any of:\n\t/usr/local/Cellar/go/1.10/libexec/src/github.com/cockroachdb/examples-orms/go/gorm/model (from $GOROOT)\n\t/Users/rloveland/go/src/github.com/cockroachdb/examples-orms/go/gorm/model (from $GOPATH)\ntesting/api_handler.go:11:2: cannot find package \"github.com/pkg/errors\" in any of:\n\t/usr/local/Cellar/go/1.10/libexec/src/github.com/pkg/errors (from $GOROOT)\n\t/Users/rloveland/go/src/github.com/pkg/errors (from $GOPATH)\nmake: *** [test] Error 1\n```\n\nHowever, this is not actually a Go project, so `go get -d` will also fail (hence the need to manually clone).\n\n```bash\n$ go get -d github.com/cockroachdb/examples-orms\npackage github.com/cockroachdb/examples-orms: no Go files in /Users/rloveland/go/src/github.com/cockroachdb/examples-orms\n```\n\n## Testing\n\nTo run automated testing against all ORMs using the latest binary of CockroachDB, run:\n\n```bash\n$ make test\n```\n\nTo run automated testing against all ORMs using a custom CockroachDB binary, run:\n\n```bash\n$ make test COCKROACH_BINARY=/path/to/binary/cockroach\n```\n\nTo run automated testing against a specific ORM, you can also specify the name with:\n\n```bash\n$ make test COCKROACH_BINARY=/path/to/binary/cockroach TESTS=TestSequelize/password\n```\n\nThese tests require dependencies to be installed on your system. You can install them with:\n\n```bash\n$ make deps\n```\n\nWhile running tests locally, you may find it useful to comment out the lines in the Makefile that\ninstall the dependencies for a tool that you don't want to test.\n\nA final option is to run using docker, so that a reproducible build environment is used.\n\n```bash\n$ make dockertest COCKROACH_BINARY=/path/to/binary/cockroach\n```\n\n## Project Structure\n\nThe repository contains a set of directories named after programming\nlanguages. Beneath these language directories are sub-directories\nnamed after specific ORM used for example application implementations.\n\nEach ORM example uses whatever build tool is standard for the language,\nbut provides a standardized Makefile with a `start` rule, which will\nstart an instance of the sample application.\n\nFor instance, the directory structure for an example application of the\nHibernate ORM will look like:\n\n```\njava\n└── hibernate\n    ├── Makefile\n    └── example_source\n```\n\n## Sample App\n\nThe sample application which each example implements is a [JSON REST API](#json-api)\nmodeling a **company** with **customers, products, and orders**. The API\nexposes access to the management of this company.\n\nThe purpose of the example application is to test common data access patterns\nso that we can stress various features and implementation details of each\nlanguage/ORM.\n\n### Schema\n\nAn ideal schema diagram for the sample application looks like:\n\n```\nCustomer\n  |\n  v\nOrder  \u003c-\u003e  Product\n```\n\nThe schema is implemented by each application using ORM-specific constructs to look as\nclose as possible to:\n\n```sql\nCREATE DATABASE IF NOT EXISTS company_{language}_{ORM};\n\nCREATE TABLE IF NOT EXISTS customers (\n  id           SERIAL PRIMARY KEY,\n  name         STRING\n);\n\nCREATE TABLE IF NOT EXISTS orders (\n  id           SERIAL PRIMARY KEY,\n  subtotal     DECIMAL(18,2)\n  customer_id  INT    REFERENCES customers(id),\n);\n\nCREATE TABLE IF NOT EXISTS products (\n  id           SERIAL PRIMARY KEY,\n  name         STRING,\n  price        DECIMAL(18,2)\n);\n\nCREATE TABLE IF NOT EXISTS product_orders (\n  id           SERIAL PRIMARY KEY,\n  product_id   INT    REFERENCES products(id),\n  order_id     INT    REFERENCES orders(id) ON DELETE CASCADE\n);\n```\n\n### JSON API\n\nEach example will expose a RESTful JSON API. The endpoints and example `curl`\ncommand lines are:\n\n```\nGET    /customer\n    curl http://localhost:6543/customer\n\nGET    /customer/:id\n    curl http://localhost:6543/customer/1\n\nPOST   /customer\n    curl -X POST -d '{\"id\": 1, \"name\": \"bob\"}' http://localhost:6543/customer\n\nPUT    /customer/:id\n    curl -X PUT -d '{\"id\": 2, \"name\": \"robert\"}' http://localhost:6543/customer/1\n\nDELETE /customer\n    curl -X DELETE http://localhost:6543/customer/1\n\nGET    /product\n    curl http://localhost:6543/product\n\nGET    /product/:id\n    curl http://localhost:6543/product/1\n\nPOST   /product\n    curl -X POST -d '{\"id\": 1, \"name\": \"apple\", \"price\": 0.30}' http://localhost:6543/product\n\nPUT    /product\nDELETE /product\n\nGET    /order\n    curl http://localhost:6543/order\n\nGET    /order/:id\n    curl http://localhost:6543/order/1\n\nPOST   /order\n    curl -X POST -d '{\"id\": 1, \"subtotal\": 18.2, \"customer\": {\"id\": 1}}' http://localhost:6543/order\n\nPUT    /order\nDELETE /order\n```\n\nThe semantics of each endpoint will be fleshed out when necessary.\n\n## Unresolved Questions\n\n- Can the schema be completely standardized across ORMs without too\n  much of a hassle with overriding default type and naming conventions?\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcockroachdb%2Fexamples-orms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcockroachdb%2Fexamples-orms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcockroachdb%2Fexamples-orms/lists"}