Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GORM example to use latest GO version + GORM v2 + pgx Smart Driver #115

Merged
merged 3 commits into from
Apr 11, 2024

Conversation

Sfurti-yb
Copy link
Collaborator

These changes are to:

  • Update the app to use latest go functionalities
  • Upgrade to gorm v2
  • Use Yugabytedb go smart driver

Changes made:

  1. README - Updated steps to run the app
  2. Changed "github.com/jinzhu/gorm/dialects/postgres" => "github.com/yugabyte/gorm-yugabytedb" for yugabytedb smart driver
  3. Changed "github.com/jinzhu/gorm" => "gorm.io/gorm" for GORM v2
  4. Removed dbConn.Model(&model.Tablename{}).AddForeignKey() since it is no longer supported in GORM v2. Instead added the same constraints during model declaration
  5. Removed explicit orderline table insert since it is done when order table insert is done.

Testing:
After running the app follow the steps here to do inserts: https://docs.yugabyte.com/stable/drivers-orms/orms/go/ysql-gorm/#send-requests-to-the-application
Note: For order creation, instead of :

curl \
  --data '{ "userId": "2", "products": [ { "productId": 1, "units": 2 } ] }' \
  -v -X POST -H 'Content-Type:application/json' http://localhost:8080/orders

use:

curl \
  --data '{ "userId": 2, "products": [ { "productId": 1, "units": 2 } ] }' \
  -v -X POST -H 'Content-Type:application/json' http://localhost:8080/orders

The docs have an error.

Copy link
Collaborator

@HarshDaryani896 HarshDaryani896 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Please update gorm-yugabytedb to use the latest Yugabytedb pgx smart driver.

| `password` | The password to connect to the database. Leave blank for the password. | - |

| `username` | The username to connect to the database. | `yugabyte` |
| `password` | The password to connect to the database. Leave blank for the password. | `yugabyte` |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Remove Leave blank for the password.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants