Macro generate Table -> Draft convenience initializer. #146
DandyLyons
started this conversation in
Ideas
Replies: 2 comments
-
You actually can interact with Does that help? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Here's the test where I found myself wishing I had an
(For context, I'm also using some test helpers here. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Currently
@Table
generates aDraft
type and an initializer that makes it easy to convert a base Table into a Draft. It would be nice if there were a convenience initializer to convert a Draft into a table type. Specifically it would be nice if the macro generated something like this:Use Case
In production this initializer isn't all that helpful. But for tests this can be quite helpful. For example, when using upsert(or:values:) you must provide a Draft. And when testing you want to assert that the write you performed caused the change you expected. But when you fetch, you can only fetch a Table, not a Draft. So now you need to convert a Draft into a Table so that you can make your assertion.
Workarounds
It's not difficult to make your own
init(id:draft:)
initializer which solves this problem. But this more code to maintain. Macros are perfect for this problem.Beta Was this translation helpful? Give feedback.
All reactions