How to model a @FetchOne query that should return a @Table object? #61
Replies: 5 comments 1 reply
-
Hi @thinkpractice, we think this would be a good thing to have. Ideally Failing that we could consider |
Beta Was this translation helpful? Give feedback.
-
@mbrandonw a @FetchOne with a default parameter would be a great idea, but in some cases I guess you also would like an optional. In my case, for example, I'm checking whether the user already has entered a weight in the database. If so, the user can adjust the previous weight. If not, the user will have to enter a completely new value. In this case you would want an optional weight being nil right? Of course, it should be made possible by |
Beta Was this translation helpful? Give feedback.
-
As an update to folks seeing this thread. It should now be possible to use |
Beta Was this translation helpful? Give feedback.
-
@stephencelis @mbrandonw thanks so much for this! I could now simplify my code to the following (as above): @ObservationIgnored
@FetchOne(Weight.order { $0.timestamp.desc() }.limit(1))
var weightLastEntered: Weight? Works like a charm! |
Beta Was this translation helpful? Give feedback.
-
Of course! That’s what you get when copy+pasting some code in a hurry 😉 thanks!
Op do 19 jun , Stephen Celis ***@***.***(mailto:Op do 19 jun , Stephen Celis <<a href=)> schreef:
… Just a note, but @FetchOne should automatically apply limit(1), so you should be able to simplify.
—
Reply to this email directly, [view it on GitHub](https://github.com/pointfreeco/sharing-grdb/discussions/61#discussioncomment-13522370), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AEOEDUQ7RTDJ6LBNDWT3G533ELTSPAVCNFSM6AAAAAB5WLXAXGVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGNJSGIZTOMA).
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there,
I'm migrating my SwiftData code for my weight tracking app ScaleDiary to SharingGRDB. In the app, I'm retrieving the last weight entered by the user so the user can adjust the weight by clicking a plus or minus button. Often, weights only change in small amounts so this add some usability to the app. Of course, this weight should be optional as it may also be the first weight the user is entering. I was trying to retrieve the last weight entered by using the following code:
This however results in the following error
Cannot convert value of type 'Select<(), Weight, ()>' to expected argument type '[Weight]'
which leads me to believe optional values are not supported. Would this be something that should be possible in the future? Or are there any reasons this should or could not work?For now, I've used a work-around but it would be nice if something similar as above would be present in future :)
kind regards,
Tim
Beta Was this translation helpful? Give feedback.
All reactions