Skip to content
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

go sdk support db (mysql/pg) #1750

Closed
Patrick0308 opened this issue Sep 8, 2023 · 7 comments
Closed

go sdk support db (mysql/pg) #1750

Patrick0308 opened this issue Sep 8, 2023 · 7 comments
Milestone

Comments

@Patrick0308
Copy link
Contributor

Patrick0308 commented Sep 8, 2023

Rust sdk already support mysql/pg. But go sdk haven't support db yet.

@melissaklein24 melissaklein24 added this to the sdk/go/v2 milestone Sep 12, 2023
@vdice vdice moved this to 🆕 Triage Needed in Spin Triage Sep 13, 2023
@Patrick0308
Copy link
Contributor Author

I'm interest in it.

@itowlson
Copy link
Contributor

@adamreese Would the pattern you established with the SQLite SDK fit with our BYO relational API? If so, would it be reasonably quick to implement?

@adamreese
Copy link
Member

They're a bit different. With SQLite a connection to the database is opened and then closed. MySQL and Postgres don't persist a connection between queries. The API would need to be implemented in a different way. We might be able to fake a "connection" and still use Go's database/sql interface.

@Patrick0308
Copy link
Contributor Author

Patrick0308 commented Sep 14, 2023

Would the pattern you established with the SQLite SDK fit with our BYO relational API?

Does "our BYO relational API" means wit API in wit directory in project? I see rust sdk using outbound-pg.wit and outbound-mysql.wit which located in wit/ephemeral dir. Can‘t go sdk follow the same way as rust sdk?

@vdice vdice moved this from 🆕 Triage Needed to 📋 Investigating / Open for Comment in Spin Triage Sep 14, 2023
@itowlson
Copy link
Contributor

"BYO relational" is an informal term for "bring your own" databases, specifically Postgres and MySQL, as opposed to the "built in" SQLite database - sorry for the confusing term!

You are correct that the WIT files define the API. And certainly Go could surface the WIT bindings directly, but they are not very friendly, because they use concepts like discriminated unions that Go doesn't have. In fact, even the Rust SDK provides a bit of a wrapper over the raw WIT to make it more ergonomic. Go is an even trickier case because it has a standard database API and the most ergonomic solution would be to adopt that. @adamreese successfully did that for SQLite but his solution won't work for Postgres or MySQL.

If you're happy to work with the WIT bindings directly, you can try running the wit-bindgen tool, and use the generated code from that directly - it doesn't need to be packaged in the SDK. Right now, though, I think we have to have wit-bindgen generate C and then use cgo (this is part of why we have been holding off) - if this is of interest then we can provide more detailed information and guidance. There is work in progress to have wit-bindgen generate Go directly, at which point generating your own client should become a lot more practical. #1630 is where that work is happening.

(I'm still not sure if we will provide official wrappers after #1630, because an idiomatic SDK is non-trivial for the reasons @adamreese describes, and if we shipped a non-idiomatic one we'd be committing to sticking with it for a potentially long period.)

I hope that clarifies the problems and opportunities - do let us know if you're interested in working something up from the WIT files!

@Patrick0308
Copy link
Contributor Author

Thanks for your reply! I think I get it. Adopting go's standard database API is cool!! May be I can implement it.

We might be able to fake a "connection" and still use Go's database/sql interface.

This way sounds good.

@adamreese
Copy link
Member

Implemented in #1794 and #1922

@github-project-automation github-project-automation bot moved this from 📋 Investigating / Open for Comment to ✅ Done in Spin Triage Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

4 participants