|
1 | | -# examples-orms |
2 | | -Sample uses of CockroachDB with popular ORMs |
| 1 | +# Cockroach ORM examples |
| 2 | + |
| 3 | +This repo contains example uses of CockroachDB with popular ORMs. |
| 4 | +Each example will implement the [sample application](#sample-app) |
| 5 | +spec presented below. |
| 6 | + |
| 7 | +See the [CockroachDB ORM Compatibility Plan](https://docs.google.com/a/cockroachlabs.com/spreadsheets/d/17A0EflPqI9yhargK0n4tSw2WogQuVc5YeK-VFmKvXHM/edit?usp=sharing) |
| 8 | +for a roadmap towards supporting various ORMs. |
| 9 | + |
| 10 | +## Project Structure |
| 11 | + |
| 12 | +The repository contains a set of directories named after programming |
| 13 | +languages. Beneath these language directories are sub-directories |
| 14 | +named after specific ORM used for example application implementations. |
| 15 | + |
| 16 | +Each ORM example uses whatever build tool is standard for the language, |
| 17 | +but provides a standardized Makefile with a `start` rule, which will |
| 18 | +start an instance of the sample application. |
| 19 | + |
| 20 | +For instance, the directory structure for an example application of the |
| 21 | +Hibernate ORM will look like: |
| 22 | + |
| 23 | +``` |
| 24 | +java |
| 25 | +└── hibernate |
| 26 | + ├── Makefile |
| 27 | + └── example_source |
| 28 | +``` |
| 29 | + |
| 30 | +## Sample App |
| 31 | + |
| 32 | +The sample application which each example implements is a [JSON REST API](#json-api) |
| 33 | +modeling a **company** with **customers, products, and orders**. The API |
| 34 | +exposes access to the management of this company. |
| 35 | + |
| 36 | +The purpose of the example application is to test common data access patterns |
| 37 | +so that we can stress various features and implementation details of each |
| 38 | +language/ORM. |
| 39 | + |
| 40 | +### Schema |
| 41 | + |
| 42 | +A schema diagram for the sample application looks like: |
| 43 | + |
| 44 | +``` |
| 45 | +Customer |
| 46 | + | |
| 47 | + v |
| 48 | +Order <-> Product |
| 49 | +``` |
| 50 | + |
| 51 | +The schema is implemented to look as close as possible to: |
| 52 | + |
| 53 | +```sql |
| 54 | +CREATE DATABASE IF NOT EXISTS company_{language}_{ORM}; |
| 55 | + |
| 56 | +CREATE TABLE IF NOT EXISTS customers ( |
| 57 | + id SERIAL PRIMARY KEY, |
| 58 | + name STRING |
| 59 | +); |
| 60 | + |
| 61 | +CREATE TABLE IF NOT EXISTS orders ( |
| 62 | + id SERIAL PRIMARY KEY, |
| 63 | + subtotal DECIMAL(18,2) |
| 64 | + customer_id INT REFERENCES customers(id), |
| 65 | +); |
| 66 | + |
| 67 | +CREATE TABLE IF NOT EXISTS products ( |
| 68 | + id SERIAL PRIMARY KEY, |
| 69 | + name STRING, |
| 70 | + price DECIMAL(18,2) |
| 71 | +); |
| 72 | + |
| 73 | +CREATE TABLE IF NOT EXISTS product_orders ( |
| 74 | + id SERIAL PRIMARY KEY, |
| 75 | + product_id INT REFERENCES products(id), |
| 76 | + order_id INT REFERENCES orders(id) ON DELETE CASCADE |
| 77 | +); |
| 78 | +``` |
| 79 | + |
| 80 | +### JSON API |
| 81 | + |
| 82 | +Each example will expose a RESTful JSON API with the following endpoints: |
| 83 | + |
| 84 | +``` |
| 85 | +GET /customer |
| 86 | +GET /customer/:id |
| 87 | +POST /customer |
| 88 | +PUT /customer |
| 89 | +DELETE /customer |
| 90 | +
|
| 91 | +GET /product |
| 92 | +GET /product/:id |
| 93 | +POST /product |
| 94 | +PUT /product |
| 95 | +DELETE /product |
| 96 | +
|
| 97 | +GET /order |
| 98 | +GET /order/:id |
| 99 | +POST /order |
| 100 | +PUT /order |
| 101 | +DELETE /order |
| 102 | +``` |
| 103 | + |
| 104 | +The semantics of each endpoint will be fleshed out when necessary. |
| 105 | + |
| 106 | +## Testing |
| 107 | + |
| 108 | +_Automated testing does not have to be included in the initial development of this repo._ |
| 109 | + |
| 110 | +To test each application, a CockroachDB instance will be spun up, and |
| 111 | +each test example will be run against it in a Docker container using `make start`. |
| 112 | +A series of HTTP requests with an expected output will be issued against each example, |
| 113 | +and the results will be verified. |
| 114 | + |
| 115 | +## Unresolved Questions |
| 116 | + |
| 117 | +- Can the schema be completely standardized across ORMs without too |
| 118 | + much of a hassle with overriding default type and naming conventions? |
0 commit comments