Skip to content

issues-336 Init array support #390

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

Closed
4 changes: 2 additions & 2 deletions examples/postgres/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use chrono::{DateTime, FixedOffset, NaiveDate, NaiveDateTime};
use postgres::{Client, NoTls, Row};
use rust_decimal::Decimal;
use sea_query::{ColumnDef, Iden, Order, PostgresQueryBuilder, Query, Table};
use sea_query::{ColumnDef, ColumnType, Iden, Order, PostgresQueryBuilder, Query, Table};
use sea_query_postgres::PostgresBinder;
use time::{
macros::{date, offset, time},
Expand Down Expand Up @@ -34,7 +34,7 @@ fn main() {
.col(ColumnDef::new(Document::Timestamp).timestamp())
.col(ColumnDef::new(Document::TimestampWithTimeZone).timestamp_with_time_zone())
.col(ColumnDef::new(Document::Decimal).decimal())
.col(ColumnDef::new(Document::Array).array("integer".into()))
.col(ColumnDef::new(Document::Array).array(ColumnType::Integer(None)))
.build(PostgresQueryBuilder),
]
.join("; ");
Expand Down
56 changes: 52 additions & 4 deletions sea-query-binder/src/sqlx_any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,74 +49,122 @@ impl<'q> sqlx::IntoArguments<'q, sqlx::any::Any> for SqlxValues {
Value::Bytes(b) => {
args.add(b.map(|b| *b));
}
#[cfg(feature = "postgres-array")]
Value::BoolArray(_)
| Value::TinyIntArray(_)
| Value::SmallIntArray(_)
| Value::IntArray(_)
| Value::BigIntArray(_)
| Value::SmallUnsignedArray(_)
| Value::UnsignedArray(_)
| Value::BigUnsignedArray(_)
| Value::FloatArray(_)
| Value::DoubleArray(_)
| Value::StringArray(_)
| Value::CharArray(_) => panic!("Array support not implemented for Any"),

#[cfg(feature = "with-chrono")]
Value::ChronoDate(d) => {
args.add(d.map(|d| *d));
}
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::ChronoDateArray(_) => panic!("Array support not implemented for Any"),
#[cfg(feature = "with-chrono")]
Value::ChronoTime(t) => {
args.add(t.map(|t| *t));
}
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::ChronoTimeArray(_) => panic!("Array support not implemented for Any"),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTime(t) => {
args.add(t.map(|t| *t));
}
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::ChronoDateTimeArray(_) => panic!("Array support not implemented for Any"),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeUtc(t) => {
args.add(t.map(|t| *t));
}
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::ChronoDateTimeUtcArray(_) => panic!("Array support not implemented for Any"),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeLocal(t) => {
args.add(t.map(|t| *t));
}
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::ChronoDateTimeLocalArray(_) => {
panic!("Array support not implemented for Any")
}
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeWithTimeZone(t) => {
args.add(Value::ChronoDateTimeWithTimeZone(t).chrono_as_naive_utc_in_string());
}
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::ChronoDateTimeWithTimeZoneArray(_) => {
panic!("Array support not implemented for Any")
}
#[cfg(feature = "with-time")]
Value::TimeDate(t) => {
args.add(Value::TimeDate(t).time_as_naive_utc_in_string());
}
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::TimeDateArray(_) => panic!("Array support not implemented for Any"),
#[cfg(feature = "with-time")]
Value::TimeTime(t) => {
args.add(Value::TimeTime(t).time_as_naive_utc_in_string());
}
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::TimeTimeArray(_) => panic!("Array support not implemented for Any"),
#[cfg(feature = "with-time")]
Value::TimeDateTime(t) => {
args.add(Value::TimeDateTime(t).time_as_naive_utc_in_string());
}
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::TimeDateTimeArray(_) => panic!("Array support not implemented for Any"),
#[cfg(feature = "with-time")]
Value::TimeDateTimeWithTimeZone(t) => {
args.add(Value::TimeDateTimeWithTimeZone(t).time_as_naive_utc_in_string());
}
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::TimeDateTimeWithTimeZoneArray(_) => {
panic!("Array support not implemented for Any")
}
#[cfg(feature = "with-uuid")]
Value::Uuid(_) => {
panic!("UUID support not implemented for Any");
}
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::UuidArray(_) => panic!("Array support not implemented for Any"),
#[cfg(feature = "with-rust_decimal")]
Value::Decimal(_) => {
panic!("Sqlite doesn't support decimal arguments");
}
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::DecimalArray(_) => panic!("Array support not implemented for Any"),
#[cfg(feature = "with-bigdecimal")]
Value::BigDecimal(_) => {
panic!("Sqlite doesn't support bigdecimal arguments");
}
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::BigDecimalArray(_) => panic!("Array support not implemented for Any"),
#[cfg(feature = "with-json")]
Value::Json(_) => {
panic!("Json support not implemented for Any");
}
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::JsonArray(_) => panic!("Array support not implemented for Any"),
#[cfg(feature = "with-ipnetwork")]
Value::IpNetwork(_) => {
panic!("SeaQuery doesn't support IpNetwork arguments for Any");
}
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::IpNetworkArray(_) => panic!("Array support not implemented for Any"),
#[cfg(feature = "with-mac_address")]
Value::MacAddress(_) => {
panic!("SeaQuery doesn't support MacAddress arguments for Any");
}
#[cfg(feature = "postgres-array")]
Value::Array(_) => {
panic!("SeaQuery doesn't support array arguments for Any");
}
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::MacAddressArray(_) => panic!("Array support not implemented for Any"),
}
}
args
Expand Down
46 changes: 42 additions & 4 deletions sea-query-binder/src/sqlx_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ impl<'q> sqlx::IntoArguments<'q, sqlx::mysql::MySql> for SqlxValues {
Value::Json(j) => {
args.add(j.as_deref());
}
#[cfg(feature = "postgres-array")]
Value::Array(_) => {
panic!("Mysql doesn't support array arguments");
}
#[cfg(feature = "with-ipnetwork")]
Value::IpNetwork(_) => {
panic!("Mysql doesn't support IpNetwork arguments");
Expand All @@ -117,6 +113,48 @@ impl<'q> sqlx::IntoArguments<'q, sqlx::mysql::MySql> for SqlxValues {
Value::MacAddress(_) => {
panic!("Mysql doesn't support MacAddress arguments");
}

#[cfg(feature = "postgres-array")]
Value::BoolArray(_)
| Value::TinyIntArray(_)
| Value::SmallIntArray(_)
| Value::IntArray(_)
| Value::BigIntArray(_)
| Value::SmallUnsignedArray(_)
| Value::UnsignedArray(_)
| Value::BigUnsignedArray(_)
| Value::FloatArray(_)
| Value::DoubleArray(_)
| Value::StringArray(_)
| Value::CharArray(_) => panic!("Mysql doesn't support array arguments"),
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::ChronoDateArray(_)
| Value::ChronoTimeArray(_)
| Value::ChronoDateTimeArray(_)
| Value::ChronoDateTimeUtcArray(_)
| Value::ChronoDateTimeLocalArray(_)
| Value::ChronoDateTimeWithTimeZoneArray(_) => {
panic!("Mysql doesn't support array")
}
#[cfg(all(feature = "with-time", feature = "postgres-array"))]
Value::TimeDateArray(_)
| Value::TimeTimeArray(_)
| Value::TimeDateTimeArray(_)
| Value::TimeDateTimeWithTimeZoneArray(_) => {
panic!("Mysql doesn't support array")
}
#[cfg(all(feature = "with-uuid", feature = "postgres-array"))]
Value::UuidArray(_) => panic!("Mysql doesn't support array"),
#[cfg(all(feature = "with-rust_decimal", feature = "postgres-array"))]
Value::DecimalArray(_) => panic!("Mysql doesn't support array"),
#[cfg(all(feature = "with-bigdecimal", feature = "postgres-array"))]
Value::BigDecimalArray(_) => panic!("Mysql doesn't support array"),
#[cfg(all(feature = "with-json", feature = "postgres-array"))]
Value::JsonArray(_) => panic!("Mysql doesn't support array"),
#[cfg(all(feature = "with-ipnetwork", feature = "postgres-array"))]
Value::IpNetworkArray(_) => panic!("Mysql doesn't support array"),
#[cfg(all(feature = "with-mac_address", feature = "postgres-array"))]
Value::MacAddressArray(_) => panic!("Mysql doesn't support array"),
}
}
args
Expand Down
110 changes: 76 additions & 34 deletions sea-query-binder/src/sqlx_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,74 +49,116 @@ impl<'q> sqlx::IntoArguments<'q, sqlx::postgres::Postgres> for SqlxValues {
Value::Bytes(b) => {
args.add(b.as_deref());
}
#[cfg(feature = "with-chrono")]
Value::ChronoDate(d) => {
args.add(d.as_deref());
#[cfg(feature = "postgres-array")]
Value::BoolArray(v) => args.add(v.as_deref()),
#[cfg(feature = "postgres-array")]
Value::TinyIntArray(v) => args.add(v.as_deref()),
#[cfg(feature = "postgres-array")]
Value::SmallIntArray(v) => args.add(v.as_deref()),
#[cfg(feature = "postgres-array")]
Value::IntArray(v) => args.add(v.as_deref()),
#[cfg(feature = "postgres-array")]
Value::BigIntArray(v) => args.add(v.as_deref()),
#[cfg(feature = "postgres-array")]
Value::SmallUnsignedArray(v) => {
args.add(v.map(|v| v.iter().map(|&i| i as i32).collect::<Vec<i32>>()))
}
#[cfg(feature = "with-chrono")]
Value::ChronoTime(t) => {
args.add(t.as_deref());
#[cfg(feature = "postgres-array")]
Value::UnsignedArray(v) => {
args.add(v.map(|v| v.iter().map(|&i| i as i64).collect::<Vec<i64>>()))
}
#[cfg(feature = "with-chrono")]
Value::ChronoDateTime(t) => {
args.add(t.as_deref());
#[cfg(feature = "postgres-array")]
Value::BigUnsignedArray(v) => args.add(v.map(|v| {
v.iter()
.map(|&i| <i64 as std::convert::TryFrom<u64>>::try_from(i).unwrap())
.collect::<Vec<i64>>()
})),
#[cfg(feature = "postgres-array")]
Value::FloatArray(v) => args.add(v.as_deref()),
#[cfg(feature = "postgres-array")]
Value::DoubleArray(v) => args.add(v.as_deref()),
#[cfg(feature = "postgres-array")]
Value::StringArray(v) => args.add(v.as_deref()),
#[cfg(feature = "postgres-array")]
Value::CharArray(v) => {
args.add(v.map(|v| v.iter().map(|c| c.to_string()).collect::<Vec<String>>()))
}
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeUtc(t) => {
args.add(t.as_deref());
}
Value::ChronoDate(d) => args.add(d.as_deref()),
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::ChronoDateArray(d) => args.add(d.as_deref()),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeLocal(t) => {
args.add(t.as_deref());
}
Value::ChronoTime(d) => args.add(d.as_deref()),
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::ChronoTimeArray(d) => args.add(d.as_deref()),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeWithTimeZone(t) => {
args.add(t.as_deref());
}
Value::ChronoDateTime(d) => args.add(d.as_deref()),
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::ChronoDateTimeArray(d) => args.add(d.as_deref()),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeUtc(d) => args.add(d.as_deref()),
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::ChronoDateTimeUtcArray(d) => args.add(d.as_deref()),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeLocal(d) => args.add(d.as_deref()),
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::ChronoDateTimeLocalArray(d) => args.add(d.as_deref()),
#[cfg(feature = "with-chrono")]
Value::ChronoDateTimeWithTimeZone(d) => args.add(d.as_deref()),
#[cfg(all(feature = "with-chrono", feature = "postgres-array"))]
Value::ChronoDateTimeWithTimeZoneArray(d) => args.add(d.as_deref()),
#[cfg(feature = "with-time")]
Value::TimeDate(t) => {
args.add(t.as_deref());
}
Value::TimeDate(t) => args.add(t.as_deref()),
#[cfg(all(feature = "with-time", feature = "postgres-array"))]
Value::TimeDateArray(t) => args.add(t.as_deref()),
#[cfg(feature = "with-time")]
Value::TimeTime(t) => {
args.add(t.as_deref());
}
Value::TimeTime(t) => args.add(t.as_deref()),
#[cfg(all(feature = "with-time", feature = "postgres-array"))]
Value::TimeTimeArray(t) => args.add(t.as_deref()),
#[cfg(feature = "with-time")]
Value::TimeDateTime(t) => {
args.add(t.as_deref());
}
Value::TimeDateTime(t) => args.add(t.as_deref()),
#[cfg(all(feature = "with-time", feature = "postgres-array"))]
Value::TimeDateTimeArray(t) => args.add(t.as_deref()),
#[cfg(feature = "with-time")]
Value::TimeDateTimeWithTimeZone(t) => {
args.add(t.as_deref());
}
Value::TimeDateTimeWithTimeZone(t) => args.add(t.as_deref()),
#[cfg(all(feature = "with-time", feature = "postgres-array"))]
Value::TimeDateTimeWithTimeZoneArray(t) => args.add(t.as_deref()),
#[cfg(feature = "with-uuid")]
Value::Uuid(uuid) => {
args.add(uuid.as_deref());
}
#[cfg(all(feature = "with-uuid", feature = "postgres-array"))]
Value::UuidArray(uuid) => args.add(uuid.as_deref()),
#[cfg(feature = "with-rust_decimal")]
Value::Decimal(d) => {
args.add(d.as_deref());
}
#[cfg(all(feature = "with-rust_decimal", feature = "postgres-array"))]
Value::DecimalArray(d) => args.add(d.as_deref()),
#[cfg(feature = "with-bigdecimal")]
Value::BigDecimal(d) => {
args.add(d.as_deref());
}
#[cfg(all(feature = "with-bigdecimal", feature = "postgres-array"))]
Value::BigDecimalArray(d) => args.add(d.as_deref()),
#[cfg(feature = "with-json")]
Value::Json(j) => {
args.add(j.as_deref());
}
#[cfg(feature = "postgres-array")]
Value::Array(_) => {
panic!("SeaQuery doesn't support array arguments for Postgresql");
}
#[cfg(all(feature = "with-json", feature = "postgres-array"))]
Value::JsonArray(d) => args.add(d.as_deref()),
#[cfg(feature = "with-ipnetwork")]
Value::IpNetwork(ip) => {
args.add(ip.as_deref());
}
#[cfg(all(feature = "with-ipnetwork", feature = "postgres-array"))]
Value::IpNetworkArray(d) => args.add(d.as_deref()),
#[cfg(feature = "with-mac_address")]
Value::MacAddress(mac) => {
args.add(mac.as_deref());
}
#[cfg(all(feature = "with-mac_address", feature = "postgres-array"))]
Value::MacAddressArray(d) => args.add(d.as_deref()),
}
}
args
Expand Down
Loading