` where `T` is any of `i32`, `i64`, `Numeric`, `AnyNumeric`, `Date`, `Timestamp`, and `TimestampWithTimeZone`.
--------------------------------------------------------------------------------
/pgrx-examples/range/range.control:
--------------------------------------------------------------------------------
1 | comment = 'range: Created by pgrx'
2 | default_version = '0.1.0'
3 | module_pathname = 'range'
4 | relocatable = false
5 | superuser = false
6 | schema = range
--------------------------------------------------------------------------------
/pgrx-examples/range/src/bin/pgrx_embed.rs:
--------------------------------------------------------------------------------
1 | ::pgrx::pgrx_embed!();
2 |
--------------------------------------------------------------------------------
/pgrx-examples/range/src/lib.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | use pgrx::prelude::*;
11 |
12 | pgrx::pg_module_magic!(c"range", pgrx::pg_sys::PG_VERSION);
13 |
14 | #[pg_extern]
15 | fn range(s: i32, e: i32) -> pgrx::Range {
16 | (s..e).into()
17 | }
18 |
19 | #[pg_extern]
20 | fn range_from(s: i32) -> pgrx::Range {
21 | (s..).into()
22 | }
23 |
24 | #[pg_extern]
25 | fn range_full() -> pgrx::Range {
26 | (..).into()
27 | }
28 |
29 | #[pg_extern]
30 | fn range_inclusive(s: i32, e: i32) -> pgrx::Range {
31 | (s..=e).into()
32 | }
33 |
34 | #[pg_extern]
35 | fn range_to(e: i32) -> pgrx::Range {
36 | (..e).into()
37 | }
38 |
39 | #[pg_extern]
40 | fn range_to_inclusive(e: i32) -> pgrx::Range {
41 | (..=e).into()
42 | }
43 |
44 | #[pg_extern]
45 | fn empty() -> pgrx::Range {
46 | pgrx::Range::empty()
47 | }
48 |
49 | #[pg_extern]
50 | fn infinite() -> pgrx::Range {
51 | pgrx::Range::infinite()
52 | }
53 |
54 | #[pg_extern]
55 | fn assert_range(r: pgrx::Range, s: i32, e: i32) -> bool {
56 | r == (s..e).into()
57 | }
58 |
--------------------------------------------------------------------------------
/pgrx-examples/range/tests/pg_regress/expected/make_range.out:
--------------------------------------------------------------------------------
1 | SELECT range.range(10, 101);
2 | range
3 | ----------
4 | [10,101)
5 | (1 row)
6 |
7 |
--------------------------------------------------------------------------------
/pgrx-examples/range/tests/pg_regress/expected/setup.out:
--------------------------------------------------------------------------------
1 | -- this setup file is run immediately after the regression database is (re)created
2 | -- the file is optional but you likely want to create the extension
3 | CREATE EXTENSION range;
4 |
--------------------------------------------------------------------------------
/pgrx-examples/range/tests/pg_regress/sql/make_range.sql:
--------------------------------------------------------------------------------
1 | SELECT range.range(10, 101);
--------------------------------------------------------------------------------
/pgrx-examples/range/tests/pg_regress/sql/setup.sql:
--------------------------------------------------------------------------------
1 | -- this setup file is run immediately after the regression database is (re)created
2 | -- the file is optional but you likely want to create the extension
3 | CREATE EXTENSION range;
4 |
--------------------------------------------------------------------------------
/pgrx-examples/range/tests/pg_regress/sql/store_ranges.sql:
--------------------------------------------------------------------------------
1 | DROP TABLE IF EXISTS store_ranges;
2 | CREATE TABLE store_ranges
3 | (
4 | id serial8,
5 | r int4range
6 | );
7 |
8 | INSERT INTO store_ranges (r)
9 | SELECT range.range(100, 100 + x)
10 | FROM generate_series(0, 100) x;
11 | SELECT *
12 | FROM store_ranges;
--------------------------------------------------------------------------------
/pgrx-examples/schemas/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
3 | /target
4 | *.iml
5 | **/*.rs.bk
6 | Cargo.lock
7 | sql/schemas-1.0.sql
8 |
--------------------------------------------------------------------------------
/pgrx-examples/schemas/Cargo.toml:
--------------------------------------------------------------------------------
1 | #LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | #LICENSE
3 | #LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | #LICENSE
5 | #LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | #LICENSE
7 | #LICENSE All rights reserved.
8 | #LICENSE
9 | #LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 |
11 | [package]
12 | name = "schemas"
13 | version = "0.0.0"
14 | edition = "2021"
15 | publish = false
16 |
17 | [lib]
18 | crate-type = ["cdylib", "lib"]
19 |
20 | [[bin]]
21 | name = "pgrx_embed_schemas"
22 | path = "./src/bin/pgrx_embed.rs"
23 |
24 | [features]
25 | default = ["pg13"]
26 | pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
27 | pg14 = ["pgrx/pg14", "pgrx-tests/pg14"]
28 | pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
29 | pg16 = ["pgrx/pg16", "pgrx-tests/pg16"]
30 | pg17 = ["pgrx/pg17", "pgrx-tests/pg17"]
31 | pg18 = ["pgrx/pg18", "pgrx-tests/pg18"]
32 | pg_test = []
33 |
34 | [dependencies]
35 | pgrx = { path = "../../pgrx", default-features = false }
36 | serde = "1.0"
37 |
38 | [dev-dependencies]
39 | pgrx-tests = { path = "../../pgrx-tests" }
40 |
41 | # uncomment these if compiling outside of 'pgrx'
42 | # [profile.dev]
43 | # panic = "unwind"
44 |
45 | # [profile.release]
46 | # panic = "unwind"
47 | # opt-level = 3
48 | # lto = "fat"
49 | # codegen-units = 1
50 |
--------------------------------------------------------------------------------
/pgrx-examples/schemas/schemas.control:
--------------------------------------------------------------------------------
1 | comment = 'schemas: Created by pgrx'
2 | default_version = '@CARGO_VERSION@'
3 | module_pathname = 'schemas'
4 | relocatable = false
5 | superuser = true # b/c this extension creates objects in "pg_catalog"
6 |
--------------------------------------------------------------------------------
/pgrx-examples/schemas/src/bin/pgrx_embed.rs:
--------------------------------------------------------------------------------
1 | ::pgrx::pgrx_embed!();
2 |
--------------------------------------------------------------------------------
/pgrx-examples/shmem/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
3 | /target
4 | *.iml
5 | **/*.rs.bk
6 | Cargo.lock
7 | sql/shmem-1.0.sql
8 |
--------------------------------------------------------------------------------
/pgrx-examples/shmem/Cargo.toml:
--------------------------------------------------------------------------------
1 | #LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | #LICENSE
3 | #LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | #LICENSE
5 | #LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | #LICENSE
7 | #LICENSE All rights reserved.
8 | #LICENSE
9 | #LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 |
11 | [package]
12 | name = "shmem"
13 | version = "0.0.0"
14 | edition = "2021"
15 | publish = false
16 |
17 | [lib]
18 | crate-type = ["cdylib", "lib"]
19 |
20 | [[bin]]
21 | name = "pgrx_embed_shmem"
22 | path = "./src/bin/pgrx_embed.rs"
23 |
24 | [features]
25 | default = ["pg13"]
26 | pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
27 | pg14 = ["pgrx/pg14", "pgrx-tests/pg14"]
28 | pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
29 | pg16 = ["pgrx/pg16", "pgrx-tests/pg16"]
30 | pg17 = ["pgrx/pg17", "pgrx-tests/pg17"]
31 | pg18 = ["pgrx/pg18", "pgrx-tests/pg18"]
32 | pg_test = []
33 |
34 | [dependencies]
35 | heapless = "0.8"
36 | pgrx = { path = "../../pgrx", default-features = false }
37 | serde = { version = "1.0", features = ["derive"] }
38 |
39 | [dev-dependencies]
40 | pgrx-tests = { path = "../../pgrx-tests" }
41 |
42 | # uncomment these if compiling outside of 'pgrx'
43 | # [profile.dev]
44 | # panic = "unwind"
45 |
46 | # [profile.release]
47 | # panic = "unwind"
48 | # opt-level = 3
49 | # lto = "fat"
50 | # codegen-units = 1
51 |
--------------------------------------------------------------------------------
/pgrx-examples/shmem/README.md:
--------------------------------------------------------------------------------
1 | ## Postgres Shared Memory and LWLock Support
2 |
3 | Important:
4 | > Extensions that use shared memory **must** be loaded via `postgresql.conf`'s
5 | >`shared_preload_libraries` configuration setting.
6 |
7 | For now, please check out the example in [src/lib.rs](src/lib.rs). It demonstrates how to
8 | safely use standard Rust types, Rust Atomics, and various data structures from
9 | [`heapless`](https://crates.io/crates/heapless) via Postgres' shared memory system.
10 |
11 |
--------------------------------------------------------------------------------
/pgrx-examples/shmem/shmem.control:
--------------------------------------------------------------------------------
1 | comment = 'shmem: Created by pgrx'
2 | default_version = '@CARGO_VERSION@'
3 | module_pathname = 'shmem'
4 | relocatable = false
5 | superuser = false
6 |
--------------------------------------------------------------------------------
/pgrx-examples/shmem/src/bin/pgrx_embed.rs:
--------------------------------------------------------------------------------
1 | ::pgrx::pgrx_embed!();
2 |
--------------------------------------------------------------------------------
/pgrx-examples/spi/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
3 | /target
4 | *.iml
5 | **/*.rs.bk
6 | Cargo.lock
7 | sql/spi-1.0.sql
8 |
--------------------------------------------------------------------------------
/pgrx-examples/spi/Cargo.toml:
--------------------------------------------------------------------------------
1 | #LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | #LICENSE
3 | #LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | #LICENSE
5 | #LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | #LICENSE
7 | #LICENSE All rights reserved.
8 | #LICENSE
9 | #LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 |
11 | [package]
12 | name = "spi"
13 | version = "0.0.0"
14 | edition = "2021"
15 | publish = false
16 |
17 | [lib]
18 | crate-type = ["cdylib", "lib"]
19 |
20 | [[bin]]
21 | name = "pgrx_embed_spi"
22 | path = "./src/bin/pgrx_embed.rs"
23 |
24 | [features]
25 | default = ["pg13"]
26 | pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
27 | pg14 = ["pgrx/pg14", "pgrx-tests/pg14"]
28 | pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
29 | pg16 = ["pgrx/pg16", "pgrx-tests/pg16"]
30 | pg17 = ["pgrx/pg17", "pgrx-tests/pg17"]
31 | pg18 = ["pgrx/pg18", "pgrx-tests/pg18"]
32 | pg_test = []
33 |
34 | [dependencies]
35 | pgrx = { path = "../../pgrx", default-features = false }
36 |
37 | [dev-dependencies]
38 | pgrx-tests = { path = "../../pgrx-tests" }
39 |
40 | # uncomment these if compiling outside of 'pgrx'
41 | # [profile.dev]
42 | # panic = "unwind"
43 |
44 | # [profile.release]
45 | # panic = "unwind"
46 | # opt-level = 3
47 | # lto = "fat"
48 | # codegen-units = 1
49 |
--------------------------------------------------------------------------------
/pgrx-examples/spi/README.md:
--------------------------------------------------------------------------------
1 | Some examples of using SPI (Server Programming Interface) with pgrx.
2 |
3 | A video covering this topic is located here: https://www.twitch.tv/videos/693509390
--------------------------------------------------------------------------------
/pgrx-examples/spi/spi.control:
--------------------------------------------------------------------------------
1 | comment = 'spi: Created by pgrx'
2 | default_version = '@CARGO_VERSION@'
3 | module_pathname = 'spi'
4 | relocatable = false
5 | superuser = false
6 | schema = 'spi'
7 |
--------------------------------------------------------------------------------
/pgrx-examples/spi/src/bin/pgrx_embed.rs:
--------------------------------------------------------------------------------
1 | ::pgrx::pgrx_embed!();
2 |
--------------------------------------------------------------------------------
/pgrx-examples/spi_srf/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
3 | /target
4 | *.iml
5 | **/*.rs.bk
6 | Cargo.lock
7 | sql/spi-1.0.sql
8 |
--------------------------------------------------------------------------------
/pgrx-examples/spi_srf/Cargo.toml:
--------------------------------------------------------------------------------
1 | #LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | #LICENSE
3 | #LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | #LICENSE
5 | #LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | #LICENSE
7 | #LICENSE All rights reserved.
8 | #LICENSE
9 | #LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 |
11 | [package]
12 | name = "spi_srf"
13 | version = "0.0.0"
14 | edition = "2021"
15 | publish = false
16 | rust-version = "1.58"
17 |
18 | [lib]
19 | crate-type = ["cdylib", "lib"]
20 |
21 | [[bin]]
22 | name = "pgrx_embed_spi_srf"
23 | path = "./src/bin/pgrx_embed.rs"
24 |
25 | [features]
26 | default = ["pg13"]
27 | pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
28 | pg14 = ["pgrx/pg14", "pgrx-tests/pg14"]
29 | pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
30 | pg16 = ["pgrx/pg16", "pgrx-tests/pg16"]
31 | pg17 = ["pgrx/pg17", "pgrx-tests/pg17"]
32 | pg18 = ["pgrx/pg18", "pgrx-tests/pg18"]
33 | pg_test = []
34 |
35 | [dependencies]
36 | pgrx = { path = "../../pgrx", default-features = false }
37 |
38 | [dev-dependencies]
39 | pgrx-tests = { path = "../../pgrx-tests" }
40 |
41 | # uncomment these if compiling outside of 'pgrx'
42 | # [profile.dev]
43 | # panic = "unwind"
44 |
45 | # [profile.release]
46 | # panic = "unwind"
47 | # opt-level = 3
48 | # lto = "fat"
49 | # codegen-units = 1
50 |
--------------------------------------------------------------------------------
/pgrx-examples/spi_srf/README.md:
--------------------------------------------------------------------------------
1 | Some examples of using SPI (Server Programming Interface) and SRF with pgrx.
--------------------------------------------------------------------------------
/pgrx-examples/spi_srf/spi_srf.control:
--------------------------------------------------------------------------------
1 | comment = 'spi_srf: Created by pgrx'
2 | default_version = '@CARGO_VERSION@'
3 | module_pathname = 'spi_srf'
4 | relocatable = false
5 | superuser = false
6 | schema = 'spi_srf'
7 |
--------------------------------------------------------------------------------
/pgrx-examples/spi_srf/src/bin/pgrx_embed.rs:
--------------------------------------------------------------------------------
1 | ::pgrx::pgrx_embed!();
2 |
--------------------------------------------------------------------------------
/pgrx-examples/srf/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
3 | /target
4 | *.iml
5 | **/*.rs.bk
6 | Cargo.lock
7 | sql/srf-1.0.sql
8 |
--------------------------------------------------------------------------------
/pgrx-examples/srf/Cargo.toml:
--------------------------------------------------------------------------------
1 | #LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | #LICENSE
3 | #LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | #LICENSE
5 | #LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | #LICENSE
7 | #LICENSE All rights reserved.
8 | #LICENSE
9 | #LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 |
11 | [package]
12 | name = "srf"
13 | version = "0.0.0"
14 | edition = "2021"
15 | publish = false
16 |
17 | [lib]
18 | crate-type = ["cdylib", "lib"]
19 |
20 | [[bin]]
21 | name = "pgrx_embed_srf"
22 | path = "./src/bin/pgrx_embed.rs"
23 |
24 | [features]
25 | default = ["pg13"]
26 | pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
27 | pg14 = ["pgrx/pg14", "pgrx-tests/pg14"]
28 | pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
29 | pg16 = ["pgrx/pg16", "pgrx-tests/pg16"]
30 | pg17 = ["pgrx/pg17", "pgrx-tests/pg17"]
31 | pg18 = ["pgrx/pg18", "pgrx-tests/pg18"]
32 | pg_test = []
33 |
34 | [dependencies]
35 | pgrx = { path = "../../pgrx", default-features = false }
36 | rand = "0.9.0"
37 |
38 | [dev-dependencies]
39 | pgrx-tests = { path = "../../pgrx-tests" }
40 |
41 | # uncomment these if compiling outside of 'pgrx'
42 | # [profile.dev]
43 | # panic = "unwind"
44 |
45 | # [profile.release]
46 | # panic = "unwind"
47 | # opt-level = 3
48 | # lto = "fat"
49 | # codegen-units = 1
50 |
--------------------------------------------------------------------------------
/pgrx-examples/srf/README.md:
--------------------------------------------------------------------------------
1 | Examples for working with Postgres Set Returning Functions.
2 |
3 | Here's a video that walks through this example (and others):
4 | https://www.twitch.tv/videos/670479038
--------------------------------------------------------------------------------
/pgrx-examples/srf/src/bin/pgrx_embed.rs:
--------------------------------------------------------------------------------
1 | ::pgrx::pgrx_embed!();
2 |
--------------------------------------------------------------------------------
/pgrx-examples/srf/srf.control:
--------------------------------------------------------------------------------
1 | comment = 'srf: Created by pgrx'
2 | default_version = '@CARGO_VERSION@'
3 | module_pathname = 'srf'
4 | relocatable = false
5 | superuser = false
6 | schema = srf
7 |
--------------------------------------------------------------------------------
/pgrx-examples/strings/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
3 | /target
4 | *.iml
5 | **/*.rs.bk
6 | Cargo.lock
7 | sql/strings-1.0.sql
8 |
--------------------------------------------------------------------------------
/pgrx-examples/strings/Cargo.toml:
--------------------------------------------------------------------------------
1 | #LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | #LICENSE
3 | #LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | #LICENSE
5 | #LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | #LICENSE
7 | #LICENSE All rights reserved.
8 | #LICENSE
9 | #LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 |
11 | [package]
12 | name = "strings"
13 | version = "0.0.0"
14 | edition = "2021"
15 | publish = false
16 |
17 | [lib]
18 | crate-type = ["cdylib", "lib"]
19 |
20 | [[bin]]
21 | name = "pgrx_embed_strings"
22 | path = "./src/bin/pgrx_embed.rs"
23 |
24 | [features]
25 | default = ["pg13"]
26 | pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
27 | pg14 = ["pgrx/pg14", "pgrx-tests/pg14"]
28 | pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
29 | pg16 = ["pgrx/pg16", "pgrx-tests/pg16"]
30 | pg17 = ["pgrx/pg17", "pgrx-tests/pg17"]
31 | pg18 = ["pgrx/pg18", "pgrx-tests/pg18"]
32 | pg_test = []
33 |
34 | [dependencies]
35 | pgrx = { path = "../../pgrx", default-features = false }
36 |
37 | [dev-dependencies]
38 | pgrx-tests = { path = "../../pgrx-tests" }
39 |
40 | # uncomment these if compiling outside of 'pgrx'
41 | # [profile.dev]
42 | # panic = "unwind"
43 |
44 | # [profile.release]
45 | # panic = "unwind"
46 | # opt-level = 3
47 | # lto = "fat"
48 | # codegen-units = 1
49 |
--------------------------------------------------------------------------------
/pgrx-examples/strings/README.md:
--------------------------------------------------------------------------------
1 | Examples for working with Rust strings and Postgres `text`/`varlena` types.
2 |
3 | Here's a video that walks through these examples:
4 | https://www.twitch.tv/videos/675826352
--------------------------------------------------------------------------------
/pgrx-examples/strings/src/bin/pgrx_embed.rs:
--------------------------------------------------------------------------------
1 | ::pgrx::pgrx_embed!();
2 |
--------------------------------------------------------------------------------
/pgrx-examples/strings/strings.control:
--------------------------------------------------------------------------------
1 | comment = 'strings: Created by pgrx'
2 | default_version = '@CARGO_VERSION@'
3 | module_pathname = 'strings'
4 | relocatable = false
5 | superuser = false
6 | schema = strings
--------------------------------------------------------------------------------
/pgrx-examples/triggers/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
3 | /target
4 | *.iml
5 | **/*.rs.bk
6 | Cargo.lock
7 | sql/triggers-1.0.sql
8 |
--------------------------------------------------------------------------------
/pgrx-examples/triggers/Cargo.toml:
--------------------------------------------------------------------------------
1 | #LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | #LICENSE
3 | #LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | #LICENSE
5 | #LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | #LICENSE
7 | #LICENSE All rights reserved.
8 | #LICENSE
9 | #LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 |
11 | [package]
12 | name = "triggers"
13 | version = "0.0.0"
14 | edition = "2021"
15 | publish = false
16 |
17 | [lib]
18 | crate-type = ["cdylib", "lib"]
19 |
20 | [[bin]]
21 | name = "pgrx_embed_triggers"
22 | path = "./src/bin/pgrx_embed.rs"
23 |
24 | [features]
25 | default = ["pg13"]
26 | pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
27 | pg14 = ["pgrx/pg14", "pgrx-tests/pg14"]
28 | pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
29 | pg16 = ["pgrx/pg16", "pgrx-tests/pg16"]
30 | pg17 = ["pgrx/pg17", "pgrx-tests/pg17"]
31 | pg18 = ["pgrx/pg18", "pgrx-tests/pg18"]
32 | pg_test = []
33 |
34 | [dependencies]
35 | pgrx = { path = "../../pgrx", default-features = false }
36 | thiserror = "2.0"
37 |
38 | [dev-dependencies]
39 | pgrx-tests = { path = "../../pgrx-tests" }
40 |
41 | # uncomment these if compiling outside of 'pgrx'
42 | #[profile.dev]
43 | #panic = "unwind"
44 |
45 | #[profile.release]
46 | #panic = "unwind"
47 | #opt-level = 3
48 | #lto = "fat"
49 | #codegen-units = 1
50 |
--------------------------------------------------------------------------------
/pgrx-examples/triggers/src/bin/pgrx_embed.rs:
--------------------------------------------------------------------------------
1 | ::pgrx::pgrx_embed!();
2 |
--------------------------------------------------------------------------------
/pgrx-examples/triggers/triggers.control:
--------------------------------------------------------------------------------
1 | comment = 'triggers: Created by pgrx'
2 | default_version = '@CARGO_VERSION@'
3 | module_pathname = 'triggers'
4 | relocatable = false
5 | superuser = false
6 |
--------------------------------------------------------------------------------
/pgrx-examples/versioned_custom_libname_so/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
3 | /target
4 | *.iml
5 | **/*.rs.bk
6 | Cargo.lock
7 |
--------------------------------------------------------------------------------
/pgrx-examples/versioned_custom_libname_so/Cargo.toml:
--------------------------------------------------------------------------------
1 | #LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | #LICENSE
3 | #LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | #LICENSE
5 | #LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | #LICENSE
7 | #LICENSE All rights reserved.
8 | #LICENSE
9 | #LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 |
11 | [package]
12 | name = "versioned_custom_libname_so"
13 | version = "0.0.0"
14 | edition = "2021"
15 | publish = false
16 |
17 | [lib]
18 | crate-type = ["cdylib", "lib"]
19 | name = "versioned_othername"
20 |
21 | [[bin]]
22 | name = "pgrx_embed_versioned_custom_libname_so"
23 | path = "./src/bin/pgrx_embed.rs"
24 |
25 | [features]
26 | default = ["pg13"]
27 | pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
28 | pg14 = ["pgrx/pg14", "pgrx-tests/pg14"]
29 | pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
30 | pg16 = ["pgrx/pg16", "pgrx-tests/pg16"]
31 | pg17 = ["pgrx/pg17", "pgrx-tests/pg17"]
32 | pg18 = ["pgrx/pg18", "pgrx-tests/pg18"]
33 | pg_test = []
34 |
35 | [dependencies]
36 | pgrx = { path = "../../pgrx", default-features = false }
37 |
38 | [dev-dependencies]
39 | pgrx-tests = { path = "../../pgrx-tests" }
40 |
41 | # uncomment these if compiling outside of 'pgrx'
42 | #[profile.dev]
43 | #panic = "unwind"
44 |
45 | #[profile.release]
46 | #panic = "unwind"
47 | #opt-level = 3
48 | #lto = "fat"
49 | #codegen-units = 1
50 |
--------------------------------------------------------------------------------
/pgrx-examples/versioned_custom_libname_so/src/bin/pgrx_embed.rs:
--------------------------------------------------------------------------------
1 | ::pgrx::pgrx_embed!();
2 |
--------------------------------------------------------------------------------
/pgrx-examples/versioned_custom_libname_so/src/lib.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | use pgrx::prelude::*;
11 |
12 | pgrx::pg_module_magic!(c"versioned_custom_libname_so", pgrx::pg_sys::PG_VERSION);
13 |
14 | #[pg_extern]
15 | fn hello_versioned_custom_libname_so() -> &'static str {
16 | "Hello, versioned_custom_libname_so"
17 | }
18 |
19 | #[cfg(any(test, feature = "pg_test"))]
20 | #[pg_schema]
21 | mod tests {
22 | use pgrx::prelude::*;
23 |
24 | #[pg_test]
25 | fn test_hello_versioned_custom_libname_so() {
26 | assert_eq!(
27 | "Hello, versioned_custom_libname_so",
28 | crate::hello_versioned_custom_libname_so()
29 | );
30 | }
31 | }
32 |
33 | #[cfg(test)]
34 | pub mod pg_test {
35 | pub fn setup(_options: Vec<&str>) {
36 | // perform one-off initialization when the pg_test framework starts
37 | }
38 |
39 | pub fn postgresql_conf_options() -> Vec<&'static str> {
40 | // return any postgresql.conf settings that are required for your tests
41 | vec![]
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/pgrx-examples/versioned_custom_libname_so/versioned_othername.control:
--------------------------------------------------------------------------------
1 | comment = 'versioned_custom_libname_so: Created by pgrx'
2 | default_version = '@CARGO_VERSION@'
3 | # commenting-out module_pathname results in this extension being built/run/tested in "versioned shared-object mode"
4 | # module_pathname = 'versioned_othername'
5 | relocatable = false
6 | superuser = false
7 |
--------------------------------------------------------------------------------
/pgrx-examples/versioned_so/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
3 | /target
4 | *.iml
5 | **/*.rs.bk
6 | Cargo.lock
7 |
--------------------------------------------------------------------------------
/pgrx-examples/versioned_so/Cargo.toml:
--------------------------------------------------------------------------------
1 | #LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | #LICENSE
3 | #LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | #LICENSE
5 | #LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | #LICENSE
7 | #LICENSE All rights reserved.
8 | #LICENSE
9 | #LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 |
11 | [package]
12 | name = "versioned_so"
13 | version = "0.0.0"
14 | edition = "2021"
15 | publish = false
16 |
17 | [lib]
18 | crate-type = ["cdylib", "lib"]
19 |
20 | [[bin]]
21 | name = "pgrx_embed_versioned_so"
22 | path = "./src/bin/pgrx_embed.rs"
23 |
24 | [features]
25 | default = ["pg13"]
26 | pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
27 | pg14 = ["pgrx/pg14", "pgrx-tests/pg14"]
28 | pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
29 | pg16 = ["pgrx/pg16", "pgrx-tests/pg16"]
30 | pg17 = ["pgrx/pg17", "pgrx-tests/pg17"]
31 | pg18 = ["pgrx/pg18", "pgrx-tests/pg18"]
32 | pg_test = []
33 |
34 | [dependencies]
35 | pgrx = { path = "../../pgrx", default-features = false }
36 |
37 | [dev-dependencies]
38 | pgrx-tests = { path = "../../pgrx-tests" }
39 |
40 | # uncomment these if compiling outside of 'pgrx'
41 | #[profile.dev]
42 | #panic = "unwind"
43 |
44 | #[profile.release]
45 | #panic = "unwind"
46 | #opt-level = 3
47 | #lto = "fat"
48 | #codegen-units = 1
49 |
--------------------------------------------------------------------------------
/pgrx-examples/versioned_so/src/bin/pgrx_embed.rs:
--------------------------------------------------------------------------------
1 | ::pgrx::pgrx_embed!();
2 |
--------------------------------------------------------------------------------
/pgrx-examples/versioned_so/src/lib.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | use pgrx::prelude::*;
11 |
12 | pgrx::pg_module_magic!(c"versioned_so", pgrx::pg_sys::PG_VERSION);
13 |
14 | #[pg_extern]
15 | fn hello_versioned_so() -> &'static str {
16 | "Hello, versioned_so"
17 | }
18 |
19 | #[cfg(any(test, feature = "pg_test"))]
20 | #[pg_schema]
21 | mod tests {
22 | use pgrx::prelude::*;
23 |
24 | #[pg_test]
25 | fn test_hello_versioned_so() {
26 | assert_eq!("Hello, versioned_so", crate::hello_versioned_so());
27 | }
28 | }
29 |
30 | #[cfg(test)]
31 | pub mod pg_test {
32 | pub fn setup(_options: Vec<&str>) {
33 | // perform one-off initialization when the pg_test framework starts
34 | }
35 |
36 | pub fn postgresql_conf_options() -> Vec<&'static str> {
37 | // return any postgresql.conf settings that are required for your tests
38 | vec![]
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/pgrx-examples/versioned_so/versioned_so.control:
--------------------------------------------------------------------------------
1 | comment = 'versioned_so: Created by pgrx'
2 | default_version = '@CARGO_VERSION@'
3 | # commenting-out module_pathname results in this extension being built/run/tested in "versioned shared-object mode"
4 | # module_pathname = 'versioned_so'
5 | relocatable = false
6 | superuser = false
7 |
--------------------------------------------------------------------------------
/pgrx-examples/wal_decoder/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
3 | /target
4 | *.iml
5 | **/*.rs.bk
6 | Cargo.lock
7 |
--------------------------------------------------------------------------------
/pgrx-examples/wal_decoder/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "wal_decoder"
3 | version = "0.0.0"
4 | edition = "2021"
5 |
6 | [lib]
7 | crate-type = ["cdylib", "lib"]
8 |
9 | [[bin]]
10 | name = "pgrx_embed_wal_decoder"
11 | path = "./src/bin/pgrx_embed.rs"
12 |
13 | [features]
14 | default = ["pg13"]
15 | pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
16 | pg14 = ["pgrx/pg14", "pgrx-tests/pg14"]
17 | pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
18 | pg16 = ["pgrx/pg16", "pgrx-tests/pg16"]
19 | pg17 = ["pgrx/pg17", "pgrx-tests/pg17"]
20 | pg18 = ["pgrx/pg18", "pgrx-tests/pg18"]
21 | pg_test = []
22 |
23 | [dependencies]
24 | pgrx = { path = "../../pgrx", default-features = false }
25 | serde = "1.0.219"
26 | serde_json = "1.0.140"
27 |
28 | [dev-dependencies]
29 | pgrx-tests = { path = "../../pgrx-tests" }
30 |
31 | [profile.dev]
32 | panic = "unwind"
33 |
34 | [profile.release]
35 | panic = "unwind"
36 | opt-level = 3
37 | lto = "fat"
38 | codegen-units = 1
39 |
--------------------------------------------------------------------------------
/pgrx-examples/wal_decoder/src/bin/pgrx_embed.rs:
--------------------------------------------------------------------------------
1 | ::pgrx::pgrx_embed!();
2 |
--------------------------------------------------------------------------------
/pgrx-examples/wal_decoder/wal_decoder.control:
--------------------------------------------------------------------------------
1 | comment = 'wal_decoder: Created by pgrx'
2 | default_version = '@CARGO_VERSION@'
3 | module_pathname = 'wal_decoder'
4 | relocatable = false
5 | superuser = true
6 | trusted = false
7 |
--------------------------------------------------------------------------------
/pgrx-macros/Cargo.toml:
--------------------------------------------------------------------------------
1 | #LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | #LICENSE
3 | #LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | #LICENSE
5 | #LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | #LICENSE
7 | #LICENSE All rights reserved.
8 | #LICENSE
9 | #LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 |
11 | [package]
12 | name = "pgrx-macros"
13 | version = "0.14.3"
14 | authors = ["PgCentral Foundation, Inc. "]
15 | license = "MIT"
16 | description = "Proc Macros for 'pgrx'"
17 | homepage = "https://github.com/pgcentralfoundation/pgrx/"
18 | repository = "https://github.com/pgcentralfoundation/pgrx/"
19 | documentation = "https://docs.rs/pgrx-macros"
20 | readme = "README.md"
21 | edition = "2021"
22 |
23 | [lib]
24 | proc-macro = true
25 |
26 | [package.metadata.docs.rs]
27 | # Enable `#[cfg(docsrs)]` (https://docs.rs/about/builds#cross-compiling)
28 | rustc-args = ["--cfg", "docsrs"]
29 |
30 | [features]
31 | no-schema-generation = ["pgrx-sql-entity-graph/no-schema-generation"]
32 |
33 |
34 | [dependencies]
35 | pgrx-sql-entity-graph.workspace = true
36 |
37 | proc-macro2.workspace = true
38 | quote.workspace = true
39 | syn.workspace = true
40 |
41 |
42 | [dev-dependencies]
43 | serde.workspace = true # for Documentation examples
44 |
--------------------------------------------------------------------------------
/pgrx-macros/README.md:
--------------------------------------------------------------------------------
1 | # pgrx-macros
2 |
3 | Procedural macros for [`pgrx`](https://crates.io/crates/pgrx/).
4 |
5 | Provides:
6 |
7 | - #[pg_extern]
8 | - #[pg_guard]
9 | - #[pg_test]
10 | - #[derive(PostgresType)]
11 | - #[derive(PostgresEnum)]
12 | - #[derive(PostgresGucEnum)]
13 |
14 | Using `pgrx` as a dependency necessitates that `pgrx-macros` also be a dependency
--------------------------------------------------------------------------------
/pgrx-pg-config/Cargo.toml:
--------------------------------------------------------------------------------
1 | #LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | #LICENSE
3 | #LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | #LICENSE
5 | #LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | #LICENSE
7 | #LICENSE All rights reserved.
8 | #LICENSE
9 | #LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 |
11 | [package]
12 | name = "pgrx-pg-config"
13 | version = "0.14.3"
14 | authors = ["PgCentral Foundation, Inc. "]
15 | license = "MIT"
16 | description = "A Postgres pg_config wrapper for 'pgrx'"
17 | homepage = "https://github.com/pgcentralfoundation/pgrx/"
18 | repository = "https://github.com/pgcentralfoundation/pgrx/"
19 | documentation = "https://docs.rs/pgrx-pg-config"
20 | readme = "README.md"
21 | edition = "2021"
22 |
23 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
24 |
25 | [dependencies]
26 | cargo_toml.workspace = true
27 | eyre.workspace = true
28 | owo-colors.workspace = true
29 | serde.workspace = true
30 | serde_json.workspace = true
31 | thiserror.workspace = true
32 | toml.workspace = true
33 | url.workspace = true
34 |
35 | home = "0.5.11"
36 | pathsearch = "0.2.0"
37 |
--------------------------------------------------------------------------------
/pgrx-pg-config/README.md:
--------------------------------------------------------------------------------
1 | # pgrx-pg-config
2 |
3 | A crate containing an abstraction/wrapper over Postgres' `pg_config` to be used with [`pgrx`](https://crates.io/crates/pgrx/)
4 |
--------------------------------------------------------------------------------
/pgrx-pg-sys/README.md:
--------------------------------------------------------------------------------
1 | # pgrx-pg-sys
2 |
3 | Bindgen-generated bindings for [`pgrx`](https://crates.io/crates/pgrx/). Not meant to be used on its own.
4 |
--------------------------------------------------------------------------------
/pgrx-pg-sys/bindgen.rs:
--------------------------------------------------------------------------------
1 | // not a build.rs so that it doesn't inherit the git history of the build.rs
2 |
3 | // little-known Rust quirk: you can import main from wherever
4 | use pgrx_bindgen::build::main;
5 |
--------------------------------------------------------------------------------
/pgrx-pg-sys/pgrx-cshim.c:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 |
11 | #include "pgrx-cshim-static.c"
12 |
13 | void SpinLockInit__pgrx_cshim(volatile slock_t *lock) {
14 | SpinLockInit(lock);
15 | }
16 |
17 | void SpinLockAcquire__pgrx_cshim(volatile slock_t *lock) {
18 | SpinLockAcquire(lock);
19 | }
20 |
21 | void SpinLockRelease__pgrx_cshim(volatile slock_t *lock) {
22 | SpinLockRelease(lock);
23 | }
24 |
25 | bool SpinLockFree__pgrx_cshim(slock_t *lock) {
26 | return SpinLockFree(lock);
27 | }
28 |
29 | int call_closure_with_sigsetjmp(int savemask, void* closure_env_ptr, int (*closure_code)(sigjmp_buf jbuf, void *env_ptr)) {
30 | sigjmp_buf jbuf;
31 | int val;
32 | if (0 == (val = sigsetjmp(jbuf, savemask))) {
33 | return closure_code(jbuf, closure_env_ptr);
34 | } else {
35 | return val;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/pgrx-pg-sys/src/cshim.rs:
--------------------------------------------------------------------------------
1 | #![cfg(feature = "cshim")]
2 | #![allow(deprecated)]
3 |
4 | use crate as pg_sys;
5 |
6 | #[pgrx_macros::pg_guard]
7 | extern "C-unwind" {
8 | #[link_name = "SpinLockInit__pgrx_cshim"]
9 | pub fn SpinLockInit(lock: *mut pg_sys::slock_t);
10 | #[link_name = "SpinLockAcquire__pgrx_cshim"]
11 | pub fn SpinLockAcquire(lock: *mut pg_sys::slock_t);
12 | #[link_name = "SpinLockRelease__pgrx_cshim"]
13 | pub fn SpinLockRelease(lock: *mut pg_sys::slock_t);
14 | #[link_name = "SpinLockFree__pgrx_cshim"]
15 | pub fn SpinLockFree(lock: *mut pg_sys::slock_t) -> bool;
16 | }
17 |
--------------------------------------------------------------------------------
/pgrx-pg-sys/src/lib.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | #[cfg(
11 | // no features at all will cause problems
12 | not(any(feature = "pg13", feature = "pg14", feature = "pg15", feature = "pg16", feature = "pg17", feature = "pg18"))
13 | )]
14 | std::compile_error!("exactly one feature must be provided (pg13, pg14, pg15, pg16, pg17, pg18)");
15 |
16 | mod cshim;
17 | mod cstr;
18 | mod include;
19 | mod node;
20 | mod port;
21 | pub mod submodules;
22 |
23 | #[cfg(feature = "cshim")]
24 | pub use cshim::*;
25 |
26 | pub use cstr::AsPgCStr;
27 | pub use include::*;
28 | pub use node::PgNode;
29 | pub use port::*;
30 |
31 | // For postgres 18+, some functions will reexport when enabling `cshim` feature
32 | #[allow(ambiguous_glob_reexports)]
33 | pub use submodules::*;
34 |
35 | mod seal {
36 | pub trait Sealed {}
37 | }
38 |
39 | // Hack to fix linker errors that we get under amazonlinux2 on some PG versions
40 | // due to our wrappers for various system library functions. Should be fairly
41 | // harmless, but ideally we would not wrap these functions
42 | // (https://github.com/pgcentralfoundation/pgrx/issues/730).
43 | #[cfg(target_os = "linux")]
44 | #[link(name = "resolv")]
45 | extern "C" {}
46 |
--------------------------------------------------------------------------------
/pgrx-pg-sys/src/submodules/cmp.rs:
--------------------------------------------------------------------------------
1 | use crate::{Point, BOX};
2 |
3 | impl PartialEq for Point {
4 | #[inline]
5 | fn eq(&self, other: &Self) -> bool {
6 | self.x == other.x && self.y == other.y
7 | }
8 | }
9 | impl Eq for Point {}
10 |
11 | impl PartialEq for BOX {
12 | #[inline]
13 | fn eq(&self, other: &Self) -> bool {
14 | self.high == other.high && self.low == other.low
15 | }
16 | }
17 | impl Eq for BOX {}
18 |
--------------------------------------------------------------------------------
/pgrx-pg-sys/src/submodules/mod.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | pub mod datum;
11 | pub mod transaction_id;
12 | #[macro_use]
13 | pub mod elog;
14 | pub mod cmp;
15 | pub mod errcodes;
16 | pub mod ffi;
17 | pub mod htup;
18 | pub mod oids;
19 | pub mod panic;
20 | pub mod pg_try;
21 | #[doc(hidden)]
22 | pub mod thread_check;
23 | pub mod tupdesc;
24 |
25 | pub mod utils;
26 |
27 | // Various SqlTranslatable mappings for SQL generation
28 | mod sql_translatable;
29 |
30 | pub use datum::Datum;
31 | pub use transaction_id::{MultiXactId, TransactionId};
32 |
33 | pub use htup::*;
34 | pub use oids::*;
35 | pub use pg_try::*;
36 | pub use utils::*;
37 |
--------------------------------------------------------------------------------
/pgrx-pg-sys/src/submodules/tupdesc.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | //! Provides helper implementations for various `TupleDesc`-related structs
11 |
12 | use crate::oids::PgOid;
13 | use crate::utils::name_data_to_str;
14 |
15 | /// Helper implementation for `FormData_pg_attribute`
16 | impl crate::FormData_pg_attribute {
17 | pub fn name(&self) -> &str {
18 | name_data_to_str(&self.attname)
19 | }
20 |
21 | pub fn type_oid(&self) -> PgOid {
22 | PgOid::from(self.atttypid)
23 | }
24 |
25 | pub fn type_mod(&self) -> i32 {
26 | self.atttypmod
27 | }
28 |
29 | pub fn num(&self) -> i16 {
30 | self.attnum
31 | }
32 |
33 | pub fn is_dropped(&self) -> bool {
34 | self.attisdropped
35 | }
36 |
37 | pub fn rel_id(&self) -> crate::Oid {
38 | self.attrelid
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/pgrx-pg-sys/src/submodules/utils.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | //! General utility functions
11 | use crate as pg_sys;
12 |
13 | /// Converts a `pg_sys::NameData` struct into a `&str`.
14 | ///
15 | /// This is a zero-copy operation and the returned `&str` is tied to the lifetime
16 | /// of the provided `pg_sys::NameData`
17 | #[inline]
18 | pub fn name_data_to_str(name_data: &pg_sys::NameData) -> &str {
19 | unsafe { core::ffi::CStr::from_ptr(name_data.data.as_ptr()) }.to_str().unwrap()
20 | }
21 |
--------------------------------------------------------------------------------
/pgrx-sql-entity-graph/Cargo.toml:
--------------------------------------------------------------------------------
1 | #LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | #LICENSE
3 | #LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | #LICENSE
5 | #LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | #LICENSE
7 | #LICENSE All rights reserved.
8 | #LICENSE
9 | #LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 |
11 | [package]
12 | name = "pgrx-sql-entity-graph"
13 | version = "0.14.3"
14 | authors = ["PgCentral Foundation, Inc. "]
15 | license = "MIT"
16 | description = "Sql Entity Graph for `pgrx`"
17 | homepage = "https://github.com/pgcentralfoundation/pgrx/"
18 | repository = "https://github.com/pgcentralfoundation/pgrx/"
19 | documentation = "https://docs.rs/pgrx-sql-entity-graph"
20 | readme = "README.md"
21 | edition = "2021"
22 | include = ["src/**/*", "README.md"]
23 |
24 | [features]
25 | syntax-highlighting = ["dep:syntect", "dep:owo-colors"]
26 | no-schema-generation = []
27 |
28 | [dependencies]
29 | eyre.workspace = true
30 | proc-macro2.workspace = true
31 | quote.workspace = true
32 | syn.workspace = true
33 | thiserror.workspace = true
34 |
35 | convert_case = "0.8.0"
36 | petgraph = "0.8.1"
37 | unescape = "0.1.0" # for escaped-character-handling
38 |
39 | # colorized sql output
40 | owo-colors = { optional = true, workspace = true }
41 | syntect = { version = "5.2.0", default-features = false, features = ["default-fancy"], optional = true }
42 |
43 | [lints.clippy]
44 | assigning-clones = "allow" # wrong diagnosis and wrong suggestions
45 | too-many-arguments = "allow" # I argue with myself all the time
46 |
--------------------------------------------------------------------------------
/pgrx-sql-entity-graph/README.md:
--------------------------------------------------------------------------------
1 | # pgrx-sql-entity-graph
2 |
3 | Sql Entity Graph generation for [`pgrx`](https://crates.io/crates/pgrx/).
4 |
5 | This crate is used internally by various `pgrx` crates
--------------------------------------------------------------------------------
/pgrx-sql-entity-graph/src/composite_type.rs:
--------------------------------------------------------------------------------
1 | /// Innards of a `composite_type!`
2 | ///
3 | /// For SQL generation and further expansion.
4 | /// Use this so you don't drop the span on the floor.
5 | #[derive(Debug, Clone)]
6 | pub struct CompositeTypeMacro {
7 | pub(crate) lifetime: Option,
8 | pub(crate) expr: syn::Expr,
9 | pub(crate) span: proc_macro2::Span,
10 | }
11 |
12 | impl syn::parse::Parse for CompositeTypeMacro {
13 | fn parse(input: syn::parse::ParseStream) -> Result {
14 | let span = input.span();
15 | let lifetime: Option = input.parse().ok();
16 | let _comma: Option = input.parse().ok();
17 | let expr = input.parse()?;
18 | Ok(Self { lifetime, expr, span })
19 | }
20 | }
21 |
22 | /// Take a `composite_type!` from a macro
23 | pub fn handle_composite_type_macro(mac: &syn::Macro) -> syn::Result {
24 | let out: CompositeTypeMacro = mac.parse_body()?;
25 | Ok(out)
26 | }
27 |
28 | impl CompositeTypeMacro {
29 | /// Expands into the implementing type, explicitly eliding the lifetime
30 | /// if none is actually given.
31 | pub fn expand_with_lifetime(&self) -> syn::Type {
32 | let CompositeTypeMacro { lifetime, span, .. } = self.clone();
33 | let lifetime = lifetime.unwrap_or_else(|| syn::Lifetime::new("'_", span));
34 | syn::parse_quote! {
35 | ::pgrx::heap_tuple::PgHeapTuple<#lifetime, ::pgrx::pgbox::AllocatedByRust>
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/pgrx-sql-entity-graph/src/enrich.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | use proc_macro2::TokenStream as TokenStream2;
11 | use quote::{quote, ToTokens, TokenStreamExt};
12 |
13 | pub struct CodeEnrichment(pub T);
14 |
15 | /// Generates the rust code that pgrx requires for one of its SQL interfaces such as `#[pg_extern]`
16 | pub trait ToRustCodeTokens {
17 | fn to_rust_code_tokens(&self) -> TokenStream2 {
18 | quote! {}
19 | }
20 | }
21 |
22 | /// Generates the rust code to tie one of pgrx' supported SQL interfaces into pgrx' schema generator
23 | pub trait ToEntityGraphTokens {
24 | fn to_entity_graph_tokens(&self) -> TokenStream2;
25 | }
26 |
27 | impl ToTokens for CodeEnrichment
28 | where
29 | T: ToEntityGraphTokens + ToRustCodeTokens,
30 | {
31 | fn to_tokens(&self, tokens: &mut TokenStream2) {
32 | #[cfg(not(feature = "no-schema-generation"))]
33 | {
34 | // only emit entity graph tokens when we're generating a schema, which is our default mode
35 | tokens.append_all(self.0.to_entity_graph_tokens());
36 | }
37 |
38 | tokens.append_all(self.0.to_rust_code_tokens());
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/pgrx-sql-entity-graph/src/finfo.rs:
--------------------------------------------------------------------------------
1 | use proc_macro2::{Ident, TokenStream};
2 | use quote::{format_ident, quote, quote_spanned};
3 | use syn::{self, spanned::Spanned, ItemFn};
4 |
5 | /// Generate the Postgres fn info record
6 | ///
7 | /// Equivalent to PG_FUNCTION_INFO_V1, Postgres will sprintf the fn ident, then `dlsym(so, expected_name)`,
8 | /// so it is important to pass exactly the ident that you want to have the record associated with!
9 | pub fn finfo_v1_tokens(ident: proc_macro2::Ident) -> syn::Result {
10 | let finfo_name = format_ident!("pg_finfo_{ident}");
11 | let tokens = quote! {
12 | #[no_mangle]
13 | #[doc(hidden)]
14 | pub extern "C" fn #finfo_name() -> &'static ::pgrx::pg_sys::Pg_finfo_record {
15 | const V1_API: ::pgrx::pg_sys::Pg_finfo_record = ::pgrx::pg_sys::Pg_finfo_record { api_version: 1 };
16 | &V1_API
17 | }
18 | };
19 | syn::parse2(tokens)
20 | }
21 |
22 | pub fn finfo_v1_extern_c(
23 | original: &syn::ItemFn,
24 | fcinfo: Ident,
25 | contents: TokenStream,
26 | ) -> syn::Result {
27 | let original_name = &original.sig.ident;
28 | let wrapper_symbol = format_ident!("{}_wrapper", original_name);
29 |
30 | let synthetic = proc_macro2::Span::mixed_site();
31 | let synthetic = synthetic.located_at(original.sig.span());
32 |
33 | let tokens = quote_spanned! { synthetic =>
34 | #[no_mangle]
35 | #[doc(hidden)]
36 | pub unsafe extern "C-unwind" fn #wrapper_symbol(#fcinfo: ::pgrx::pg_sys::FunctionCallInfo) -> ::pgrx::pg_sys::Datum {
37 | #contents
38 | }
39 | };
40 |
41 | syn::parse2(tokens)
42 | }
43 |
--------------------------------------------------------------------------------
/pgrx-sql-entity-graph/src/fmt.rs:
--------------------------------------------------------------------------------
1 | /// Evaluate an expression that resolves to any `impl ToTokens`, then produce a closure
2 | /// for lazily combining errors only on the unhappy path of `syn::Result`
3 | macro_rules! lazy_err {
4 | ($span_expr:expr, $lit:literal $(, $tokens:tt),*) => {
5 | {
6 | let spanning = $span_expr;
7 | || ::syn::Error::new_spanned(spanning, format!($lit, $($tokens)*))
8 | }
9 | }
10 | }
11 |
12 | pub fn with_array_brackets(s: String, brackets: bool) -> String {
13 | s + if brackets { "[]" } else { "" }
14 | }
15 |
16 | pub(crate) trait ErrHarder {
17 | fn more_error(self, closerr: impl FnOnce() -> syn::Error) -> Self;
18 | }
19 |
20 | impl ErrHarder for syn::Result {
21 | fn more_error(self, closerr: impl FnOnce() -> syn::Error) -> Self {
22 | self.map_err(|inner| {
23 | let mut e = inner.clone();
24 | e.combine(closerr());
25 | e
26 | })
27 | }
28 | }
29 |
30 | impl ErrHarder for syn::Error {
31 | fn more_error(mut self, closerr: impl FnOnce() -> syn::Error) -> Self {
32 | self.combine(closerr());
33 | self
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/pgrx-sql-entity-graph/src/metadata/entity.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | /*!
11 |
12 | Function and type level metadata entities for Rust to SQL translation
13 |
14 | > Like all of the [`sql_entity_graph`][crate] APIs, this is considered **internal**
15 | > to the `pgrx` framework and very subject to change between versions. While you may use this, please do it with caution.
16 |
17 |
18 | */
19 | use super::{ArgumentError, Returns, ReturnsError, SqlMapping};
20 |
21 | #[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
22 | pub struct FunctionMetadataEntity {
23 | pub arguments: Vec,
24 | pub retval: FunctionMetadataTypeEntity,
25 | pub path: &'static str,
26 | }
27 |
28 | #[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
29 | pub struct FunctionMetadataTypeEntity {
30 | pub type_name: &'static str,
31 | pub argument_sql: Result,
32 | pub return_sql: Result,
33 | pub variadic: bool,
34 | pub optional: bool,
35 | }
36 |
--------------------------------------------------------------------------------
/pgrx-sql-entity-graph/src/metadata/mod.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | /*!
11 |
12 | Function and type level metadata for Rust to SQL translation
13 |
14 | > Like all of the [`sql_entity_graph`][crate] APIs, this is considered **internal**
15 | > to the `pgrx` framework and very subject to change between versions. While you may use this, please do it with caution.
16 |
17 |
18 | */
19 |
20 | mod entity;
21 | mod function_metadata;
22 | mod return_variant;
23 | mod sql_translatable;
24 |
25 | pub use entity::{FunctionMetadataEntity, FunctionMetadataTypeEntity};
26 | pub use function_metadata::FunctionMetadata;
27 | pub use return_variant::{Returns, ReturnsError};
28 | pub use sql_translatable::{ArgumentError, SqlMapping, SqlTranslatable};
29 |
--------------------------------------------------------------------------------
/pgrx-sql-entity-graph/src/pg_extern/entity/argument.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | /*!
11 |
12 | `#[pg_extern]` related argument entities for Rust to SQL translation
13 |
14 | > Like all of the [`sql_entity_graph`][crate] APIs, this is considered **internal**
15 | > to the `pgrx` framework and very subject to change between versions. While you may use this, please do it with caution.
16 |
17 | */
18 | use crate::{SqlGraphIdentifier, UsedTypeEntity};
19 |
20 | /// The output of a [`PgExternArgument`](crate::PgExternArgument) from `quote::ToTokens::to_tokens`.
21 | #[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
22 | pub struct PgExternArgumentEntity {
23 | pub pattern: &'static str,
24 | pub used_ty: UsedTypeEntity,
25 | }
26 |
27 | impl SqlGraphIdentifier for PgExternArgumentEntity {
28 | fn dot_identifier(&self) -> String {
29 | format!("arg {}", self.rust_identifier())
30 | }
31 | fn rust_identifier(&self) -> String {
32 | self.used_ty.full_path.to_string()
33 | }
34 |
35 | fn file(&self) -> Option<&'static str> {
36 | None
37 | }
38 |
39 | fn line(&self) -> Option {
40 | None
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/pgrx-sql-entity-graph/src/pg_extern/entity/cast.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | /*!
11 |
12 | `#[pg_extern]` related cast entities for Rust to SQL translation
13 |
14 | > Like all of the [`sql_entity_graph`][crate] APIs, this is considered **internal**
15 | > to the `pgrx` framework and very subject to change between versions. While you may use this, please do it with caution.
16 |
17 | */
18 |
19 | /// The output of a [`PgCast`](crate::PgCast) from `quote::ToTokens::to_tokens`.
20 | #[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
21 | pub enum PgCastEntity {
22 | Default,
23 | Assignment,
24 | Implicit,
25 | }
26 |
--------------------------------------------------------------------------------
/pgrx-sql-entity-graph/src/pg_extern/entity/operator.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | /*!
11 |
12 | `#[pg_extern]` related operator entities for Rust to SQL translation
13 |
14 | > Like all of the [`sql_entity_graph`][crate] APIs, this is considered **internal**
15 | > to the `pgrx` framework and very subject to change between versions. While you may use this, please do it with caution.
16 |
17 | */
18 |
19 | /// The output of a [`PgOperator`](crate::PgOperator) from `quote::ToTokens::to_tokens`.
20 | #[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
21 | pub struct PgOperatorEntity {
22 | pub opname: Option<&'static str>,
23 | pub commutator: Option<&'static str>,
24 | pub negator: Option<&'static str>,
25 | pub restrict: Option<&'static str>,
26 | pub join: Option<&'static str>,
27 | pub hashes: bool,
28 | pub merges: bool,
29 | }
30 |
--------------------------------------------------------------------------------
/pgrx-sql-entity-graph/src/pg_extern/entity/returning.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | /*!
11 |
12 | `#[pg_extern]` related return value entities for Rust to SQL translation
13 |
14 | > Like all of the [`sql_entity_graph`][crate] APIs, this is considered **internal**
15 | > to the `pgrx` framework and very subject to change between versions. While you may use this, please do it with caution.
16 |
17 | */
18 | use crate::UsedTypeEntity;
19 |
20 | #[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
21 | pub enum PgExternReturnEntity {
22 | None,
23 | Type { ty: UsedTypeEntity },
24 | SetOf { ty: UsedTypeEntity },
25 | Iterated { tys: Vec },
26 | Trigger,
27 | }
28 |
29 | #[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
30 | pub struct PgExternReturnEntityIteratedItem {
31 | pub ty: UsedTypeEntity,
32 | pub name: Option<&'static str>,
33 | }
34 |
--------------------------------------------------------------------------------
/pgrx-tests/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea/
3 | target/
4 | *.iml
5 | **/*.rs.bk
6 | Cargo.lock
7 | sql/pgrx_tests-1.0.sql
8 |
--------------------------------------------------------------------------------
/pgrx-tests/README.md:
--------------------------------------------------------------------------------
1 | # pgrx-tests
2 |
3 | Test framework for [`pgrx`](https://crates.io/crates/pgrx/).
4 |
5 | Meant to be used as one of your `[dev-dependencies]` when using `pgrx`.
--------------------------------------------------------------------------------
/pgrx-tests/pgrx_tests.control:
--------------------------------------------------------------------------------
1 | comment = 'tests: Created by pgrx'
2 | default_version = '1.0'
3 | module_pathname = 'pgrx_tests'
4 | relocatable = false
5 | superuser = false
6 |
--------------------------------------------------------------------------------
/pgrx-tests/src/bin/pgrx_embed.rs:
--------------------------------------------------------------------------------
1 | ::pgrx::pgrx_embed!();
2 |
--------------------------------------------------------------------------------
/pgrx-tests/src/lib.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 |
11 | #![cfg_attr(feature = "nightly", feature(allocator_api))]
12 |
13 | mod framework;
14 | #[cfg(any(test, feature = "pg_test"))]
15 | mod tests;
16 |
17 | pub use framework::*;
18 | #[cfg(feature = "proptest")]
19 | pub mod proptest;
20 |
21 | #[cfg(any(test, feature = "pg_test"))]
22 | pgrx::pg_module_magic!();
23 |
24 | #[cfg(test)]
25 | pub mod pg_test {
26 | pub fn setup(_options: Vec<&str>) {
27 | // noop
28 | }
29 |
30 | pub fn postgresql_conf_options() -> Vec<&'static str> {
31 | vec!["shared_preload_libraries='pgrx_tests'"]
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/pgrx-tests/src/tests/anyelement_tests.rs:
--------------------------------------------------------------------------------
1 | use pgrx::{prelude::*, AnyElement};
2 |
3 | #[pg_extern]
4 | fn anyelement_arg(element: AnyElement) -> AnyElement {
5 | element
6 | }
7 |
8 | #[cfg(any(test, feature = "pg_test"))]
9 | #[pgrx::pg_schema]
10 | mod tests {
11 | #[allow(unused_imports)]
12 | use crate as pgrx_tests;
13 |
14 | use pgrx::{datum::DatumWithOid, prelude::*, AnyElement};
15 |
16 | #[pg_test]
17 | fn test_anyelement_arg() -> Result<(), pgrx::spi::Error> {
18 | let element = Spi::get_one_with_args::("SELECT anyelement_arg($1);", unsafe {
19 | &[DatumWithOid::new(123, AnyElement::type_oid())]
20 | })?
21 | .map(|e| e.datum());
22 |
23 | assert_eq!(element, 123.into_datum());
24 |
25 | Ok(())
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/pgrx-tests/src/tests/anynumeric_tests.rs:
--------------------------------------------------------------------------------
1 | use pgrx::{prelude::*, AnyNumeric};
2 |
3 | #[pg_extern]
4 | fn anynumeric_arg(numeric: AnyNumeric) -> AnyNumeric {
5 | numeric
6 | }
7 |
8 | #[cfg(any(test, feature = "pg_test"))]
9 | #[pgrx::pg_schema]
10 | mod tests {
11 | #[allow(unused_imports)]
12 | use crate as pgrx_tests;
13 |
14 | use pgrx::{prelude::*, AnyNumeric};
15 |
16 | #[pg_test]
17 | fn test_anynumeric_arg() -> Result<(), pgrx::spi::Error> {
18 | let numeric =
19 | Spi::get_one_with_args::("SELECT anynumeric_arg($1);", &[123.into()])?
20 | .map(|n| n.normalize().to_string());
21 |
22 | assert_eq!(numeric, Some("123".to_string()));
23 |
24 | Ok(())
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/pgrx-tests/src/tests/attributes_tests.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | #[cfg(any(test, feature = "pg_test"))]
11 | #[pgrx::pg_schema]
12 | mod tests {
13 | #[allow(unused_imports)]
14 | use crate as pgrx_tests;
15 |
16 | use pgrx::prelude::*;
17 |
18 | #[pg_test]
19 | #[ignore = "This test should be ignored."]
20 | fn test_for_ignore_attribute() {
21 | assert_eq!(true, false);
22 | }
23 |
24 | #[pg_test]
25 | #[should_panic(expected = "I should panic")]
26 | fn test_for_should_panic_attribute() {
27 | assert_eq!(1, 2, "I should panic");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/pgrx-tests/src/tests/bindings_of_inline_fn_tests.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | #[cfg(any(test, feature = "pg_test"))]
11 | #[pgrx::pg_schema]
12 | mod tests {
13 | #[allow(unused_imports)]
14 | use crate as pgrx_tests;
15 |
16 | use pgrx::prelude::*;
17 |
18 | #[pg_test]
19 | fn test_static_inline_fns() {
20 | unsafe {
21 | use pgrx::pg_sys::{itemptr_encode, BlockIdData, ItemPointerData};
22 | assert_eq!(
23 | itemptr_encode(&mut ItemPointerData {
24 | ip_blkid: BlockIdData { bi_hi: 111, bi_lo: 222 },
25 | ip_posid: 333
26 | }),
27 | 476755919181
28 | );
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/pgrx-tests/src/tests/cfg_tests.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | #![allow(unexpected_cfgs)]
11 | use pgrx::prelude::*;
12 |
13 | #[cfg(any(test, feature = "pg_test"))]
14 | #[pg_extern]
15 | fn func_test_cfg() {}
16 |
17 | #[cfg(feature = "nonexistent")]
18 | #[pg_extern]
19 | fn func_non_existent_cfg(t: NonexistentType) {}
20 |
21 | #[cfg(any(test, feature = "pg_test"))]
22 | #[pgrx::pg_schema]
23 | mod tests {
24 | #[allow(unused_imports)]
25 | use crate as pgrx_tests;
26 |
27 | use pgrx::prelude::*;
28 |
29 | #[pg_test]
30 | fn test_cfg_exists() -> Result<(), spi::Error> {
31 | Spi::run("SELECT func_test_cfg();")
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/pgrx-tests/src/tests/composite_type_tests.rs:
--------------------------------------------------------------------------------
1 | use pgrx::prelude::*;
2 |
3 | extension_sql!(
4 | r#"
5 | CREATE TYPE entity AS (id INT, lang TEXT);
6 | CREATE TYPE result AS (score DOUBLE PRECISION, entities entity[]);
7 | "#,
8 | name = "issue1293"
9 | );
10 |
11 | #[pg_extern(requires = ["issue1293"])]
12 | fn create_result() -> pgrx::composite_type!('static, "result") {
13 | let mut record = PgHeapTuple::new_composite_type("result").unwrap();
14 | record.set_by_name("score", 0.707).unwrap();
15 | let mut entity_records: Vec = Vec::new();
16 | for i in 0..10 {
17 | let mut entity_record = PgHeapTuple::new_composite_type("entity").unwrap();
18 | entity_record.set_by_name("id", i).unwrap();
19 | entity_record.set_by_name("lang", "en".to_string()).unwrap();
20 | entity_records.push(entity_record);
21 | }
22 | record.set_by_name("entities", entity_records).unwrap();
23 | return record;
24 | }
25 |
26 | #[cfg(any(test, feature = "pg_test"))]
27 | #[pgrx::pg_schema]
28 | mod tests {
29 | use pgrx::prelude::*;
30 |
31 | #[allow(unused_imports)]
32 | use crate as pgrx_tests;
33 |
34 | #[pg_test]
35 | fn test_array_of_composite_type() {
36 | Spi::get_one::("SELECT create_result() is not null")
37 | .expect("SPI failed")
38 | .expect("failed to create `result` composite type'");
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/pgrx-tests/src/tests/derive_pgtype_lifetimes.rs:
--------------------------------------------------------------------------------
1 | //LICENSE Portions Copyright 2019-2021 ZomboDB, LLC.
2 | //LICENSE
3 | //LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc.
4 | //LICENSE
5 | //LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc.
6 | //LICENSE
7 | //LICENSE All rights reserved.
8 | //LICENSE
9 | //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
10 | #![allow(dead_code)]
11 | /// the purpose of this test is to just make sure this code compiles!
12 | use pgrx::prelude::*;
13 | use serde::*;
14 |
15 | fn foo<'a>(_s: Vec