-
Notifications
You must be signed in to change notification settings - Fork 44
Better @Table/@Selection composition: nested column groupings, enums, and more
#184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The `@Selection` and `@Table` type overlap in many ways, but there is
no reason why `@Selection`'s `Columns` type should ever be omitted from
`@Table`, and so this PR introduces the machinery for just that.
Draft for now because there's much to discuss:
- Should we deprecate `@Selection` entirely, and push people to use
`@Table` for everything? It might be a little weird, but we've
already blurred the line with CTEs and database views that maybe we
should consider `@Table` to mean groups of columns that can be
assembled in Swift. It's also less library code to
maintain/document, though it is _more_ code generation (arguably not
a ton, but who knows the impact on the compiler/binary).
- Or should we keep `@Selection` around as a lightweight subset of
`@Table`?
- If so, should we somehow compose our macro code better, so that
`@Table` calls down to `@Selection`?
- Or should it still live in a parallel world, but be updated to
use some formal machinery, like the `TableExpression` protocol
introduced in this PR.
8cb48c5 to
4b95802
Compare
@Selection logic into @Table@Table selections via a new @Columns macro
| /// A type that describes this table as a query expression. | ||
| associatedtype Selection: TableExpression<Self> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bikeshed opportunity: this is aliased to Columns, but named Selection here to distinguish itself better from TableColumns. Do we want to consider alternate naming, though to avoid overloading things with aliases?
| /// Don't create instances of this value directly. Instead, use the `@Table` and `@Columns` macros | ||
| /// to generate values of this type. | ||
| @dynamicMemberLookup | ||
| public struct ColumnGroup<Root: Table, Values: Table>: _TableColumnExpression |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bikeshed opportunity: Should we call this TableColumnGroup for consistent prefixing?
@Table selections via a new @Columns macro@Table selections
@Table selections@Tables, selections, and more
@Tables, selections, and more@Table/@Selection composition: nested column groupings, enums, and more
…ums, and more (pointfreeco#184) * Incorporate `@Selection` logic into `@Table` The `@Selection` and `@Table` type overlap in many ways, but there is no reason why `@Selection`'s `Columns` type should ever be omitted from `@Table`, and so this PR introduces the machinery for just that. Draft for now because there's much to discuss: - Should we deprecate `@Selection` entirely, and push people to use `@Table` for everything? It might be a little weird, but we've already blurred the line with CTEs and database views that maybe we should consider `@Table` to mean groups of columns that can be assembled in Swift. It's also less library code to maintain/document, though it is _more_ code generation (arguably not a ton, but who knows the impact on the compiler/binary). - Or should we keep `@Selection` around as a lightweight subset of `@Table`? - If so, should we somehow compose our macro code better, so that `@Table` calls down to `@Selection`? - Or should it still live in a parallel world, but be updated to use some formal machinery, like the `TableExpression` protocol introduced in this PR. * wip * Support tuple operations with `Table` records * Support nested tables * fixes * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Basic docs pass * wip * Fixes * wip * fixes * wip * wip * db function support * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Infer multi-column when possible * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Docs and tests * wip * wip * wip * wip * wip * wip * wip --------- Co-authored-by: Brandon Williams <[email protected]>
…ums, and more (pointfreeco#184) * Incorporate `@Selection` logic into `@Table` The `@Selection` and `@Table` type overlap in many ways, but there is no reason why `@Selection`'s `Columns` type should ever be omitted from `@Table`, and so this PR introduces the machinery for just that. Draft for now because there's much to discuss: - Should we deprecate `@Selection` entirely, and push people to use `@Table` for everything? It might be a little weird, but we've already blurred the line with CTEs and database views that maybe we should consider `@Table` to mean groups of columns that can be assembled in Swift. It's also less library code to maintain/document, though it is _more_ code generation (arguably not a ton, but who knows the impact on the compiler/binary). - Or should we keep `@Selection` around as a lightweight subset of `@Table`? - If so, should we somehow compose our macro code better, so that `@Table` calls down to `@Selection`? - Or should it still live in a parallel world, but be updated to use some formal machinery, like the `TableExpression` protocol introduced in this PR. * wip * Support tuple operations with `Table` records * Support nested tables * fixes * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Basic docs pass * wip * Fixes * wip * fixes * wip * wip * db function support * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Infer multi-column when possible * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Docs and tests * wip * wip * wip * wip * wip * wip * wip --------- Co-authored-by: Brandon Williams <[email protected]>
…ums, and more (pointfreeco#184) * Incorporate `@Selection` logic into `@Table` The `@Selection` and `@Table` type overlap in many ways, but there is no reason why `@Selection`'s `Columns` type should ever be omitted from `@Table`, and so this PR introduces the machinery for just that. Draft for now because there's much to discuss: - Should we deprecate `@Selection` entirely, and push people to use `@Table` for everything? It might be a little weird, but we've already blurred the line with CTEs and database views that maybe we should consider `@Table` to mean groups of columns that can be assembled in Swift. It's also less library code to maintain/document, though it is _more_ code generation (arguably not a ton, but who knows the impact on the compiler/binary). - Or should we keep `@Selection` around as a lightweight subset of `@Table`? - If so, should we somehow compose our macro code better, so that `@Table` calls down to `@Selection`? - Or should it still live in a parallel world, but be updated to use some formal machinery, like the `TableExpression` protocol introduced in this PR. * wip * Support tuple operations with `Table` records * Support nested tables * fixes * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Basic docs pass * wip * Fixes * wip * fixes * wip * wip * db function support * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Infer multi-column when possible * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Docs and tests * wip * wip * wip * wip * wip * wip * wip --------- Co-authored-by: Brandon Williams <[email protected]>
The
@Selectionand@Tablemacros currently overlap in many ways, but there lacks a cohesive story.@Selectiongenerates a nestedColumnstype that can used in a query to select from expressions, while@Tabledoes not, even though it would be just as beneficial to do so.And then we have
@Table @Selectionfor combining this logic together for common table expressions, which can be queried like tables. But we should probably just bake everything into a single macro.This PR explores a rethinking of
@Tableand@Selectionto allow them to better compose together. Both macros now output most of the same functionality. There is just a small semantic difference.@Tableshould be used for globally queryable table-like things. This includes:@Selectionshould be used for groups of columns. This includes:With their functionality now almost entirely overlapping, we can compose them together. You can now group a bunch of a table's columns using
@Selection:(You can nest these selections arbitrarily deep.)
You can specify composite primary keys:
You can even define database functions that take full tables/selections as arguments:
Finally, we are introducing a new
StructuredQueriesCasePathstrait, which allows for enum-based tables and selections, which can be used in all the ways above.