fire_postgres/table/
info.rs

1use super::column::Column;
2use crate::query::Param;
3
4#[derive(Debug, Clone)]
5pub struct Info {
6	data: Vec<Column>,
7}
8
9impl Info {
10	pub fn new(data: Vec<Column>) -> Self {
11		Self { data }
12	}
13
14	pub fn with_capacity(cap: usize) -> Self {
15		Self {
16			data: Vec::with_capacity(cap),
17		}
18	}
19
20	pub fn push(&mut self, col: Column) {
21		self.data.push(col);
22	}
23
24	pub fn data(&self) -> &Vec<Column> {
25		&self.data
26	}
27
28	pub fn names(&self) -> Vec<&'static str> {
29		self.data.iter().map(|v| v.name).collect()
30	}
31
32	pub fn validate_params(
33		&self,
34		params: &[Param],
35	) -> Result<(), ValidateParamsError> {
36		'param_loop: for param in params {
37			for col in &self.data {
38				if param.name != col.name {
39					continue;
40				}
41
42				if param.kind == col.kind {
43					continue 'param_loop;
44				} else {
45					return Err(ValidateParamsError(format!(
46						"{:?} != {:?}",
47						param, col
48					)));
49				}
50			}
51			return Err(ValidateParamsError(format!(
52				"param: {:?} not found",
53				param.name
54			)));
55		}
56		Ok(())
57	}
58}
59
60#[derive(Debug, Clone)]
61pub struct ValidateParamsError(pub String);