google_cloud_bigquery/http/tabledata/
insert_all.rs1use reqwest_middleware::{ClientWithMiddleware as Client, RequestBuilder};
2use serde::Serialize;
3
4#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
5#[serde(rename_all = "camelCase")]
6pub struct Row<T: Serialize> {
7 pub insert_id: Option<String>,
10
11 pub json: T,
14}
15
16#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
17#[serde(rename_all = "camelCase")]
18pub struct InsertAllRequest<T: Serialize> {
19 pub skip_invalid_rows: Option<bool>,
22 pub ignore_unknown_values: Option<bool>,
25 pub template_suffix: Option<String>,
28 pub rows: Vec<Row<T>>,
30 pub trace_id: Option<String>,
33}
34
35impl<T: Serialize> Default for InsertAllRequest<T> {
36 fn default() -> Self {
37 Self {
38 skip_invalid_rows: None,
39 ignore_unknown_values: None,
40 template_suffix: None,
41 rows: vec![],
42 trace_id: None,
43 }
44 }
45}
46
47#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Default, Debug)]
48#[serde(rename_all = "camelCase")]
49pub struct ErrorMessage {
50 pub reason: String,
52 pub location: String,
54 pub debug_info: String,
56 pub message: String,
58}
59
60#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Default, Debug)]
61#[serde(rename_all = "camelCase")]
62pub struct Error {
63 pub index: i32,
64 pub errors: Vec<ErrorMessage>,
65}
66
67#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Default, Debug)]
68#[serde(rename_all = "camelCase")]
69pub struct InsertAllResponse {
70 #[serde(default)]
71 pub kind: String,
72 pub insert_errors: Option<Vec<Error>>,
73}
74
75pub fn build<T: Serialize>(
76 base_url: &str,
77 client: &Client,
78 project_id: &str,
79 dataset_id: &str,
80 table_id: &str,
81 data: &InsertAllRequest<T>,
82) -> RequestBuilder {
83 let url = format!(
84 "{}/projects/{}/datasets/{}/tables/{}/insertAll",
85 base_url, project_id, dataset_id, table_id
86 );
87 client.post(url).json(data)
88}