added PostgreSQL Interval value variant#709
Conversation
| 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.
There was previously no dependency on SQLx. However, PgInterval is provided by SQLx. Is this fine?
| 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.
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.
Is this the preferred way of adding this feature dependency?
| args.add(Value::ChronoDateTimeWithTimeZone(t).chrono_as_naive_utc_in_string()); | ||
| } | ||
| #[cfg(feature = "postgres-interval")] | ||
| Value::Interval(_) => {} |
There was a problem hiding this comment.
Is there a better of doing this other than splitting the query builder or throwing an error?
| args.add(t.map(|t| *t)); | ||
| } | ||
| #[cfg(feature = "postgres-interval")] | ||
| Value::Interval(_) => {} |
There was a problem hiding this comment.
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.
Shall I make the units abbreviated or is this better for clarity when inspecting the built SQL statement?
| } | ||
|
|
||
| fn column_type() -> ColumnType { | ||
| ColumnType::Interval(None, None) |
There was a problem hiding this comment.
What do I pass to ColumnType::Interval, if anything?
| #[cfg(feature = "with-chrono")] | ||
| Value::ChronoDateTimeLocal(_) => CommonSqlQueryBuilder.value_to_string(value).into(), | ||
| #[cfg(feature = "postgres-interval")] | ||
| Value::Interval(_) => CommonSqlQueryBuilder.value_to_string(value).into(), |
|
Thank you. I will put this on my pipeline. |
tyt2y3
left a comment
There was a problem hiding this comment.
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.
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.
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.