Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add support for money type#601

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

tkbrigham
Copy link

Closes#598

ImplementsToSql andFromSql for thepostgres_money::Money struct, behind the featurewith-money-0_2.

@tkbrighamtkbrighamforce-pushed thetkbrigham/add-support-for-money-type branch from9b69b5a tod24167eCompareMay 7, 2020 04:44
@sfackler
Copy link
Collaborator

For a postgres-specific crate like postgres_money, these impls would just live directly in that crate and not require a feature over here.

@tkbrigham
Copy link
Author

tkbrigham commentedMay 9, 2020
edited
Loading

@sfackler thepostgres_money crate is not dependent on therust-postgres crate (nor theToSql andFromSql traits) in order to be useful. It is just representation of data that should mirror what Postgres does for themoney type. In fact, thepostgres_money crate could potentially be valuable without every communicating with Postgres if you wanted to use it to see how Postgres would parse and represent strings (though this is admittedly farfetched).

The pattern I believe you are suggesting is keep all of the impls in the postgres_money crate, but that seems to lead to the following situation:

  • Another crate (new_postgres_reader) wants to usepostgres_money
  • They open a pull request topostgres_money that implements the traits thatnew_postgres_reader needs to send data to PG
  • postgres_money now has an additional dependency on another crate, which has a dependency onpostgres_money. Admittedly easy to feature flag, but still.

This seems to fly in the face of encapsulation, where this crate now has to have knowledge of its consumers, instead of the consumers taking a dependency on this crate. It seems that unless every crate that interfaces with Postgres data directly has the same APIs and signatures, implementing the SQL representation traits forpostgres_money::Money would make sense to live closer to the Postgres binding crate.

As a concrete example, if we pretend Diesel didn't have theMoney type support in place, they could take a dependency onpostgres_money and implement their bindings betweenpostgres_money::Money and their DB interface. Conversely, if we added the binding in thepostgres_money crate,postgres_money would take a dependency on Diesel and vice versa.

So it seems like the SQL-interface layer is better served as a feature within the crates that access Postgres, not within the generic representation of that data.

@arekbal
Copy link

arekbal commentedMay 9, 2020
edited
Loading

They open a pull request to postgres_money that implements the traits that new_postgres_reader needs to send data to PG

Don't blame me if I am wrong(a noob here) but isn't postgres_money meant to be more like sattelite crate - an extension for main postgres crates instead? Not like let-everybody-in club.

This seems to fly in the face of encapsulation.

@sfackler
Copy link
Collaborator

The pattern I believe you are suggesting is keep all of the impls in the postgres_money crate, but that seems to lead to the following situation:

This does not appear to have been a problem in the last 5 or so years of the development of this crate.

@sfackler
Copy link
Collaborator

You can always have a feature flat on postgres_money to make the dependency on postgres_types optional.

@tkbrigham
Copy link
Author

If I were someone new coming to the rust-postgres crate and I wanted support for both theuuid andmoney column types, I would find it odd that one was natively supported (behind a feature) and I'd have to find my own implementation for the other.

If the goal is to have developers choose their own implementation becauserust-postgres doesn't support it natively, then implementing the ToSql and FromSql elsewhere seems reasonable, just not what I had in mind.

@sfackler
Copy link
Collaborator

I don't understand - you have to use an external implementation of theUuid type just as you would for theMoney type. The features just add the impl for crates where it doesn't make sense for them to support it natively.

@tkbrigham
Copy link
Author

tkbrigham commentedMay 9, 2020
edited
Loading

I think the drivers for my thought process are basically three things, broken down intouser concerns (devs using the rust-postgres crate) andmaintainer concerns (e.g. you for rust-postgres and me for postgres_money):

User Concerns

Discoverability

As a developer, I decide to us PG as a backend. I discover this crate, and pull it in as a dep. I know I have some tables that will depend onmoney, so I look throughrust-postgres to see how I can interface with this type.

Possible outcomes:
  • Ifmoney is a supported feature inrust-postgres, I simply enable it, rebuild and am on my way.
  • Ifmoney is not supported, possiblyrust-postgres suggests/documents thepostgres_money crate, the dev can go out and import this crate themselves with the appropriate features. (From my perspective, why wouldrust-postgres suggest a crate but not implement it behind a feature?)
  • Ifmoney is not supported and not suggested/documented, the developer is left with the task of finding their own implementation/solution

Of note: this was basically the process I went through when I realized there was nomoney support. It would have been amazing if I could have simply enabled a feature and kept coding.

Robust Postgres Support

This crate saysPostgreSQL support for Rust. There is a gap though - the Postgresmoney type. If this crate is supporting Postgres, why should support for this native Postgres feature not live inside this crate? If themoney support is behind a feature flag, it's hard for me to understand what the drawbacks of collocating money support with a postgres crate are.

You mentioned this hasn't been a concern with other crates - can you give me examples of other crates that implement Postgres native types and also implement rust-postgres ToSql and FromSql impls?

Maintainer Concerns

Maintainability

If your concern is to avoid adding more dependencies to the rust-postgres footprint, or concerns with being the one responsible to maintain the ToSql and FromSql implementations for thepostgres_money crate, that seems like a fine reason not to want to include this dependency. If that is the case, I'm happy to commit to handling bugfixes and feature requests for this bit of functionality.

arekbal reacted with thumbs up emoji

@sfackler
Copy link
Collaborator

  • Ifmoney is a supported feature inrust-postgres, I simply enable it, rebuild and am on my way.

No, you enable the feature on the postgres dependency and add the dependency on the postgres_money crate. How is that significantly different from adding a dependency on the postgres_money crate and (maybe) enabling a feature on the postgres_money crate?

@tkbrigham
Copy link
Author

tkbrigham commentedMay 11, 2020
edited
Loading

How is that significantly different from adding a dependency on the postgres_money crate and (maybe) enabling a feature on the postgres_money crate?

Because of discoverability. The developer has already found therust-postgres crate, so enabling a feature within that crate is a matter of reading the docs.

On the other hand, if support formoney is something thatrust-postgres doesn't know about (because it only lives as a feature withinpostgres_money), then the developer must 1) go do research and determine whether or not there aremoney implementations forrust-postgres and 2) spend time evaluating which implementation they want to use.

This is all in addition to the fact thatrust-postgres technically has a feature gap, which is support for Postgres' nativemoney type. It seems like ifrust-postgres is intended as a fully-featured driver for Postgres, support for themoney type would be welcome.

I'm having a hard time understanding your motivations and responses from the feedback you are providing. Perhaps you could share what your goals are for suggesting this live outside of rust-postgres, or what you are optimizing for generally? If you do, I could help address those concerns or understand why my suggested approach is not preferable.

arekbal and BaptisteRoseau reacted with thumbs up emoji

@sfackler
Copy link
Collaborator

The developer has already found therust-postgres crate, so enabling a feature within that crate is a matter of reading the docs.

The docs can point people towards postgres-money.

I'm having a hard time understanding your motivations and responses from the feedback you are providing.

I want to minimize the number of feature flags exposed by the postgres crate. If a library is built specifically for postgres, like postgres-array, or postgres-range, or postgres-money, then that's great since a feature flag won't be necessary for those types.

I want to avoid having types with nontrivial APIs (like ranges or arrays or money) in this crate. That allows those APIs to have more freedom to iterate through e.g. breaking changes. I do not want to cut breaking releases of the core postgres crates very often since each break pushes work downstream to update.

@tkbrigham
Copy link
Author

@sfackler understood. The minimization of feature flags is definitely not what I'd expected, so that is good to know.

I will close this PR. I'd probably lean towards keeping the issue open, but I'll defer to you on that.

@nixpulvis
Copy link

Bothuuid (for example) andmoney are built in types to Postgres, as a user I would fully expect to enable support for them in the same way with this crate (assuming they aren't enabled by default). If there's an issue of too many feature flags, perhaps that could be helped by making groups of feature flags? What is the problem with having a lot of feature flags?

lgrosz added a commit to lgrosz/climb-graphql that referenced this pull requestMar 24, 2025
This _does not_ add the date window support, yet. This is because thereis not a great native rust-postgres way of getting PostgreSQLs DATERANGEtype. Looks like there'srust-postgres/rust-postgres-range#18, but it hasn'tbeen merged in a year and the general state of rust-postgres-range seemsunmaintained.. perhaps@tkbrigham has a good point inrust-postgres/rust-postgres#601.. it'd be great if all the PostgreSQLfeatures were supported in rust-postgres directly.
lgrosz added a commit to lgrosz/climb-graphql that referenced this pull requestMar 24, 2025
This _does not_ add the date window support, yet. This is because thereis not a great native rust-postgres way of getting PostgreSQLs DATERANGEtype. Looks like there'srust-postgres/rust-postgres-range#18, but it hasn'tbeen merged in a year and the general state of rust-postgres-range seemsunmaintained.. perhaps@tkbrigham has a good point inrust-postgres/rust-postgres#601.. it'd be great if all the PostgreSQLfeatures were supported in rust-postgres directly.
lgrosz added a commit to lgrosz/climb-graphql that referenced this pull requestMar 25, 2025
This _does not_ add the date window support, yet. This is because thereis not a great native rust-postgres way of getting PostgreSQLs DATERANGEtype. Looks like there'srust-postgres/rust-postgres-range#18, but it hasn'tbeen merged in a year and the general state of rust-postgres-range seemsunmaintained.. perhaps@tkbrigham has a good point inrust-postgres/rust-postgres#601.. it'd be great if all the PostgreSQLfeatures were supported in rust-postgres directly.
lgrosz added a commit to lgrosz/climb-graphql that referenced this pull requestMar 28, 2025
This _does not_ add the date window support, yet. This is because thereis not a great native rust-postgres way of getting PostgreSQLs DATERANGEtype. Looks like there'srust-postgres/rust-postgres-range#18, but it hasn'tbeen merged in a year and the general state of rust-postgres-range seemsunmaintained.. perhaps@tkbrigham has a good point inrust-postgres/rust-postgres#601.. it'd be great if all the PostgreSQLfeatures were supported in rust-postgres directly.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

postgres-types: Converting Postgres Money type to Rust type

4 participants

@tkbrigham@sfackler@arekbal@nixpulvis

[8]ページ先頭

©2009-2025 Movatter.jp