1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

use super::column::Column;
use crate::query::Param;

#[derive(Debug, Clone)]
pub struct Info {
	data: Vec<Column>
}

impl Info {
	
	pub fn new(data: Vec<Column>) -> Self {
		Self { data }
	}

	pub fn with_capacity(cap: usize) -> Self {
		Self { data: Vec::with_capacity(cap) }
	}

	pub fn push(&mut self, col: Column) {
		self.data.push(col);
	}

	pub fn data(&self) -> &Vec<Column> {
		&self.data
	}

	pub fn names(&self) -> Vec<&'static str> {
		self.data.iter().map(|v| v.name).collect()
	}

	pub fn validate_params(
		&self,
		params: &[Param]
	) -> Result<(), ValidateParamsError> {
		'param_loop: for param in params {
			for col in &self.data {
				if param.name != col.name {
					continue
				}

				if param.kind == col.kind {
					continue 'param_loop
				} else {
					return Err(ValidateParamsError(
						format!("{:?} != {:?}", param, col)
					));
				}
			}
			return Err(ValidateParamsError(
				format!("param: {:?} not found", param.name)
			))
		}
		Ok(())
	}

}

#[derive(Debug, Clone)]
pub struct ValidateParamsError(String);