Skip to content

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

@ryanulit

Description

@ryanulit

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stalecomp:policyPolicy Configuration ( attributes, subject mappings, resource mappings, kas registry)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions