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

Postgrest can be Clone #53

Closed
jnhyatt opened this issue Jul 20, 2023 · 2 comments · Fixed by #54
Closed

Postgrest can be Clone #53

jnhyatt opened this issue Jul 20, 2023 · 2 comments · Fixed by #54
Labels
enhancement New feature or request

Comments

@jnhyatt
Copy link
Contributor

jnhyatt commented Jul 20, 2023

Feature request

Hi!

Is your feature request related to a problem? Please describe.

I would like to be able to pass my Postgrest around my program to be able to make requests from multiple places, notably from async tasks I spawn periodically. My approach would be:

let client = postgrest.clone();
let task = task_pool.spawn(async move {
    let result = build_query(client).execute().await;
    handle_result(result).await
});

Describe alternatives you've considered

Leave as is and require the user to either:

  • Create a new Postgrest at each call site. The downside to this would be that all information needed to build the client must be available as well. This breaks encapsulation as it requires users to "ship" state (access tokens, etc.) around instead of the Postgrest object, which could just do this for you.
  • Use Rc or similar to share the Postgrest object throughout the program. This feels redundant as Client already stores an Arc to all the persistent, non-Clone state.

Additional context

Two facts jump out at me when looking at the implementation:

  • Client is Clone (as are all other fields)
  • Constructing a Postgrest is a simple matter -- very little state is stored in the structure
    Both of these hint to me that cloning should probably be a feature of the public API: if Postgrest only represents the state necessary to make a request, that state should probably be cloneable as it behaves similarly to POD.

Let me know what you think!

@jnhyatt jnhyatt added the enhancement New feature or request label Jul 20, 2023
@soedirgo
Copy link
Collaborator

Thanks @jnhyatt! Builder is already Clone, I think it's reasonable to make Postgrest Clone too.

@jnhyatt
Copy link
Contributor Author

jnhyatt commented Jul 21, 2023

Awesome, I'll send up a PR. Thanks!

@soedirgo soedirgo linked a pull request Jul 25, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants