Skip to content

Commit eb4036d

Browse files
authored
feat: foreign table limit (#47)
* foreign table limit * add test * cargo fmt, cargo clippy, and cargo nextest
1 parent 24af800 commit eb4036d

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ reqwest = { version = "0.11", default-features = false, features = ["rustls-tls"
1616

1717
[dev-dependencies]
1818
json = "0.12"
19-
tokio = { version = "1.5", features = ["full"] }
19+
tokio = { version = "1", features = ["full"] }

src/builder.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,28 @@ impl<'a> Builder<'a> {
202202
self
203203
}
204204

205+
/// Limits the result of a foreign table with the specified `count`.
206+
///
207+
/// # Example
208+
///
209+
/// ```
210+
/// use postgrest::Postgrest;
211+
///
212+
/// let client = Postgrest::new("https://your.postgrest.endpoint");
213+
/// client
214+
/// .from("countries")
215+
/// .select("name, cities(name)")
216+
/// .foreign_table_limit(1, "cities");
217+
/// ```
218+
pub fn foreign_table_limit<T>(mut self, count: usize, foreign_table: T) -> Self
219+
where
220+
T: Into<String>,
221+
{
222+
self.queries
223+
.push((format!("{}.limit", foreign_table.into()), count.to_string()));
224+
self
225+
}
226+
205227
/// Limits the result to rows within the specified range, inclusive.
206228
///
207229
/// # Example
@@ -545,6 +567,19 @@ mod tests {
545567
);
546568
}
547569

570+
#[test]
571+
fn foreign_table_limit_assert_query() {
572+
let client = Client::new();
573+
let builder = Builder::new(TABLE_URL, None, HeaderMap::new(), &client)
574+
.foreign_table_limit(20, "some_table");
575+
assert_eq!(
576+
builder
577+
.queries
578+
.contains(&("some_table.limit".to_string(), "20".to_string())),
579+
true
580+
);
581+
}
582+
548583
#[test]
549584
fn range_assert_range_header() {
550585
let client = Client::new();

0 commit comments

Comments
 (0)