-
-
Notifications
You must be signed in to change notification settings - Fork 194
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
added PostgreSQL Interval value variant #709
base: master
Are you sure you want to change the base?
Conversation
Cargo.toml
Outdated
@@ -44,6 +44,7 @@ time = { version = "0.3", default-features = false, optional = true, features = | |||
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
@@ -60,7 +61,7 @@ derive = ["sea-query-derive"] | |||
attr = ["sea-query-attr"] | |||
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?
@@ -42,6 +42,7 @@ with-time = ["sqlx?/time", "sea-query/with-time", "time"] | |||
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
@@ -73,6 +73,8 @@ impl sqlx::IntoArguments<'_, sqlx::mysql::MySql> for SqlxValues { | |||
Value::ChronoDateTimeWithTimeZone(t) => { | |||
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
@@ -73,6 +73,8 @@ impl<'q> sqlx::IntoArguments<'q, sqlx::sqlite::Sqlite> for SqlxValues { | |||
Value::ChronoDateTimeWithTimeZone(t) => { | |||
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
@@ -1423,6 +1477,8 @@ pub fn sea_value_to_json_value(value: &Value) -> Json { | |||
Value::ChronoDateTimeUtc(_) => CommonSqlQueryBuilder.value_to_string(value).into(), | |||
#[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. |
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
PgInterval
inside 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
?
@@ -105,6 +107,10 @@ impl sqlx::IntoArguments<'_, sqlx::postgres::Postgres> for SqlxValues { | |||
Value::TimeDateTimeWithTimeZone(t) => { | |||
args.add(t.as_deref()); | |||
} | |||
#[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::Interval
enum variant containing aPgInterval
provided 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.