{"id":21042687,"url":"https://github.com/yugabytedb-samples/orm-examples","last_synced_at":"2025-05-15T17:30:58.179Z","repository":{"id":37103875,"uuid":"174637549","full_name":"YugabyteDB-Samples/orm-examples","owner":"YugabyteDB-Samples","description":"Examples showing how to use various ORMs with YSQL","archived":false,"fork":false,"pushed_at":"2024-08-02T09:32:56.000Z","size":800,"stargazers_count":32,"open_issues_count":23,"forks_count":21,"subscribers_count":58,"default_branch":"master","last_synced_at":"2025-04-03T12:11:23.131Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","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/YugabyteDB-Samples.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":"2019-03-09T02:13:37.000Z","updated_at":"2024-07-04T02:21:13.000Z","dependencies_parsed_at":"2024-04-03T11:27:21.301Z","dependency_job_id":"c8039929-636d-4632-868b-b386fcd3568b","html_url":"https://github.com/YugabyteDB-Samples/orm-examples","commit_stats":null,"previous_names":["yugabyte/orm-examples"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Form-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Form-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Form-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YugabyteDB-Samples%2Form-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YugabyteDB-Samples","download_url":"https://codeload.github.com/YugabyteDB-Samples/orm-examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254388052,"owners_count":22062976,"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":[],"created_at":"2024-11-19T14:08:40.843Z","updated_at":"2025-05-15T17:30:57.735Z","avatar_url":"https://github.com/YugabyteDB-Samples.png","language":"Java","readme":"# Using ORMs with YugabyteDB\n\nThis repository has examples showing build a simple REST API server using ORMs on top of YugabyteDB (using the YSQL API). The scenario modelled is that of a simple online e-commerce store. It consists of the following.\n\n* The users of the ecommerce site are stored in the `users` table.\n* The `products` table contains a list of products the ecommerce site sells.\n* The orders placed by the users are populated in the `orders` table. An order can consist of multiple line items, each of these are inserted in the `orderline` table.\n\n## Step 1. Install YugabyteDB\n\nYou should first [install YugabyteDB](https://docs.yugabyte.com/latest/quick-start/), which is a distributed SQL database compatible with the PostgreSQL language.\n\n## Step 2. Bring up the REST API server\n\nThe same REST APIs are implemented using various ORMs. Each of these is present in one of the sub-directories in this repo. For example, to start the REST API server using `Spring`, simply go to the appropriate directory and follow the instructions there.\n\nBy default, the REST API server listens on `localhost` port `8080`.\n\n| Directory  | ORM |\n| ------------- | ------------- |\n| [Java - Spring](https://github.com/YugaByte/orm-examples/blob/master/java/spring)  | Spring Data JPA (uses Hibernate internally)   |\n| [Core Java - Hibernate](https://github.com/YugaByte/orm-examples/blob/master/java/hibernate)  | Core Java - Hibernate Example   |\n| [Java - Mybatis](https://github.com/YugaByte/orm-examples/blob/master/java/mybatis)  | Java - Mybatis Example   |\n| [Scala - Play](https://github.com/YugaByte/orm-examples/blob/master/java/ebean)  | Play Framework Example   |\n| [Golang - Gorm](https://github.com/YugaByte/orm-examples/blob/master/golang/gorm)  | Gorm   |\n| [NodeJS - Sequelize](https://github.com/YugaByte/orm-examples/blob/master/node/sequelize)  | Sequelize   |\n| [Python - SQLAlchemy](https://github.com/YugaByte/orm-examples/blob/master/python/sqlalchemy)  | SQL Alchemy   |\n| [Python - django](https://github.com/YugaByte/orm-examples/blob/master/python/django)  | Django   |\n| [Ruby on Rails - ActiveRecord](https://github.com/YugaByte/orm-examples/tree/master/ruby/ror)  | ActiveRecord   |\n| [Rust - Diesel](https://github.com/YugaByte/orm-examples/blob/master/rust/diesel)  | Rust Diesel   |\n| [C# - Dapper](https://github.com/YugaByte/orm-examples/blob/master/csharp/dapper)  | Dapper   |\n| [Php - Laravel](https://github.com/YugaByte/orm-examples/blob/master/php/laravel/)  | Php Laravel   |\n\n\n\n## Step 3. Create a user\n\nYou can create a user named `John Smith` and email `jsmith@example.com` as follows:\n\n```\n$ curl --data '{ \"firstName\" : \"John\", \"lastName\" : \"Smith\", \"email\" : \"jsmith@example.com\" }' \\\n       -v -X POST -H 'Content-Type:application/json' http://localhost:8080/users\n```\n\nThis will return the inserted record as a JSON document:\n```\n{\n  \"userId\": \"1\",\n  \"firstName\": \"John\",\n  \"lastName\": \"Smith\",\n  \"email\": \"jsmith@example.com\"\n}\n```\n\nYou can connect to YugabyteDB using `psql` and select these records:\n```\npostgres=# select * from users;\n user_id | first_name | last_name |  user_email\n---------+------------+-----------+---------------\n       1 | John       | Smith     | jsmith@example.com(1 row)\n```\n\n## Step 4. List all users\n\nYou can list the current set of users by running the following:\n```\n$ curl http://localhost:8080/users\n```\n\nYou should see the following output:\n```\n{\n  \"content\": [\n    {\n      \"userId\":\"1\",\n      \"email\":\"jsmith@example.com\",\n      \"firstName\":\"John\",\n      \"lastName\":\"Smith\"\n    }\n  ],\n  ...\n}\n```\n\n## Step 5. Create a product\n\nYou can create a product listing as follows:\n```\n$ curl \\\n  --data '{ \"productName\": \"Notebook\", \"description\": \"200 page notebook\", \"price\": 7.50 }' \\\n  -v -X POST -H 'Content-Type:application/json' http://localhost:8080/products\n```\n\nYou should see the following return value:\n```\n{\n  \"productId\": \"1\",\n  \"productName\": \"Notebook\",\n  \"description\": \"200 page, hardbound, blank notebook\",\n  \"price\": 7.5}\n```\n\n## Step 6. List all products\n\nYou can do this as follows:\n```\n$ curl http://localhost:8080/products\n```\n\nYou should see an output as follows:\n```\n{\n  \"content\":[\n    {\n      \"productId\": \"1\",\n      \"productName\": \"Notebook\",\"description\":\"200 page, hardbound, blank notebook\",\n      \"price\": 7.5\n    }\n  ],\n  ...\n}\n```\n\n## Step 7. Create an order\n\nCreating an order involves a user id ordering a particular product, this can be achieved as follows:\n```\n$ curl \\\n  --data '{ \"userId\": \"1\", \"products\": [ { \"productId\": 1, \"units\": 2 } ] }' \\\n  -v -X POST -H 'Content-Type:application/json' http://localhost:8080/orders\n```\n\nYou should see the following return value:\n```\nTBD\n```\n\nNote that you can check out multiple products in one order. As an example, the following POST payload makes one user (id=1) checkout two products (id=1 and id=2) by creating the following payload:\n\n```\n{ \"userId\": \"1\", \"products\": [ { \"productId\": 1, \"units\": 2 }, { \"productId\": 2, \"units\": 4 } ] }\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyugabytedb-samples%2Form-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyugabytedb-samples%2Form-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyugabytedb-samples%2Form-examples/lists"}