-
Notifications
You must be signed in to change notification settings - Fork 40
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
Merged
Merged
Changes from 20 commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
f2a3a59
Incorporate `@Selection` logic into `@Table`
stephencelis 4b95802
wip
stephencelis 1be6e0b
Support tuple operations with `Table` records
stephencelis 3e15094
Support nested tables
stephencelis 376ee57
fixes
stephencelis 1d4e907
wip
stephencelis b34df28
wip
stephencelis 922e5b3
wip
stephencelis fa8b00d
wip
stephencelis 0723ede
wip
stephencelis 1974bb0
wip
stephencelis 3905f40
wip
stephencelis 7800ea8
wip
stephencelis 21e0c9a
wip
stephencelis c4c2d03
wip
stephencelis 7d434e2
wip
stephencelis c7cac92
wip
stephencelis 4958464
wip
stephencelis e07a4eb
wip
stephencelis 9623521
Basic docs pass
stephencelis 642fd4e
wip
stephencelis a69e5fb
Fixes
stephencelis a0a0fca
wip
stephencelis 3d5d296
fixes
stephencelis ccb5151
wip
stephencelis f2e4981
wip
stephencelis f6394a3
db function support
stephencelis 29fcd86
wip
stephencelis ac6f814
wip
stephencelis 1018903
wip
stephencelis 65f0294
wip
stephencelis df4b1a7
Merge remote-tracking branch 'origin/main' into table-expression
stephencelis 4f44594
wip
stephencelis c424493
wip
stephencelis 5345f66
wip
stephencelis 9789c32
wip
stephencelis cdc589b
wip
stephencelis 661cb7d
wip
stephencelis 137b82f
wip
stephencelis f18feec
wip
stephencelis 0324749
wip
stephencelis c477c11
wip
stephencelis 7ee5a6b
wip
stephencelis 4dc29da
Infer multi-column when possible
stephencelis cb6e29d
wip
stephencelis 324ab9c
wip
stephencelis 20148be
wip
stephencelis 0465e23
wip
stephencelis 93e4379
wip
stephencelis 366138a
wip
stephencelis 9bbc844
wip
stephencelis 70ce95f
wip
stephencelis cdb99e1
wip
stephencelis c820b2b
wip
stephencelis cc1c9cd
Docs and tests
mbrandonw 5ded480
wip
stephencelis 6d06754
wip
stephencelis a5b1723
wip
stephencelis 78d5081
wip
stephencelis d209480
wip
stephencelis 3a795ea
Merge remote-tracking branch 'origin/main' into table-expression
stephencelis b82b66d
wip
mbrandonw 0bc5a80
wip
stephencelis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/// A group of table columns. | ||
/// | ||
/// 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 | ||
where Values.QueryOutput == Values { | ||
public typealias Value = Values | ||
|
||
public var _names: [String] { Values.TableColumns.allColumns.map(\.name) } | ||
|
||
public typealias QueryValue = Values | ||
|
||
public static func allColumns(keyPath: KeyPath<Root, Values>) -> [any TableColumnExpression] { | ||
return Values.TableColumns.allColumns.map { column in | ||
func open<R, V>( | ||
_ column: some TableColumnExpression<R, V> | ||
) -> any TableColumnExpression { | ||
let keyPath = keyPath.appending( | ||
path: unsafeDowncast(column.keyPath, to: KeyPath<Values, V.QueryOutput>.self) | ||
) | ||
return TableColumn<Root, V>( | ||
column.name, | ||
keyPath: keyPath, | ||
default: column.defaultValue | ||
) | ||
} | ||
return open(column) | ||
} | ||
} | ||
|
||
public static func writableColumns( | ||
keyPath: KeyPath<Root, Values> | ||
) -> [any WritableTableColumnExpression] { | ||
return Values.TableColumns.writableColumns.map { column in | ||
func open<R, V>( | ||
_ column: some WritableTableColumnExpression<R, V> | ||
) -> any WritableTableColumnExpression { | ||
let keyPath = keyPath.appending( | ||
path: unsafeDowncast(column.keyPath, to: KeyPath<Values, V.QueryOutput>.self) | ||
) | ||
return TableColumn<Root, V>( | ||
column.name, | ||
keyPath: keyPath, | ||
default: column.defaultValue | ||
) | ||
} | ||
return open(column) | ||
} | ||
} | ||
|
||
public let keyPath: KeyPath<Root, Values> | ||
|
||
public init(keyPath: KeyPath<Root, Values>) { | ||
self.keyPath = keyPath | ||
} | ||
|
||
public var queryFragment: QueryFragment { | ||
ColumnGroup.allColumns(keyPath: keyPath).map(\.queryFragment).joined(separator: ", ") | ||
} | ||
|
||
public subscript<Member>( | ||
dynamicMember keyPath: KeyPath<Values.TableColumns, TableColumn<Values, Member>> | ||
) -> TableColumn<Root, Member> { | ||
let column = Values.columns[keyPath: keyPath] | ||
return TableColumn<Root, Member>( | ||
column.name, | ||
keyPath: self.keyPath.appending(path: column.keyPath), | ||
default: column.defaultValue | ||
) | ||
} | ||
|
||
public subscript<Member>( | ||
dynamicMember keyPath: KeyPath<Values.TableColumns, GeneratedColumn<Values, Member>> | ||
) -> GeneratedColumn<Root, Member> { | ||
let column = Values.columns[keyPath: keyPath] | ||
return GeneratedColumn<Root, Member>( | ||
column.name, | ||
keyPath: self.keyPath.appending(path: column.keyPath), | ||
default: column.defaultValue | ||
) | ||
} | ||
|
||
public subscript<Member>( | ||
dynamicMember keyPath: KeyPath<Values.TableColumns, ColumnGroup<Values, Member>> | ||
) -> ColumnGroup<Root, Member> { | ||
let column = Values.columns[keyPath: keyPath] | ||
return ColumnGroup<Root, Member>( | ||
keyPath: self.keyPath.appending(path: column.keyPath) | ||
) | ||
} | ||
} |
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
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
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
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
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
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
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
Oops, something went wrong.
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.
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?