Skip to content

Commit 8ce52ff

Browse files
committed
Separate filter functionality from builder.rs
1 parent 4774bb1 commit 8ce52ff

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

src/builder.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,12 @@ use reqwest::{
33
Client, Error, Method, Response,
44
};
55

6-
macro_rules! filter {
7-
( $( $op:ident ),* ) => {
8-
$(
9-
pub fn $op(mut self, column: &str, param: &str) -> Self {
10-
self.queries.push((column.to_string(),
11-
format!("{}.{}", stringify!($op), param)));
12-
self
13-
}
14-
)*
15-
}
16-
}
17-
186
#[derive(Default)]
197
pub struct Builder {
208
method: Method,
219
url: String,
2210
schema: Option<String>,
23-
queries: Vec<(String, String)>,
11+
pub(crate) queries: Vec<(String, String)>,
2412
headers: HeaderMap,
2513
body: Option<String>,
2614
is_rpc: bool,
@@ -150,19 +138,6 @@ impl Builder {
150138
self
151139
}
152140

153-
// It's unfortunate that `in` is a keyword, otherwise it'd belong in the
154-
// collection of filters below
155-
filter!(
156-
eq, gt, gte, lt, lte, neq, like, ilike, is, fts, plfts, phfts, wfts, cs, cd, ov, sl, sr,
157-
nxr, nxl, adj, not
158-
);
159-
160-
pub fn in_(mut self, column: &str, param: &str) -> Self {
161-
self.queries
162-
.push((column.to_string(), format!("in.{}", param)));
163-
self
164-
}
165-
166141
pub fn rpc(mut self, params: &str) -> Self {
167142
self.method = Method::POST;
168143
self.body = Some(params.to_string());

src/filter.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use crate::Builder;
2+
3+
macro_rules! filter {
4+
( $( $op:ident ),* ) => {
5+
$(
6+
pub fn $op(mut self, column: &str, param: &str) -> Self {
7+
self.queries.push((column.to_string(),
8+
format!("{}.{}", stringify!($op), param)));
9+
self
10+
}
11+
)*
12+
}
13+
}
14+
15+
impl Builder {
16+
// It's unfortunate that `in` is a keyword, otherwise it'd belong in the
17+
// collection of filters below
18+
filter!(
19+
eq, gt, gte, lt, lte, neq, like, ilike, is, fts, plfts, phfts, wfts, cs, cd, ov, sl, sr,
20+
nxr, nxl, adj, not
21+
);
22+
23+
pub fn in_(mut self, column: &str, param: &str) -> Self {
24+
self.queries
25+
.push((column.to_string(), format!("in.{}", param)));
26+
self
27+
}
28+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod builder;
2+
mod filter;
23

34
use builder::Builder;
45

0 commit comments

Comments
 (0)