google_cloud_bigquery/http/tabledata/
list.rs

1use std::fmt::Debug;
2
3use reqwest_middleware::{ClientWithMiddleware as Client, RequestBuilder};
4
5#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
6#[serde(untagged)]
7pub enum Value {
8    Null,
9    String(String),
10    Array(Vec<Cell>),
11    Struct(Tuple),
12}
13
14#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
15#[serde(rename_all = "camelCase")]
16pub struct Cell {
17    pub v: Value,
18}
19
20#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
21#[serde(rename_all = "camelCase")]
22pub struct Tuple {
23    pub f: Vec<Cell>,
24}
25
26#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
27#[serde(rename_all = "camelCase")]
28pub struct FetchDataRequest {
29    /// Start row index of the table.
30    pub start_index: Option<i32>,
31    /// Row limit of the table.
32    pub max_results: Option<u32>,
33    ///To retrieve the next page of table data, set
34    /// this field to the string provided in the pageToken field of the response body from
35    /// your previous call to tabledata.list.
36    pub page_token: Option<String>,
37    /// Subset of fields to return, supports select into sub fields. Example: selectedFields = "a,e.d.f";
38    pub selected_fields: Option<String>,
39}
40
41#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
42#[serde(rename_all = "camelCase")]
43pub struct FetchDataResponse {
44    /// Will be set to "bigquery#tableDataList".
45    #[serde(default)]
46    pub kind: String,
47    /// Etag to the response.
48    #[serde(default)]
49    pub etag: String,
50    /// Total rows of the entire table. In order to show default value "0", we have to present it as string.
51    #[serde(deserialize_with = "crate::http::from_str")]
52    pub total_rows: u64,
53    /// When this field is non-empty, it indicates that additional results are available.
54    /// To request the next page of data, set the pageToken field of your next tabledata.
55    /// list call to the string returned in this field.
56    pub page_token: Option<String>,
57    /// Repeated rows as result. The REST-based representation of this data leverages a series of JSON f,v objects for indicating fields and values.
58    pub rows: Option<Vec<Tuple>>,
59}
60
61pub fn build(
62    base_url: &str,
63    client: &Client,
64    project_id: &str,
65    dataset_id: &str,
66    table_id: &str,
67    data: &FetchDataRequest,
68) -> RequestBuilder {
69    let url = format!(
70        "{}/projects/{}/datasets/{}/tables/{}/data",
71        base_url, project_id, dataset_id, table_id
72    );
73    client.get(url).query(&data)
74}