feat(pg-codegen): emit per-column field decoders for projections - #1731
Merged
Conversation
A joined or partial SELECT is not a whole table row, so the record decoders reject it. Each record module now also exports <TABLE>_FIELDS: one decoder per column, sharing the record decoders' definition of the column's runtime check. Also replaces the README, which still described the removed v1 class output.
Contributor
Author
🤖 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
The record decoders only accept a whole table row — every NOT NULL column present, or
CoerceError. Most real queries don't return one: they project a subset, alias columns, and join. Auditing constructive-db's 280 uncheckedrow.x as stringcasts, the single biggest site (157 casts,compute/lib/module-loader/src/loaders.ts) is entirely of that shape:so there was nothing generated it could use. Each record module now also exports
<TABLE>_FIELDS, one decoder per column:A NOT NULL column's decoder is strict and takes an overridable label so a projection names its own alias (
FIELDS.name(row.thread_table_name, 'agent_module.thread_table')); a nullable column's is lenient and has no label, because it cannot fail.decodeExpressionwas generalized to take value+label expressions instead of a key, so the whole-record decoder (record.foo,`${label}.foo`) and the field decoder (value,label) are the same definition of a column's runtime check — a test asserts they agree column-by-column over a whole row.Also replaces the README, which still documented v1's removed
class X implements Xoutput and agenerateCodeTree/pg-codegen/introspectAPI that no longer exists.Link to Devin session: https://app.devin.ai/sessions/b1fb8d90ec0a4cd1bd95e3c77c6f6680
Requested by: @pyramation