Feat/dynamic select#1
Merged
Merged
Conversation
Introduce Select(fields ...AnyField), the counterpart of jOOQ's DSL.select(SelectFieldOrAsterisk...) for projections whose arity only becomes known at run time, such as a GROUP BY column set derived from a request. The constructor produces dynamic Record rows and composes with the whole existing clause chain, including set operations and every terminal fetch. Each projected field that carries a Go element type is scanned into a value of that type through a new unexported scanTarget hook on the concrete field implementation, so Record values match the values the equivalent typed SelectN projection would produce, independent of the driver's native representations. Passing no fields mirrors the reference's empty-select convenience and renders SELECT *, taking the column names from the result set. Record mirrors the untyped org.jooq.Record: Size, Columns, Values, Get by index, and GetByName, plus the generic accessors Value and ValueAt mirroring Record.get(..., Class) with deliberate conversions only (byte slices relax to string and numeric kinds convert between one another) rather than silent reflect conversions. Covered by golden SQL and fake-driver unit tests plus PostgreSQL and SQLite integration suites, including the run-time GROUP BY arity use case.
Error message prefixes, the fake test driver name, and every comment that refers to this library itself now say gooq instead of the leftover jooq working name. References to the jOOQ Java library that inspired the design, including its org.jooq package paths and website, are intentionally preserved.
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.
feat: add dynamic select with run-time projection and record accessors
Summary
This pull request adds a dynamic
SELECTconstructor for projections whose arity only becomes known at run time, mirroring jOOQ'sDSL.select(SelectFieldOrAsterisk...)and its untypedorg.jooq.Record. It also renames the library's leftover internal working name (jooq) togooqacross error messages and self-referential comments.Motivation
The typed
Select1..Select22constructors require the projection arity at compile time. A query whose column set is assembled from a run-time value — for example aGROUP BYdimension list derived from a request — previously forced consumers into a switch over every possible arity, duplicating the query construction and row mapping once per case.What is included
Select(fields ...AnyField) SelectFromStep[Record]Distinct,Where,GroupBy,Having,OrderBy, limits, locking, set operations, and every terminal fetch.Field[T], including aliased fields and theRaw/RawValueescape hatches) is scanned into a value of that type through a new unexportedscanTargethook on the concrete field implementation, soRecordvalues match what the equivalent typed projection would produce, independent of the driver's native representations.NULLscanned into a non-nullable element type is an error, exactly as in the typed constructors; nullable columns are projected with a pointer orsql.Null*element type.SELECT *, taking the column names from the result set.RecordDynamic row type mirroring
org.jooq.Record:Size(),Columns(),Values(),Get(index), andGetByName(name)(case-insensitive, consistent withFetchIntocolumn matching).Value[T](record, name)andValueAt[T](record, index)mirroringRecord.get(..., Class), with deliberate conversions only:[]byterelaxes tostringand numeric kinds convert between one another. Anything else is an error rather than a silent reflect conversion, which would, for example, turn an integer into the string of its code point.Rename:
jooq→gooqError message prefixes (
gooq: ...), the fake test driver name, and every comment that refers to this library itself now saygooq. References to the jOOQ Java library that inspired the design — itsorg.jooqpackage paths and website — are intentionally preserved.Testing
SELECT *path, nullable projections, conversion errors, and the single-row terminal operations.GROUP BYarity case.