Skip to content

Commit 7adcb0b

Browse files
authored
Merge pull request #145 from supabase/fix/doc-tests
fix: doc test compilation errors
2 parents fbab881 + 2866e55 commit 7adcb0b

File tree

5 files changed

+109
-9
lines changed

5 files changed

+109
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Test Wrappers
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
test:
10+
name: Run supabase_wrappers tests
11+
runs-on: ubuntu-20.04
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- uses: actions-rs/toolchain@v1
18+
with:
19+
toolchain: stable
20+
21+
- run: |
22+
sudo apt remove -y postgres*
23+
sudo apt-get install -y wget gnupg
24+
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
25+
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
26+
sudo apt-get update -y -qq --fix-missing
27+
sudo apt-get install -y \
28+
clang-10 \
29+
llvm-10 \
30+
clang \
31+
gcc \
32+
make \
33+
build-essential \
34+
libz-dev \
35+
zlib1g-dev \
36+
strace \
37+
libssl-dev \
38+
pkg-config \
39+
postgresql-15 \
40+
postgresql-server-dev-15
41+
sudo chmod a+rwx `/usr/lib/postgresql/15/bin/pg_config --pkglibdir` `/usr/lib/postgresql/15/bin/pg_config --sharedir`/extension /var/run/postgresql/
42+
43+
- run: cargo install cargo-pgrx --version 0.9.8
44+
- run: cargo pgrx init --pg15 /usr/lib/postgresql/15/bin/pg_config
45+
- run: cd supabase-wrappers && cargo test

.github/workflows/test_wrappers.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
test:
10-
name: Run tests
10+
name: Run wrappers tests
1111
runs-on: ubuntu-20.04
1212

1313
steps:

supabase-wrappers/src/interface.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -628,18 +628,23 @@ pub trait ForeignDataWrapper {
628628
/// # Example
629629
///
630630
/// ```rust,no_run
631+
/// use pgrx::pg_sys::Oid;
632+
/// use supabase_wrappers::prelude::check_options_contain;
633+
///
631634
/// fn validator(opt_list: Vec<Option<String>>, catalog: Option<Oid>) {
632635
/// if let Some(oid) = catalog {
633636
/// match oid {
634637
/// FOREIGN_DATA_WRAPPER_RELATION_ID => {
635638
/// // check a required option when create foreign data wrapper
636-
/// check_options_contain(&opt_list, "required_option");
639+
/// check_options_contain(&opt_list, "foreign_data_wrapper_required_option");
637640
/// }
638641
/// FOREIGN_SERVER_RELATION_ID => {
639642
/// // check option here when create server
643+
/// check_options_contain(&opt_list, "foreign_server_required_option");
640644
/// }
641645
/// FOREIGN_TABLE_RELATION_ID => {
642646
/// // check option here when create foreign table
647+
/// check_options_contain(&opt_list, "foreign_table_required_option");
643648
/// }
644649
/// _ => {}
645650
/// }

supabase-wrappers/src/lib.rs

+35-3
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@
6060
//! The FDW implements [`interface::ForeignDataWrapper`] trait must use [`wrappers_fdw`] macro and implement a `new()` initialization function. For example,
6161
//!
6262
//! ```rust,no_run
63+
//! # mod wrapper {
64+
//! use std::collections::HashMap;
6365
//! use supabase_wrappers::prelude::*;
64-
//!
6566
//! #[wrappers_fdw(
6667
//! version = "0.1.0",
6768
//! author = "Supabase",
@@ -76,7 +77,7 @@
7677
//! }
7778
//!
7879
//! impl ForeignDataWrapper for HelloWorldFdw {
79-
//! pub fn new(options: &HashMap<String, String>) -> Self {
80+
//! fn new(options: &HashMap<String, String>) -> Self {
8081
//! // 'options' is the key-value pairs defined in `CREATE SERVER` SQL, for example,
8182
//! //
8283
//! // create server my_helloworld_server
@@ -95,7 +96,21 @@
9596
//! tgt_cols: Vec::new(),
9697
//! }
9798
//! }
99+
//!
100+
//! fn begin_scan(&mut self, quals: &[Qual], columns: &[Column], sorts: &[Sort], limit: &Option<Limit>, options: &HashMap<String, String>) {
101+
//! // Do any initilization
102+
//! }
103+
//!
104+
//! fn iter_scan(&mut self, row: &mut Row) -> Option<()> {
105+
//! // Return None when done
106+
//! None
107+
//! }
108+
//!
109+
//! fn end_scan(&mut self) {
110+
//! // Cleanup any resources
111+
//! }
98112
//! }
113+
//! # }
99114
//! ```
100115
//!
101116
//! To develop a simple FDW supports basic query `SELECT`, you need to implement `begin_scan`, `iter_scan` and `end_scan`.
@@ -120,7 +135,24 @@
120135
//! Then we can implement [`interface::ForeignDataWrapper`] trait like below,
121136
//!
122137
//! ```rust,no_run
138+
//! use std::collections::HashMap;
139+
//! use supabase_wrappers::prelude::*;
140+
//!
141+
//! pub(crate) struct HelloWorldFdw {
142+
//! // row counter
143+
//! row_cnt: i64,
144+
//!
145+
//! // target column name list
146+
//! tgt_cols: Vec<Column>,
147+
//! }
123148
//! impl ForeignDataWrapper for HelloWorldFdw {
149+
//! fn new(options: &HashMap<String, String>) -> Self {
150+
//! Self {
151+
//! row_cnt: 0,
152+
//! tgt_cols: Vec::new(),
153+
//! }
154+
//! }
155+
//!
124156
//! fn begin_scan(
125157
//! &mut self,
126158
//! _quals: &[Qual],
@@ -141,7 +173,7 @@
141173
//! if self.row_cnt < 1 {
142174
//! // add values to row if they are in target column list
143175
//! for tgt_col in &self.tgt_cols {
144-
//! match tgt_col.as_str() {
176+
//! match tgt_col.name.as_str() {
145177
//! "id" => row.push("id", Some(Cell::I64(self.row_cnt))),
146178
//! "col" => row.push("col", Some(Cell::String("Hello world".to_string()))),
147179
//! _ => {}

supabase-wrappers/src/utils.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub fn log_debug1(msg: &str) {
3232
/// For example,
3333
///
3434
/// ```rust,no_run
35+
/// # use supabase_wrappers::prelude::report_info;
3536
/// report_info(&format!("this is an info"));
3637
/// ```
3738
#[inline]
@@ -51,6 +52,7 @@ pub fn report_info(msg: &str) {
5152
/// For example,
5253
///
5354
/// ```rust,no_run
55+
/// # use supabase_wrappers::prelude::report_notice;
5456
/// report_notice(&format!("this is a notice"));
5557
/// ```
5658
#[inline]
@@ -70,6 +72,7 @@ pub fn report_notice(msg: &str) {
7072
/// For example,
7173
///
7274
/// ```rust,no_run
75+
/// # use supabase_wrappers::prelude::report_warning;
7376
/// report_warning(&format!("this is a warning"));
7477
/// ```
7578
#[inline]
@@ -90,6 +93,7 @@ pub fn report_warning(msg: &str) {
9093
/// For example,
9194
///
9295
/// ```rust,no_run
96+
/// # use supabase_wrappers::prelude::report_error;
9397
/// use pgrx::prelude::PgSqlErrorCode;
9498
///
9599
/// report_error(
@@ -111,12 +115,20 @@ pub fn report_error(code: PgSqlErrorCode, msg: &str) {
111115
/// For example,
112116
///
113117
/// ```rust,no_run
118+
/// # use supabase_wrappers::prelude::create_async_runtime;
119+
/// # struct Client {
120+
/// # }
121+
/// # impl Client {
122+
/// # async fn query(&self, _sql: &str) -> Result<(), ()> { Ok(()) }
123+
/// # }
124+
/// # let client = Client {};
125+
/// # let sql = "";
114126
/// let rt = create_async_runtime();
115127
///
116-
/// // client.query() is an async function
128+
/// // client.query() is an async function returning a Result
117129
/// match rt.block_on(client.query(&sql)) {
118-
/// Ok(result) => {...}
119-
/// Err(err) => {...}
130+
/// Ok(result) => { }
131+
/// Err(err) => { }
120132
/// }
121133
/// ```
122134
#[inline]
@@ -132,6 +144,9 @@ pub fn create_async_runtime() -> Runtime {
132144
/// For example,
133145
///
134146
/// ```rust,no_run
147+
/// # use supabase_wrappers::prelude::require_option;
148+
/// # use std::collections::HashMap;
149+
/// # let options = &HashMap::new();
135150
/// require_option("my_option", options);
136151
/// ```
137152
pub fn require_option(opt_name: &str, options: &HashMap<String, String>) -> Option<String> {
@@ -151,7 +166,10 @@ pub fn require_option(opt_name: &str, options: &HashMap<String, String>) -> Opti
151166
/// For example,
152167
///
153168
/// ```rust,no_run
154-
/// require_option_or("my_option", options, "default value");
169+
/// # use supabase_wrappers::prelude::require_option_or;
170+
/// # use std::collections::HashMap;
171+
/// # let options = &HashMap::new();
172+
/// require_option_or("my_option", options, "default value".to_string());
155173
/// ```
156174
pub fn require_option_or(
157175
opt_name: &str,

0 commit comments

Comments
 (0)