backend-reference
backend-reference copied to clipboard
go-api: Postgres & sqlc
What's this PR do?
Go API using PostgresQL as DB and sqlc as a query generator.
Summary by CodeRabbit
-
New Features
- Introduced a Go API project with PostgreSQL, utilizing Docker Compose for containerization.
- Added functionality for user operations, including listing users, getting a user by ID, and creating a new user.
-
Documentation
- Updated README with detailed setup instructions, query generation, and application execution.
-
Chores
- Added a
.gitignorefile to exclude specific directories. - Implemented SQL queries for user management and database schema for user table creation.
- Added a
Walkthrough
This update introduces a comprehensive setup for a Golang API with a PostgreSQL database. It includes a multi-stage Dockerfile, Docker Compose configuration, database migrations, SQL queries, and a REST API with user management capabilities. The project is structured to leverage sqlc for SQL query generation and includes handlers, services, and repositories to manage user data.
Changes
| File(s) | Change Summary |
|---|---|
.gitignore |
Updated to ignore binaries, test outputs, dependency directories, workspace files, and specific directories like users/ and data/. |
Dockerfile |
New multi-stage Dockerfile for building and running the Golang application using gcr.io/distroless/base-debian12. |
README.md |
Instructions for containerizing the Go API and PostgreSQL database using Docker Compose, with emphasis on sqlc for SQL queries and models generation. |
compose.yml |
Docker Compose configuration for setting up PostgreSQL and Golang API services. |
db/database.go |
Defines DB struct and New function for database connection initialization. |
db/migrations/schema.sql |
SQL script for creating a users table with user details. |
db/query/user.sql |
SQL queries for user operations like getting a user by ID, listing all users, and creating a new user. |
db/sqlc/db.go, db/sqlc/models.go, db/sqlc/querier.go, db/sqlc/user.sql.go |
Definitions for database transactions, user struct, querier interface, and generated code for database interaction. |
handler/handler.go |
Functionality for handling HTTP requests related to user management, including listing users, getting user by ID, and creating new users. |
main.go |
Sets up a REST API using Gorilla Mux, connects to PostgreSQL, performs migrations, and defines routes for user operations. |
model/model.go |
Defines a User struct for user details. |
repository/repository.go |
Introduces IUserRepository interface and UserRepository struct for user data access methods. |
service/service.go |
Defines IUserService interface and UserService struct for user-related operations using a repository. |
sqlc.yaml |
Configuration settings for SQLC code generation for the Golang API with PostgreSQL. |
.sqlfluff |
Configuration setting for sqlfluff to specify the SQL dialect as postgres. |
In code we trust, our API's might, With Docker's touch, we launch the flight. PostgreSQL stands strong, a data knight,
sqlccrafts queries, pure delight. Users join, our app ignites, A rabbit's joy, code's shining light. 🐇✨
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai generate interesting stats about this repository and render them as a table.@coderabbitai show all the console.log statements in this repository.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (invoked as PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger a review. This is useful when automatic reviews are disabled for the repository.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai helpto get help.
Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
CodeRabbit Configration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
| Warnings | |
|---|---|
| :warning: | This PR is changing more than 200 lines. |
| :warning: | This PR is changing more than 10 files. |
| Messages | |
|---|---|
| :book: | Thanks for updating docs! We :heart: documentation! |
Generated by :no_entry_sign: dangerJS against 44ad8f0a1365dc376221072092bb61836530525f