Skip to content

Commit 7b83d20

Browse files
committed
fixup! feat(query): Fetch query response in JSON format.
Rename to `fetch_json`.
1 parent 684c2ce commit 7b83d20

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/query.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Query {
8787

8888
/// Executes the query, returning a [`RowJsonCursor`] to obtain results.
8989
#[cfg(feature = "watch")]
90-
pub fn json<T>(mut self) -> Result<watch::RowJsonCursor<T>> {
90+
pub fn fetch_json<T>(mut self) -> Result<watch::RowJsonCursor<T>> {
9191
self.sql.append(" FORMAT JSONEachRowWithProgress");
9292

9393
let response = self.do_execute(true)?;
@@ -98,11 +98,11 @@ impl Query {
9898
///
9999
/// Note that `T` must be owned.
100100
#[cfg(feature = "watch")]
101-
pub async fn json_one<T>(self) -> Result<T>
101+
pub async fn fetch_json_one<T>(self) -> Result<T>
102102
where
103103
T: for<'b> Deserialize<'b>,
104104
{
105-
match self.json()?.next().await {
105+
match self.fetch_json()?.next().await {
106106
Ok(Some(row)) => Ok(row),
107107
Ok(None) => Err(Error::RowNotFound),
108108
Err(err) => Err(err),
@@ -113,24 +113,24 @@ impl Query {
113113
///
114114
/// Note that `T` must be owned.
115115
#[cfg(feature = "watch")]
116-
pub async fn json_optional<T>(self) -> Result<Option<T>>
116+
pub async fn fetch_json_optional<T>(self) -> Result<Option<T>>
117117
where
118118
T: for<'b> Deserialize<'b>,
119119
{
120-
self.json()?.next().await
120+
self.fetch_json()?.next().await
121121
}
122122

123123
/// Executes the query and returns all the generated results,
124124
/// collected into a [`Vec`].
125125
///
126126
/// Note that `T` must be owned.
127127
#[cfg(feature = "watch")]
128-
pub async fn json_all<T>(self) -> Result<Vec<T>>
128+
pub async fn fetch_json_all<T>(self) -> Result<Vec<T>>
129129
where
130130
T: for<'b> Deserialize<'b>,
131131
{
132132
let mut result = Vec::new();
133-
let mut cursor = self.json::<T>()?;
133+
let mut cursor = self.fetch_json::<T>()?;
134134

135135
while let Some(row) = cursor.next().await? {
136136
result.push(row);

tests/it/query.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,15 @@ async fn fetches_json_row() {
222222

223223
let value = client
224224
.query("SELECT 1,2,3")
225-
.json_one::<serde_json::Value>()
225+
.fetch_json_one::<serde_json::Value>()
226226
.await
227227
.unwrap();
228228

229229
assert_eq!(value, serde_json::json!({ "1": 1, "2": 2, "3": 3}));
230230

231231
let value = client
232232
.query("SELECT (1,2,3) as data")
233-
.json_one::<serde_json::Value>()
233+
.fetch_json_one::<serde_json::Value>()
234234
.await
235235
.unwrap();
236236

@@ -252,7 +252,7 @@ async fn fetches_json_struct() {
252252

253253
let value = client
254254
.query("SELECT -1 as one, '2' as two, 3.0 as three, false as four")
255-
.json_one::<Row>()
255+
.fetch_json_one::<Row>()
256256
.await
257257
.unwrap();
258258

@@ -274,7 +274,7 @@ async fn describes_table() {
274274

275275
let columns = client
276276
.query("DESCRIBE TABLE system.users")
277-
.json_all::<serde_json::Value>()
277+
.fetch_json_all::<serde_json::Value>()
278278
.await
279279
.unwrap();
280280
for c in &columns {

0 commit comments

Comments
 (0)