https://github.com/drowzy/pgx_fdw
https://github.com/drowzy/pgx_fdw
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/drowzy/pgx_fdw
- Owner: drowzy
- Created: 2021-02-06T18:22:31.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-10T10:14:57.000Z (about 5 years ago)
- Last Synced: 2025-03-23T01:05:37.448Z (about 1 year ago)
- Language: Rust
- Size: 21.5 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pgx-fdw
Experimental [Foreign Data Wrapper](https://www.postgresql.org/docs/13/fdwhandler.html) support for [pgx](https://github.com/zombodb/pgx).
## Implementing a FDW
1. Impl the trait `pgx_fdw::ForeignData`
```rust
struct MyFdw {}
impl pgx_fdw::ForeignData for MyFdw {
...
}
```
2. Create handler function
```rust
/// ```sql
/// CREATE FUNCTION my_handler() RETURNS fdw_handler LANGUAGE c AS 'MODULE_PATHNAME', 'my_handler_wrapper';
/// ```
#[pg_extern]
fn my_handler() -> pg_sys::Datum {
pgx_fdw::FdwState::::into_datum()
}
```
3. Create wrapper + server
```sql
CREATE FOREIGN DATA WRAPPER my_handler handler my_handler NO VALIDATOR;
CREATE SERVER my_fdw_srv FOREIGN DATA WRAPPER my_handler OPTIONS (server_option '1', server_option '2');
CREATE FOREIGN TABLE users (
id text,
name text,
email text
) SERVER my_fdw_server OPTIONS (
table_option '1',
table_option2 '2'
);
```
## Examples
* `inmem_table` - Simple in-memory table fdw using `Vec`