Skip to content

Rework Sql connections, add Products sql classes#42

Merged
jlpdeveloper merged 6 commits intomainfrom
products-sql
May 1, 2026
Merged

Rework Sql connections, add Products sql classes#42
jlpdeveloper merged 6 commits intomainfrom
products-sql

Conversation

@jlpdeveloper
Copy link
Copy Markdown
Contributor

@jlpdeveloper jlpdeveloper commented May 1, 2026

Description

  • reworks sqlc generated code for existing platforms calls
  • adds products sql and sqlc generated code
  • adds empty handler for future implementations

Code Rabbit Summary

Summary by CodeRabbit

  • New Features

    • Added product management operations and handlers to the API infrastructure.
  • Refactor

    • Restructured the database layer to separate platform and product concerns into distinct modules for improved maintainability and scalability.
    • Introduced a unified Store abstraction to bundle platform and product database operations.

Fixes

Closes #21

Post Deployment Tasks?

@jlpdeveloper jlpdeveloper added this to the Phase 2: API Endpoints milestone May 1, 2026
@jlpdeveloper jlpdeveloper self-assigned this May 1, 2026
@jlpdeveloper jlpdeveloper added enhancement New feature or request skip-changelog Won't be added to the release notes labels May 1, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

📝 Walkthrough

Walkthrough

This PR restructures the database layer from a generic package to domain-driven packages by splitting sqlc configuration to generate separate platform and product database layers, removes the local PlatformQuerier interface in favor of sqlc-generated versions, introduces a new ProductHandler scaffold and product CRUD operations, and adds a Store abstraction bundling both platform and product queries at the application level.

Changes

Cohort / File(s) Summary
Platform API Handler Refactoring
api/platform/create.go, api/platform/get.go, api/platform/update.go
Updated imports from generic products/internal/db to platform-specific products/internal/db/platform package; minimal single-line import changes.
Platform Handler Type Updates
api/platform/platform.go
Changed PlatformHandler.queries field type and NewPlatformHandler parameter from local PlatformQuerier to sqlc-generated platform.Querier; added corresponding import for the platform package.
Platform Querier Removal
api/platform/platform_querier.go
Deleted local PlatformQuerier interface definition (14 lines); interface contract now provided by sqlc-generated platform.Querier.
Platform Test Updates
api/platform/platform_test.go
Updated all mock querier method signatures and test assertions to use platform.* types instead of generic db.* types; adjusted test fixtures and zero-value returns to match platform-specific models.
Product Handler Scaffold
api/product/product.go
Introduced new ProductHandler struct holding product.Querier dependency and established handler foundation for product API operations.
Platform Database Layer
internal/db/platform/db.go, internal/db/platform/models.go, internal/db/platform/querier.go, internal/db/platform/platforms.sql.go
Generated sqlc code for platform package: defines DBTX interface, Queries struct, models (Flow, FlowStep, Platform, Product), and Querier interface; package renamed from db to platform.
Product Database Layer
internal/db/product/db.go, internal/db/product/models.go, internal/db/product/products.sql.go, internal/db/product/querier.go
Generated sqlc code for product package: includes CRUD methods (CreateProduct, DeleteProduct, GetProductById, GetProductsByPlatform, UpdateProduct), parameter structs, and Querier interface with product-specific models.
Store Abstraction
internal/db/store.go
Introduced Store struct bundling platform.Queries and product.Queries; defined DBTX interface specifying Exec, Query, QueryRow methods; New constructor wires both domain-specific query layers.
Product SQL Queries
queries/products.sql
Added five CRUD query definitions for products table: GetProductsByPlatform (:many), GetProductById (:one), CreateProduct (:exec), UpdateProduct (:exec), DeleteProduct (:exec) with named parameters.
sqlc Configuration
sqlc.yml
Split single query generator into two domain-specific generators: one for queries/platforms.sqlinternal/db/platform, another for queries/products.sqlinternal/db/product; added emit_interface: true and explicit output model/SQL package configuration per generator.
Router Wiring
router/router.go
Updated SetupRouter to create store := db.New(dbConn) and pass store.Platform to registerPlatformCallHandler; changed registerPlatformCallHandler signature from generic db.Querier to platformDb.Querier.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • Create Product Handler Package Structure #22: This PR directly addresses the request to create a ProductHandler scaffold by introducing api/product/product.go with a ProductHandler struct wired to the sqlc-generated product.Querier.

Possibly related PRs

  • Adds sqlc and just #16: Both PRs add sqlc-generated database code, models, and query methods, touching the same database abstraction layer and configuration tooling (sqlc.yml, internal/db/ structure).
  • Create Platform Endpoint #17: This PR continues the work of refactoring the platform handler to use sqlc-generated platform.Querier, directly replacing the local PlatformQuerier interface that was removed in the linked PR.

Poem

🐰 A hop through schemas new and neat,
Where platforms dance with products sweet,
Sqlc generates with graceful care,
Domain boundaries in the air! ✨🌱

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Changes include refactoring platform package structure and introducing a ProductHandler, which go beyond the explicit scope of issue #21 requirements. Consider separating platform refactoring and ProductHandler from product SQL implementation, or clarify that architectural improvements were part of the PR's broader goals.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: reworking SQL connections and adding product SQL classes.
Linked Issues check ✅ Passed All coding requirements from issue #21 are met: products SQL queries created, sqlc generated methods and params present, and querier interface updated.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch products-sql

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@api/product/product.go`:
- Around line 1-7: The ProductHandler struct currently declares a queries field
(type product.Querier) but has no methods, causing an unused field/lint error;
remove the dead field from ProductHandler (delete the queries product.Querier
declaration) until you add real handler methods that need product.Querier, or
alternatively add a constructor/usage if you intend immediate use—update
ProductHandler to have no fields for now and keep the package import of
products/internal/db/product only when you reintroduce queries.

In `@internal/db/product/products.sql.go`:
- Around line 14-24: The INSERT uses separate created_at/updated_at params
causing drift; update the SQL constant createProduct to reuse a single named
parameter (e.g. `@timestamp`) for both created_at and updated_at, and adjust the
generated param struct by replacing CreatedAt and UpdatedAt with a single
Timestamp field (type pgtype.Timestamptz) so CreateProduct/CreateProductParams
reflect the single timestamp parameter used in the query.

In `@queries/products.sql`:
- Around line 1-14: The SQL contracts produce the wrong generated API tags and
must match the CRUD spec: keep GetProductsByPlatform (:many) and GetProductById
(:one) as-is, but change any INSERT/UPDATE/DELETE that return an id to use the
:one result tag so the generated product.Querier exposes a single-row return
type; specifically update the CreateProduct, UpdateProduct, and DeleteProduct
declarations to use :one (not :exec) and ensure UpdateProduct's SET list and
params only include name, description, updated_at (no platform_id) and WHERE id
= `@id`, and CreateProduct continues to accept platform_id, name, description,
created_at, updated_at as separate params.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ebbaf853-1c0d-43d0-b8e1-3d358da68ac2

📥 Commits

Reviewing files that changed from the base of the PR and between 7ec5ea6 and 6bee4fd.

📒 Files selected for processing (19)
  • api/platform/create.go
  • api/platform/get.go
  • api/platform/platform.go
  • api/platform/platform_querier.go
  • api/platform/platform_test.go
  • api/platform/update.go
  • api/product/product.go
  • internal/db/platform/db.go
  • internal/db/platform/models.go
  • internal/db/platform/platforms.sql.go
  • internal/db/platform/querier.go
  • internal/db/product/db.go
  • internal/db/product/models.go
  • internal/db/product/products.sql.go
  • internal/db/product/querier.go
  • internal/db/store.go
  • queries/products.sql
  • router/router.go
  • sqlc.yml
💤 Files with no reviewable changes (1)
  • api/platform/platform_querier.go

Comment thread api/product/product.go
Comment thread internal/db/product/products.sql.go
Comment thread queries/products.sql
@jlpdeveloper jlpdeveloper merged commit 8c2edd4 into main May 1, 2026
3 checks passed
@jlpdeveloper jlpdeveloper deleted the products-sql branch May 1, 2026 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request skip-changelog Won't be added to the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Sql and Generate Sqlc Code

1 participant