pub async fn init(config: DatabaseConfig) -> Result<Arc<DbPool>>Expand description
初始化全局数据库连接池
使用提供的配置初始化连接池。如果连接池已经初始化,将返回错误。
§示例
use baichun_framework_db::{DatabaseConfig, init};
async fn example() -> Result<()> {
let config = DatabaseConfig::new()
.url("mysql://user:pass@localhost/db_name")
.max_connections(10);
init(config).await?;
Ok(())
}