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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use std::path::PathBuf;
use crate::{SqlFunArgs, SqlFunArgsError, SqlFunMetadata};
/// builtin item data path resolver
pub struct PostgresBuiltinPaths {
builtin_base_path: PathBuf,
}
impl PostgresBuiltinPaths {
/// create instance
///
/// # Errors
///
/// Returns [`SqlFunArgsError`] when builtin directories cannot be resolved.
pub fn try_from_args(
args: &SqlFunArgs,
metadata: &SqlFunMetadata,
) -> Result<Self, SqlFunArgsError> {
let base_path = args.builtin_info_dir(metadata)?;
Ok(Self {
builtin_base_path: base_path,
})
}
fn path_exists_and_file(path: PathBuf) -> Result<PathBuf, SqlFunArgsError> {
if !path.exists() || !path.is_file() {
SqlFunArgsError::file_path_not_found(&path)?;
}
Ok(path)
}
/// returns type data file path
///
/// # Errors
///
/// Returns [`SqlFunArgsError`] when the expected file is missing.
pub fn types(&self) -> Result<PathBuf, SqlFunArgsError> {
Self::path_exists_and_file(self.builtin_base_path.join("pg_type.json"))
}
/// returns type data file path
///
/// # Errors
///
/// Returns [`SqlFunArgsError`] when the expected file is missing.
pub fn functions(&self) -> Result<PathBuf, SqlFunArgsError> {
Self::path_exists_and_file(self.builtin_base_path.join("functions.json"))
}
/// function details for table functions
///
/// # Errors
///
/// Returns [`SqlFunArgsError`] when the expected file is missing.
pub fn function_details(&self) -> Result<PathBuf, SqlFunArgsError> {
Self::path_exists_and_file(self.builtin_base_path.join("func_detail.json"))
}
/// binary operators
///
/// # Errors
///
/// Returns [`SqlFunArgsError`] when the expected file is missing.
pub fn binary_operators(&self) -> Result<PathBuf, SqlFunArgsError> {
Self::path_exists_and_file(self.builtin_base_path.join("binary_op.json"))
}
/// left unary operators
///
/// # Errors
///
/// Returns [`SqlFunArgsError`] when the expected file is missing.
pub fn left_unary_operators(&self) -> Result<PathBuf, SqlFunArgsError> {
Self::path_exists_and_file(self.builtin_base_path.join("left_unary_op.json"))
}
/// right unary operators
///
/// # Errors
///
/// Returns [`SqlFunArgsError`] when the expected file is missing.
pub fn right_unary_operators(&self) -> Result<PathBuf, SqlFunArgsError> {
Self::path_exists_and_file(self.builtin_base_path.join("right_unary_op.json"))
}
/// casts
///
/// # Errors
///
/// Returns [`SqlFunArgsError`] when the expected file is missing.
pub fn casts(&self) -> Result<PathBuf, SqlFunArgsError> {
Self::path_exists_and_file(self.builtin_base_path.join("casts.json"))
}
}