-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add type mapping for 'pg_sys::TimestampTz' to 'timestamp with time zone'
This allows the `pg_sys::TimestampTz' type to be used in function signatures, providing zero-cost access to the underlying i64 timestamp of a 'timestamp with time zone' field.
- Loading branch information
1 parent
de8ce98
commit b4d0276
Showing
8 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
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,22 @@ | ||
# Auto-generated by pgx. You may edit this, or delete it to have a new one created. | ||
|
||
[target.x86_64-unknown-linux-gnu] | ||
linker = ".cargo/pgx-linker-script.sh" | ||
|
||
[target.aarch64-unknown-linux-gnu] | ||
linker = ".cargo/pgx-linker-script.sh" | ||
|
||
[target.x86_64-unknown-linux-musl] | ||
linker = ".cargo/pgx-linker-script.sh" | ||
|
||
[target.aarch64-unknown-linux-musl] | ||
linker = ".cargo/pgx-linker-script.sh" | ||
|
||
[target.x86_64-apple-darwin] | ||
linker = ".cargo/pgx-linker-script.sh" | ||
|
||
[target.aarch64-apple-darwin] | ||
linker = ".cargo/pgx-linker-script.sh" | ||
|
||
[target.x86_64-unknown-freebsd] | ||
linker = ".cargo/pgx-linker-script.sh" |
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,19 @@ | ||
#! /usr/bin/env bash | ||
# Auto-generated by pgx. You may edit this, or delete it to have a new one created. | ||
|
||
if [[ $CARGO_BIN_NAME == "sql-generator" ]]; then | ||
UNAME=$(uname) | ||
if [[ $UNAME == "Darwin" ]]; then | ||
TEMP=$(mktemp pgx-XXX) | ||
echo "*_pgx_internals_*" > ${TEMP} | ||
gcc -exported_symbols_list ${TEMP} $@ | ||
rm -rf ${TEMP} | ||
else | ||
TEMP=$(mktemp pgx-XXX) | ||
echo "{ __pgx_internals_*; };" > ${TEMP} | ||
gcc -Wl,-dynamic-list=${TEMP} $@ | ||
rm -rf ${TEMP} | ||
fi | ||
else | ||
gcc -Wl,-undefined,dynamic_lookup $@ | ||
fi |
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,6 @@ | ||
.DS_Store | ||
.idea/ | ||
/target | ||
*.iml | ||
**/*.rs.bk | ||
Cargo.lock |
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,38 @@ | ||
[package] | ||
name = "builtin_types" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
# remove this empty 'workspace' declaration if compiling outside of 'pgx' | ||
[workspace] | ||
|
||
[features] | ||
default = ["pg13"] | ||
pg10 = ["pgx/pg10", "pgx-tests/pg10" ] | ||
pg11 = ["pgx/pg11", "pgx-tests/pg11" ] | ||
pg12 = ["pgx/pg12", "pgx-tests/pg12" ] | ||
pg13 = ["pgx/pg13", "pgx-tests/pg13" ] | ||
pg14 = ["pgx/pg14", "pgx-tests/pg14" ] | ||
pg_test = [] | ||
|
||
[dependencies] | ||
pgx = { path = "../../../pgx/pgx", default-features = false } | ||
pgx-macros = { path = "../../../pgx/pgx-macros", default-features = false } | ||
|
||
|
||
[dev-dependencies] | ||
pgx-tests = { path = "../../../pgx/pgx-tests" } | ||
|
||
# uncomment these if compiling outside of 'pgx' | ||
# [profile.dev] | ||
# panic = "unwind" | ||
# lto = "thin" | ||
|
||
# [profile.release] | ||
# panic = "unwind" | ||
# opt-level = 3 | ||
# lto = "fat" | ||
# codegen-units = 1 |
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,5 @@ | ||
comment = 'builtin_types: Created by pgx' | ||
default_version = '@CARGO_VERSION@' | ||
module_pathname = '$libdir/builtin_types' | ||
relocatable = false | ||
superuser = false |
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,2 @@ | ||
/* Auto-generated by pgx. You may edit this, or delete it to have a new one created. */ | ||
pgx::pg_binary_magic!(builtin_types); |
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,39 @@ | ||
use pgx::*; | ||
|
||
pg_module_magic!(); | ||
|
||
#[pg_extern] | ||
fn timestamptz(tstz: pg_sys::TimestampTz) -> i64 { | ||
tstz | ||
} | ||
|
||
#[cfg(any(test, feature = "pg_test"))] | ||
#[pg_schema] | ||
mod tests { | ||
use pgx::*; | ||
|
||
use std::time::Duration; | ||
|
||
#[pg_test] | ||
fn test_timestamptz() { | ||
let result = Spi::get_one::<i64>(r#" | ||
SELECT timestamptz('2000-01-01 00:01:00.0000000+00'::timestamptz) | ||
"#).expect("SQL query failed"); | ||
|
||
assert_eq!(result, Duration::from_secs(60).as_micros() as i64); | ||
} | ||
|
||
} | ||
|
||
#[cfg(test)] | ||
pub mod pg_test { | ||
|
||
pub fn setup(_options: Vec<&str>) { | ||
// perform one-off initialization when the pg_test framework starts | ||
} | ||
|
||
pub fn postgresql_conf_options() -> Vec<&'static str> { | ||
// return any postgresql.conf settings that are required for your tests | ||
vec![] | ||
} | ||
} |
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