-
Notifications
You must be signed in to change notification settings - Fork 251
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
feat(spin_sdk::pg): Extract type conversions into sdk #813
Conversation
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.
I'm happy for this to go into the SDK, but I suggest we have to make it more comprehensive first. A sample can get away with just doing the things needed for the sample (and to show the pattern), but a blessed library needs to be systematic. We'd also need to manage things like SQL NULL handling, which the sample dodged by making all of the columns NOT NULL. grin
We do have fuller conversion coverage in the .NET SDK (https://github.com/spin/spin-dotnet-sdk) -- if we have parity with that then that would be fine I reckon. Thoughts?
d259f5a
to
711d019
Compare
@itowlson I've added decoding support for the following
Initially, I wanted to review/test types mapping inside the
Also, I want to share some other thoughts which are out of the scope of this PR but are related to:
|
Thanks for the great feedback. I agree we need a better story for DB-specific types and generally on how to represent DB-specific operations and options. There's a reason every database gets its own library and we can't afford to smooth that over too much. One option longer term is to not even have database WIT specs, and provide infrastructure whereby source languages can use their own database crates / packages / modules / etc. But that's hard to do at the moment because most of them sit over raw sockets, and that sockets code doesn't yet compile to Wasm. The current situation is a sighting shot at what we can do in the meantime, and there's certainly a good case for moving the data types out of a common WIT and into database-specific ones. But at the WIT level we'd probably still end up with a big honkin' Regarding how we evolve WIT files - this (and contract versioning more generally) is a big concern of mine, and folks within Fermyon are actively debating when to stabilise various contracts and how to version them thereafter. We have muddled along so far by batching up breaking changes to limit the number of times we have to perform breaks, but we do need a more robust and systemic solution. Unfortunately, we don't yet know what that looks like, and it likely needs to align to broader Wasm Component Model standards which are still in flux. Sorry I can't give you a more satisfying answer for now, but it's very much on our radar. Thanks again for the detailed thoughts. This is a very early-stage area and it's so helpful to have wider conversations about it! |
Yeah, I was looking into more resource-oriented approach but wit-bindgen is currently experiencing a big rewrite, so resource/handle support is dropped for now. P.S. async support is also temporary dropped |
87fea2b
to
e9363c8
Compare
I've added basic integration test to test outbound-pg. It's currently excluded from the default integration test because it expects running postgresql server. |
ab46fc2
to
e4d6973
Compare
a1d6939
to
ef568cd
Compare
UPD
Is there something else to cover?
|
96285fb
to
5aee67c
Compare
70e833a
to
ae806c0
Compare
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.
Wow, this looks tremendous. Thank you so much for slogging through all the types, and for putting in the hard yards to produce an properly self-contained integration test.
I feel a bit guilty for raising a nit about doc strings now... everything else looks great!
sdk/rust/src/pg.rs
Outdated
} | ||
} | ||
|
||
// A pg error |
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.
Not sure if I'm misreading this but I think pub
stuff should have doc strings? The module deny(missing-docs)
should be catching this though so perhaps I'm misunderstanding...
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.
SDK allows missing_docs
https://github.com/fermyon/spin/blob/main/sdk/rust/src/lib.rs#L41-L60 because, otherwise it fails with:
error: missing documentation for an enum
--> sdk/rust/src/lib.rs:54:5
|
54 | wit_bindgen_rust::import!("../../wit/ephemeral/spin-config.wit");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `wit_bindgen_rust::import` (in Nightly builds, run with -Z macro-backtrace for more info)
error: could not document `spin-sdk`
But you're right, this isn't an excuse for not adding the docs :)
Fixed, thanks!
Signed-off-by: Konstantin Shabanov <mail@etehtsea.me>
This has to be the starting point on the way to providing the API that is able to automatically map a DB response into the user-defined struct. Signed-off-by: Konstantin Shabanov <mail@etehtsea.me>
Signed-off-by: Konstantin Shabanov <mail@etehtsea.me>
- Add conversion support for: int16, int32, int64, floating32, floating64, binary, boolean; - Add support for nullable variants; - Introduce spin_sdk::pg::Error; Signed-off-by: Konstantin Shabanov <mail@etehtsea.me>
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.
LGTM - thanks!
This has to be the starting point on the way to providing the API that is able to automatically map a DB response into the user-defined struct.
Signed-off-by: Konstantin Shabanov mail@etehtsea.me