oracle_nosql_rust_sdk/
list_tables_request.rs1use crate::error::NoSQLError;
8use crate::handle::Handle;
9use crate::handle::SendOptions;
10use crate::nson::*;
11use crate::reader::Reader;
12use crate::types::OpCode;
13use crate::writer::Writer;
14use std::result::Result;
15use std::time::Duration;
16
17#[derive(Default, Debug)]
19pub struct ListTablesRequest {
20 pub(crate) compartment_id: String,
21 pub(crate) namespace: String,
22 pub(crate) start_index: i32,
23 pub(crate) limit: i32,
24 pub(crate) timeout: Option<Duration>,
25 }
27
28#[derive(Default, Debug)]
30pub struct ListTablesResult {
31 pub table_names: Vec<String>,
32 pub last_table_index: i32,
33}
34
35impl ListTablesRequest {
36 pub fn new() -> ListTablesRequest {
37 ListTablesRequest {
38 ..Default::default()
39 }
40 }
41
42 pub fn timeout(mut self, t: &Duration) -> Self {
49 self.timeout = Some(t.clone());
50 self
51 }
52
53 pub fn compartment_id(mut self, compartment_id: &str) -> Self {
61 self.compartment_id = compartment_id.to_string();
62 self
63 }
64
65 pub fn namespace(mut self, namespace: &str) -> ListTablesRequest {
66 self.namespace = namespace.to_string();
67 self
68 }
69
70 pub fn limit(mut self, limit: i32) -> ListTablesRequest {
71 self.limit = limit;
72 self
73 }
74
75 pub fn start_index(mut self, start_index: i32) -> ListTablesRequest {
76 self.start_index = start_index;
77 self
78 }
79
80 pub async fn execute(&self, h: &Handle) -> Result<ListTablesResult, NoSQLError> {
81 let mut w: Writer = Writer::new();
82 w.write_i16(h.inner.serial_version);
83 let timeout = h.get_timeout(&self.timeout);
84 self.nson_serialize(&mut w, &timeout);
85 let mut opts = SendOptions {
86 timeout: timeout,
87 retryable: true,
88 compartment_id: self.compartment_id.clone(),
89 ..Default::default()
90 };
91 let mut r = h.send_and_receive(w, &mut opts).await?;
92 let resp = ListTablesRequest::nson_deserialize(&mut r)?;
93 Ok(resp)
94 }
95
96 pub(crate) fn nson_serialize(&self, w: &mut Writer, timeout: &Duration) {
97 let mut ns = NsonSerializer::start_request(w);
98 ns.start_header();
99 ns.write_header(OpCode::ListTables, timeout, "");
100 ns.end_header();
101
102 ns.start_payload();
104 ns.write_nonempty_string_field(NAMESPACE, &self.namespace);
105 ns.write_nonzero_i32_field(LIST_START_INDEX, self.start_index);
106 ns.write_nonzero_i32_field(LIST_MAX_TO_READ, self.limit);
107 ns.end_payload();
110
111 ns.end_request();
112 }
113
114 pub(crate) fn nson_deserialize(r: &mut Reader) -> Result<ListTablesResult, NoSQLError> {
115 let mut walker = MapWalker::new(r)?;
116 let mut res: ListTablesResult = Default::default();
117 while walker.has_next() {
118 walker.next()?;
119 let name = walker.current_name();
120 match name.as_str() {
121 ERROR_CODE => {
122 walker.handle_error_code()?;
123 }
124 TABLES => {
125 res.table_names = walker.read_nson_string_array()?;
126 }
128 LAST_INDEX => {
129 res.last_table_index = walker.read_nson_i32()?;
130 }
132 _ => {
133 walker.skip_nson_field()?;
135 }
136 }
137 }
138 Ok(res)
139 }
140}
141
142impl NsonRequest for ListTablesRequest {
143 fn serialize(&self, w: &mut Writer, timeout: &Duration) {
144 self.nson_serialize(w, timeout);
145 }
146}