sentinel_driver/
statement.rs1use std::sync::Arc;
2
3use crate::protocol::backend::FieldDescription;
4use crate::types::Oid;
5
6#[derive(Debug, Clone)]
8pub struct Statement {
9 name: String,
11 sql: String,
13 param_types: Vec<Oid>,
15 columns: Option<Arc<Vec<FieldDescription>>>,
17}
18
19impl Statement {
20 pub fn new(
21 name: String,
22 sql: String,
23 param_types: Vec<Oid>,
24 columns: Option<Vec<FieldDescription>>,
25 ) -> Self {
26 Self {
27 name,
28 sql,
29 param_types,
30 columns: columns.map(Arc::new),
31 }
32 }
33
34 pub fn name(&self) -> &str {
36 &self.name
37 }
38
39 pub fn sql(&self) -> &str {
41 &self.sql
42 }
43
44 pub fn param_types(&self) -> &[Oid] {
46 &self.param_types
47 }
48
49 pub fn param_count(&self) -> usize {
51 self.param_types.len()
52 }
53
54 pub fn columns(&self) -> Option<&[FieldDescription]> {
56 self.columns.as_ref().map(|c| c.as_slice())
57 }
58
59 pub fn column_count(&self) -> usize {
61 self.columns.as_ref().map_or(0, |c| c.len())
62 }
63}