1use std::path::PathBuf;
2
3use crate::{SqlFunArgs, SqlFunArgsError, SqlFunMetadata};
4
5pub struct PostgresBuiltinPaths {
7 builtin_base_path: PathBuf,
8}
9
10impl PostgresBuiltinPaths {
11 pub fn try_from_args(
17 args: &SqlFunArgs,
18 metadata: &SqlFunMetadata,
19 ) -> Result<Self, SqlFunArgsError> {
20 let base_path = args.builtin_info_dir(metadata)?;
21 Ok(Self {
22 builtin_base_path: base_path,
23 })
24 }
25
26 fn path_exists_and_file(path: PathBuf) -> Result<PathBuf, SqlFunArgsError> {
27 if !path.exists() || !path.is_file() {
28 SqlFunArgsError::file_path_not_found(&path)?;
29 }
30 Ok(path)
31 }
32
33 pub fn types(&self) -> Result<PathBuf, SqlFunArgsError> {
39 Self::path_exists_and_file(self.builtin_base_path.join("pg_type.json"))
40 }
41
42 pub fn functions(&self) -> Result<PathBuf, SqlFunArgsError> {
48 Self::path_exists_and_file(self.builtin_base_path.join("functions.json"))
49 }
50
51 pub fn function_details(&self) -> Result<PathBuf, SqlFunArgsError> {
57 Self::path_exists_and_file(self.builtin_base_path.join("func_detail.json"))
58 }
59
60 pub fn binary_operators(&self) -> Result<PathBuf, SqlFunArgsError> {
66 Self::path_exists_and_file(self.builtin_base_path.join("binary_op.json"))
67 }
68
69 pub fn left_unary_operators(&self) -> Result<PathBuf, SqlFunArgsError> {
75 Self::path_exists_and_file(self.builtin_base_path.join("left_unary_op.json"))
76 }
77
78 pub fn right_unary_operators(&self) -> Result<PathBuf, SqlFunArgsError> {
84 Self::path_exists_and_file(self.builtin_base_path.join("right_unary_op.json"))
85 }
86
87 pub fn casts(&self) -> Result<PathBuf, SqlFunArgsError> {
93 Self::path_exists_and_file(self.builtin_base_path.join("casts.json"))
94 }
95}