-
-
Notifications
You must be signed in to change notification settings - Fork 228
added PostgreSQL Interval value variant #709
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
base: master
Are you sure you want to change the base?
Conversation
Cargo.toml
Outdated
| ipnetwork = { version = "0.20", default-features = false, optional = true } | ||
| mac_address = { version = "1.1", default-features = false, optional = true } | ||
| ordered-float = { version = "3.4", default-features = false, optional = true } | ||
| sqlx = { git = "https://github.com/yasamoka/sqlx", branch = "pg-interval-hash", default-features = false, optional = true } |
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.
There was previously no dependency on SQLx. However, PgInterval is provided by SQLx. Is this fine?
Cargo.toml
Outdated
| hashable-value = ["derivative", "ordered-float"] | ||
| postgres-array = [] | ||
| postgres-interval = ["proc-macro2", "quote"] | ||
| postgres-interval = ["proc-macro2", "quote", "sqlx/postgres"] |
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.
Is this the preferred way of adding this feature dependency?
| with-ipnetwork = ["sqlx?/ipnetwork", "sea-query/with-ipnetwork", "ipnetwork"] | ||
| with-mac_address = ["sqlx?/mac_address", "sea-query/with-mac_address", "mac_address"] | ||
| postgres-array = ["sea-query/postgres-array"] | ||
| postgres-interval = ["sqlx-postgres", "sqlx/chrono"] |
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.
Is this the preferred way of adding this feature dependency?
sea-query-binder/src/sqlx_mysql.rs
Outdated
| args.add(Value::ChronoDateTimeWithTimeZone(t).chrono_as_naive_utc_in_string()); | ||
| } | ||
| #[cfg(feature = "postgres-interval")] | ||
| Value::Interval(_) => {} |
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.
Is there a better of doing this other than splitting the query builder or throwing an error?
sea-query-binder/src/sqlx_sqlite.rs
Outdated
| args.add(t.map(|t| *t)); | ||
| } | ||
| #[cfg(feature = "postgres-interval")] | ||
| Value::Interval(_) => {} |
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.
Is there a better of doing this other than splitting the query builder or throwing an error?
| } | ||
|
|
||
| write!(s, "'::interval").unwrap(); | ||
| } |
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.
Shall I make the units abbreviated or is this better for clarity when inspecting the built SQL statement?
src/value.rs
Outdated
| } | ||
|
|
||
| fn column_type() -> ColumnType { | ||
| ColumnType::Interval(None, None) |
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.
What do I pass to ColumnType::Interval, if anything?
src/value.rs
Outdated
| #[cfg(feature = "with-chrono")] | ||
| Value::ChronoDateTimeLocal(_) => CommonSqlQueryBuilder.value_to_string(value).into(), | ||
| #[cfg(feature = "postgres-interval")] | ||
| Value::Interval(_) => CommonSqlQueryBuilder.value_to_string(value).into(), |
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.
Is this correct?
|
Thank you. I will put this on my pipeline. |
tyt2y3
left a comment
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.
Hi, thank you for your contribution. However, I don't think we should pull in sqlx as a dependency in the root crate.
What we can do is:
- define our own
PgIntervalinside SeaQuery - add a variant to
Value(which is now done) - support it in
sea-query-binder
that way, in the future we can also support other driver libraries
|
Also, we already have the https://docs.rs/sea-query/latest/sea_query/table/enum.PgInterval.html column type. |
Done :) I named it |
7027767 to
c9c53dc
Compare
| for (interval, formatted) in VALUES { | ||
| let query = Query::select().expr(interval).to_owned(); | ||
| assert_eq!( | ||
| query.to_string(PostgresQueryBuilder), |
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.
What shall we do about MysqlQueryBuolder and SqliteQueryBuilder?
| } | ||
| #[cfg(feature = "postgres-interval")] | ||
| Value::Interval(t) => { | ||
| args.add(t.as_deref()); |
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.
How would I implement sqlx::Encode<'_, Postgres> for PgIntervalValue without adding sqlx as a dependency for sea-query?
First of all, thank you for this feature-filled query builder.
This PR adds the
Value::Intervalenum variant containing aPgIntervalprovided by SQLx. It requires this change in SQLx and is required for these changes in SeaORM.If this PR is considered relevant to the project, then I need some help with how to improve it in some aspects. I will mention the various points in further review requests.