taos_query/stmt/
mod.rs

1use crate::{
2    common::{views::ColumnView, Value},
3    AsyncQueryable, Queryable, RawResult,
4};
5
6mod column;
7pub use column::*;
8
9pub trait Bindable<Q>
10where
11    Q: Queryable,
12    Self: Sized,
13{
14    fn init(taos: &Q) -> RawResult<Self>;
15
16    fn init_with_req_id(taos: &Q, req_id: u64) -> RawResult<Self>;
17
18    fn prepare<S: AsRef<str>>(&mut self, sql: S) -> RawResult<&mut Self>;
19
20    fn set_tbname<S: AsRef<str>>(&mut self, name: S) -> RawResult<&mut Self>;
21
22    fn set_tags(&mut self, tags: &[Value]) -> RawResult<&mut Self>;
23
24    fn set_tbname_tags<S: AsRef<str>>(&mut self, name: S, tags: &[Value]) -> RawResult<&mut Self> {
25        self.set_tbname(name)?.set_tags(tags)
26    }
27
28    fn bind(&mut self, params: &[ColumnView]) -> RawResult<&mut Self>;
29
30    fn add_batch(&mut self) -> RawResult<&mut Self>;
31
32    fn execute(&mut self) -> RawResult<usize>;
33
34    fn affected_rows(&self) -> usize;
35
36    fn result_set(&mut self) -> RawResult<Q::ResultSet> {
37        todo!()
38    }
39}
40
41#[async_trait::async_trait]
42pub trait AsyncBindable<Q>
43where
44    Q: AsyncQueryable,
45    Self: Sized,
46{
47    async fn init(taos: &Q) -> RawResult<Self>;
48
49    async fn init_with_req_id(taos: &Q, req_id: u64) -> RawResult<Self>;
50
51    async fn prepare(&mut self, sql: &str) -> RawResult<&mut Self>;
52
53    async fn set_tbname(&mut self, name: &str) -> RawResult<&mut Self>;
54
55    async fn set_tags(&mut self, tags: &[Value]) -> RawResult<&mut Self>;
56
57    async fn set_tbname_tags(&mut self, name: &str, tags: &[Value]) -> RawResult<&mut Self> {
58        self.set_tbname(name).await?.set_tags(tags).await
59    }
60
61    async fn bind(&mut self, params: &[ColumnView]) -> RawResult<&mut Self>;
62
63    async fn add_batch(&mut self) -> RawResult<&mut Self>;
64
65    async fn execute(&mut self) -> RawResult<usize>;
66
67    async fn affected_rows(&self) -> usize;
68
69    async fn result_set(&mut self) -> RawResult<Q::AsyncResultSet> {
70        todo!()
71    }
72}