feat(pg-codegen): generated Prisma-like db client over query-builder - #1733
Merged
Conversation
Emits a shared client.ts runtime (TableClient: findMany/findFirst/findFirstOrThrow/count/create/update/updateOrThrow/delete, camelCase where/select/orderBy in the query-spec filter grammar, decoded rows, $with rebinding) plus a per-schema createXDb factory binding one TableClient per table with runtime schema/table overrides.
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pg-codegen output now includes a high-level database client mirroring the GraphQL ORM's surface, so consumers stop hand-assembling SELECT lists,
columnByFieldlookups, and per-column decoder calls:Two new emitted files:
client.ts— shared runtime, copied from a typechecked template (src/emit/templates/client.ts, same pattern as graphql-codegen templates).TableClient<App>wraps@constructive-io/query-builder:findMany/findFirst/findFirstOrThrow/count/create/update/updateOrThrow/delete, camelCasewherein the shared query-spec grammar (equalTo,in,greaterThan,startsWith,and/or/not; bare value =equalTo,null=isNull),select: { field: true }narrowing the result type viaSelectResult,orderBy: { createdAt: 'DESC' }, rows decoded through the generated field decoders, writes serialized (Dates → ISO, json fields → stringify, arrays passed through to pg). Zero-rowupdateOrThrow/findFirstOrThrowthrowRowNotFoundError— never silent.<schema>/db.ts— AST-emittedcreate<Schema>Db(db, options?)factory binding oneTableClientper table over the existing<TABLE>_TABLE/<TABLE>_FIELDSconstants, with runtimeschema/per-table name overrides for tables provisioned into per-tenant schemas, plus$withfor transactions.Notes:
@constructive-io/query-builderdependency (generated output imports it); templates are copied intodist/at build like graphql-codegen..execute()envelope — pg errors throw, so methods are plain promises.__tests__/client.test.ts) runs the committed fixture client against a provisioned DB: CRUD, projections, filter grammar, and/or/not, count,$with. 48 tests green.Link to Devin session: https://app.devin.ai/sessions/b1fb8d90ec0a4cd1bd95e3c77c6f6680
Requested by: @pyramation