-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cuid): add timestamp extraction fn for cuid
Some ID generation functions have timestamps embedded in them, and being able to extract the timestamp is a useful feature. Timestamps extracted from IDs can be used in logic checks, as virtual/generated columns and have many other use cases. This commit adds functions for extracting timestamps from CUID values (even though they are deprecated in favor of CUID2). Signed-off-by: vados <[email protected]>
- Loading branch information
Showing
5 changed files
with
283 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,7 @@ | |
name = "pg_idkit" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = [ | ||
"Victor Adossi <[email protected]>" | ||
] | ||
authors = ["Victor Adossi <[email protected]>"] | ||
rust-version = "1.73.0" | ||
description = """ | ||
A Postgres extension for generating UUIDs | ||
|
@@ -18,17 +16,19 @@ maintenance = { status = "actively-maintained" } | |
|
||
[features] | ||
default = ["pg15"] | ||
pg11 = [ "pgrx/pg11", "pgrx-tests/pg11" ] | ||
pg12 = [ "pgrx/pg12", "pgrx-tests/pg12" ] | ||
pg13 = [ "pgrx/pg13", "pgrx-tests/pg13" ] | ||
pg14 = [ "pgrx/pg14", "pgrx-tests/pg14" ] | ||
pg15 = [ "pgrx/pg15", "pgrx-tests/pg15" ] | ||
pg11 = ["pgrx/pg11", "pgrx-tests/pg11"] | ||
pg12 = ["pgrx/pg12", "pgrx-tests/pg12"] | ||
pg13 = ["pgrx/pg13", "pgrx-tests/pg13"] | ||
pg14 = ["pgrx/pg14", "pgrx-tests/pg14"] | ||
pg15 = ["pgrx/pg15", "pgrx-tests/pg15"] | ||
pg_test = [] | ||
|
||
[dependencies] | ||
cuid = "1.3.2" | ||
cuid2 = "0.1.2" | ||
getrandom = "0.2.10" | ||
base36 = "0.0.1" | ||
chrono = { version = "0.4.31", default-features = false, features = ["clock"] } | ||
ksuid = "0.2.0" | ||
nanoid = "0.4.0" | ||
pgrx = "=0.11.0" | ||
|
@@ -38,6 +38,7 @@ timeflake-rs = "0.3.0" | |
ulid = "1.1.0" | ||
uuid7 = "0.7.2" | ||
xid = "1.0.3" | ||
miette = { version = "5.10.0", features = ["fancy"] } | ||
|
||
[dev-dependencies] | ||
pgrx-tests = "=0.11.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// A trait that encapsulates things that can be converted to some type | ||
/// or to an error if conversion fails (ex. Result, Option, etc) | ||
pub(crate) trait OrPgxError<T> { | ||
/// Convert the given type to a T, possibly failing | ||
/// and calling [`pgrx::error`], with a given prefix if an error is returned | ||
fn or_pgrx_error(self, prefix: impl AsRef<str>) -> T; | ||
} | ||
|
||
impl<T, E> OrPgxError<T> for Result<T, E> | ||
where | ||
E: std::error::Error, | ||
{ | ||
fn or_pgrx_error(self, prefix: impl AsRef<str>) -> T { | ||
match self { | ||
Ok(v) => v, | ||
Err(e) => pgrx::error!("{}: {e}", prefix.as_ref()), | ||
} | ||
} | ||
} | ||
|
||
impl<T> OrPgxError<T> for Option<T> { | ||
fn or_pgrx_error(self, prefix: impl AsRef<str>) -> T { | ||
match self { | ||
Some(v) => v, | ||
None => pgrx::error!("{}", prefix.as_ref()), | ||
} | ||
} | ||
} |
Oops, something went wrong.