br_pgsql/
lib.rs

1use json::JsonValue;
2use crate::config::Config;
3use crate::connect::Connect;
4use crate::pools::Pools;
5
6mod config;
7pub mod connect;
8mod packet;
9mod format;
10pub mod pools;
11
12#[derive(Clone, Debug)]
13pub struct Pgsql {
14    /// 基础配置
15    pub config: Config,
16}
17
18impl Pgsql {
19    /// 配置文件加载
20    pub fn new(config: JsonValue) -> Result<Self, String> {
21        let config = match Config::new(config) {
22            Ok(e) => e,
23            Err(e) => return Err(format!("配置文件错误: {e}")),
24        };
25
26        Ok(Self { config })
27    }
28
29    /// 获取连接
30    pub fn connect(&mut self) -> Result<Connect, String> {
31        Connect::new(self.config.clone())
32    }
33    /// 获取连接
34    pub fn pools(&mut self) -> Result<Pools, String> {
35        Pools::new(self.config.clone())
36    }
37}