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 {
62 self.compartment_id = compartment_id.to_string();
63 self
64 }
65
66 pub fn namespace(mut self, namespace: &str) -> ListTablesRequest {
67 self.namespace = namespace.to_string();
68 self
69 }
70
71 pub fn limit(mut self, limit: i32) -> ListTablesRequest {
72 self.limit = limit;
73 self
74 }
75
76 pub fn start_index(mut self, start_index: i32) -> ListTablesRequest {
77 self.start_index = start_index;
78 self
79 }
80
81 pub async fn execute(&self, h: &Handle) -> Result<ListTablesResult, NoSQLError> {
82 let mut w: Writer = Writer::new();
83 w.write_i16(h.inner.serial_version);
84 let timeout = h.get_timeout(&self.timeout);
85 self.nson_serialize(&mut w, &timeout);
86 let mut opts = SendOptions {
87 timeout: timeout,
88 retryable: true,
89 compartment_id: self.compartment_id.clone(),
90 ..Default::default()
91 };
92 let mut r = h.send_and_receive(w, &mut opts).await?;
93 let resp = ListTablesRequest::nson_deserialize(&mut r)?;
94 Ok(resp)
95 }
96
97 pub(crate) fn nson_serialize(&self, w: &mut Writer, timeout: &Duration) {
98 let mut ns = NsonSerializer::start_request(w);
99 ns.start_header();
100 ns.write_header(OpCode::ListTables, timeout, "");
101 ns.end_header();
102
103 ns.start_payload();
105 ns.write_nonempty_string_field(NAMESPACE, &self.namespace);
106 ns.write_nonzero_i32_field(LIST_START_INDEX, self.start_index);
107 ns.write_nonzero_i32_field(LIST_MAX_TO_READ, self.limit);
108 ns.end_payload();
111
112 ns.end_request();
113 }
114
115 pub(crate) fn nson_deserialize(r: &mut Reader) -> Result<ListTablesResult, NoSQLError> {
116 let mut walker = MapWalker::new(r)?;
117 let mut res: ListTablesResult = Default::default();
118 while walker.has_next() {
119 walker.next()?;
120 let name = walker.current_name();
121 match name.as_str() {
122 ERROR_CODE => {
123 walker.handle_error_code()?;
124 }
125 TABLES => {
126 res.table_names = walker.read_nson_string_array()?;
127 }
129 LAST_INDEX => {
130 res.last_table_index = walker.read_nson_i32()?;
131 }
133 _ => {
134 walker.skip_nson_field()?;
136 }
137 }
138 }
139 Ok(res)
140 }
141}
142
143impl NsonRequest for ListTablesRequest {
144 fn serialize(&self, w: &mut Writer, timeout: &Duration) {
145 self.nson_serialize(w, timeout);
146 }
147}