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

Have all DB functions support either a postgres connection, or a postgres pool. #4745

Closed
5 tasks done
dessalines opened this issue May 24, 2024 · 2 comments
Closed
5 tasks done

Comments

@dessalines
Copy link
Member

dessalines commented May 24, 2024

Requirements

  • Is this a feature request? For questions or discussions use https://lemmy.ml/c/lemmy_support
  • Did you check to see if this issue already exists?
  • Is this only a feature request? Do not put multiple feature requests in one issue.
  • Is this a backend issue? Use the lemmy-ui repo for UI / frontend issues.
  • Do you agree to follow the rules in our Code of Conduct?

Is your proposal related to a problem?

When using diesel transactions, you need to use an individual postgres connection, rather than passing in an entire DB pool. This is a problem because some API actions, like comment creation, have many operations, and should be done in a transaction.

Currently, nearly all our functions in db_schema use the pool, rather than individual connections. So for the above example, we'd have to create nearly identical functions just for the PgConn versions.

Describe the solution you'd like.

Create a PoolOrConnection enum, and alter all the functions in db_schema to use it, instead of the pool.

Add a helper function to the enum, that if given a pool, extracts the connection, but if given a connection, just uses it.

Describe alternatives you've considered.

NA

Additional context

#4742

@dessalines
Copy link
Member Author

Looks like this is already done, but that should be renamed:

pub enum DbPool<'a> {

@phiresky
Copy link
Collaborator

this was done in #3420

@Nutomic Nutomic closed this as completed Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants