diff --git a/README.md b/README.md index 1e92ef464..ee03da4ef 100644 --- a/README.md +++ b/README.md @@ -227,7 +227,19 @@ There's a few things on our immediate TODO list will be built into the `cargo-pgx` subcommand and make use of https://github.com/zombodb/postgres-parser. - More examples -- especially around memory management and the various derive macros `#[derive(PostgresType/Enum)]` -## Experimental Features + +## Feature Flags +PGX has optional feature flags for Rust code that do not involve configuring the version of Postgres used, +but rather extend additional support for other kinds of Rust code. These are not included by default. + +### "time-crate": interop with the `time` crate +This crate once used direct interop with the excellent [time crate][timecrate]. +However, due to complications involving performance and accurate interop with Postgres, +this feature is now considered deprecated in favor of a lower-overhead interop. +You may still request implementations of `TryFrom for pgx::MatchingType` +and `From for pgx::MatchingType` by enabling the `"time-crate"` feature. + +### Experimental Features Adding `pgx = { version = "0.5.0-beta.0", features = ["postgrestd"] }` to your Cargo.toml will enable a **highly** experimental variant of `pgx` designed for integration with `postgrestd`, @@ -269,3 +281,4 @@ Use of this source code is governed by the MIT license that can be found in the ``` [Discord]: https://discord.gg/hPb93Y9 +[timecrate]: https://crates.io/crates/time diff --git a/pgx-tests/Cargo.toml b/pgx-tests/Cargo.toml index 645d0390f..a3b40a78f 100644 --- a/pgx-tests/Cargo.toml +++ b/pgx-tests/Cargo.toml @@ -35,7 +35,6 @@ rustdoc-args = ["--cfg", "docsrs"] owo-colors = "3.4.0" once_cell = "1.10.0" libc = "0.2.126" -pgx = { path = "../pgx", default-features = false, version= "=0.5.0-beta.0" } pgx-macros = { path = "../pgx-macros", version= "=0.5.0-beta.0" } pgx-pg-config = { path = "../pgx-pg-config", version= "=0.5.0-beta.0" } pgx-utils = { path = "../pgx-utils", version= "=0.5.0-beta.0" } @@ -47,3 +46,9 @@ shutdown_hooks = "0.1.0" time = "0.3.9" eyre = "0.6.8" thiserror = "1.0" + +[dependencies.pgx] +path = "../pgx" +default-features = false +features = [ "time-crate" ] # testing purposes +version= "=0.5.0-beta.0" diff --git a/pgx/Cargo.toml b/pgx/Cargo.toml index 8207fb3bb..bbad8e511 100644 --- a/pgx/Cargo.toml +++ b/pgx/Cargo.toml @@ -24,6 +24,7 @@ pg11 = [ "pgx-pg-sys/pg11" ] pg12 = [ "pgx-pg-sys/pg12" ] pg13 = [ "pgx-pg-sys/pg13" ] pg14 = [ "pgx-pg-sys/pg14" ] +time-crate = [ ] # TODO(0.6.0): add "dep:time" [package.metadata.docs.rs] features = ["pg14"] @@ -43,7 +44,7 @@ pgx-utils = { path = "../pgx-utils/", version = "=0.5.0-beta.0" } serde = { version = "1.0.137", features = [ "derive" ] } serde_cbor = "0.11.2" serde_json = "1.0.81" -time = { version = "0.3.9", features = ["formatting", "parsing", "alloc", "macros"] } +time = { version = "0.3.9", features = ["formatting", "parsing", "alloc", "macros"] } # TODO(0.6.0): add `optional = true` atomic-traits = "0.3.0" heapless = "0.7.13" uuid = { version = "1.0.0", features = [ "v4" ] } diff --git a/pgx/src/datum/date.rs b/pgx/src/datum/date.rs index 4c50854f8..828b0e524 100644 --- a/pgx/src/datum/date.rs +++ b/pgx/src/datum/date.rs @@ -53,11 +53,12 @@ impl Date { #[inline] #[deprecated( since = "0.5.0", - note = "the repr of pgx::Date is no longer time::Date \ - and this fn will be removed in a future version" + note = "the repr of pgx::Date is no longer time::Date and this fn will be broken in a future version\n\ + please use pgx's `time-crate` feature to opt-in to `From for pgx::Date`" )] pub fn new(date: time::Date) -> Date { - date.into() + // TODO(0.6.0): remove this + timecrate_date_to_pg_date(date) } #[inline] @@ -96,13 +97,21 @@ impl Date { } } +#[cfg(feature = "time-crate")] impl From for Date { #[inline] fn from(date: time::Date) -> Self { - Date::from_pg_epoch_days(date.to_julian_day() - POSTGRES_EPOCH_JDATE) + timecrate_date_to_pg_date(date) } } +// This function only exists as a temporary shim while the deprecation cycle for Date::new is running +// TODO(0.6.0): remove this +#[inline(always)] +fn timecrate_date_to_pg_date(date: time::Date) -> Date { + Date::from_pg_epoch_days(date.to_julian_day() - POSTGRES_EPOCH_JDATE) +} + impl TryFrom for time::Date { type Error = i32; fn try_from(date: Date) -> Result {