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

Policy: PolicyDBClient struct should not expose SQLC query generated functions #1652

Open
ryanulit opened this issue Oct 15, 2024 · 1 comment

Comments

@ryanulit
Copy link
Contributor

ryanulit commented Oct 15, 2024

Background

The PolicyDBClient struct uses composition to expose all SQLC generated queries as functions callable from that struct. While this does simplify interaction with those functions, it also has unintended consequences:

  1. Since the service layer uses the PolicyDBClient struct to make calls to the DB layer methods, a developer could accidentally bypass the DB layer and call a SQLC generated method directly that was never meant to be exposed to the service layer. DB layer methods handle the appropriate transformations from SQLC generated structs to policy objects, and thus should be the only DB-specific methods called from the service layer.

  2. Bloated intellisense exacerbates the first issue, as it's not entirely clear to the developer which method is SQLC generated vs one that was intentionally written in the DB layer.

Acceptance Criteria

  • Only intentionally written DB layer methods are exposed by the PolicyDBClient
  • All unit and integration tests continue to pass

Possible solutions that need further investigation:

  • Update all SQLC query names to use lowercase for the leading character to tell Go not to expose them as public
  • Refactor the PolicyDBClient to no longer use composition with the Queries struct and use global variable for Queries that is only referenced within the db package
  • Mix of 1 and/or 2 OR do both?
@ryanulit ryanulit changed the title feat(policy): PolicyDBClient struct should not expose SQLC query generated functions Policy: PolicyDBClient struct should not expose SQLC query generated functions Oct 15, 2024
@jrschumacher
Copy link
Member

Let's just go with lowercasing the leading character. Seems to be the simplest solution.

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

No branches or pull requests

2 participants