You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
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?
The text was updated successfully, but these errors were encountered:
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
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: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.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
PolicyDBClient
Possible solutions that need further investigation:
PolicyDBClient
to no longer use composition with theQueries
struct and use global variable for Queries that is only referenced within thedb
packageThe text was updated successfully, but these errors were encountered: