mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-13 19:15:39 +00:00
feat: load db_* db connection
This commit is contained in:
16
src/data.rs
16
src/data.rs
@@ -19,6 +19,8 @@ use std::thread;
|
|||||||
|
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
use argon2_creds::{Config, ConfigBuilder, PasswordPolicy};
|
use argon2_creds::{Config, ConfigBuilder, PasswordPolicy};
|
||||||
|
use db_core::prelude::*;
|
||||||
|
use db_sqlx_postgres::{ConnectionOptions, Fresh};
|
||||||
use lettre::transport::smtp::authentication::Mechanism;
|
use lettre::transport::smtp::authentication::Mechanism;
|
||||||
use lettre::{
|
use lettre::{
|
||||||
transport::smtp::authentication::Credentials, AsyncSmtpTransport, Tokio1Executor,
|
transport::smtp::authentication::Credentials, AsyncSmtpTransport, Tokio1Executor,
|
||||||
@@ -41,6 +43,8 @@ use libmcaptcha::{
|
|||||||
use sqlx::postgres::PgPoolOptions;
|
use sqlx::postgres::PgPoolOptions;
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
|
||||||
|
use db_core::MCDatabase;
|
||||||
|
|
||||||
use crate::errors::ServiceResult;
|
use crate::errors::ServiceResult;
|
||||||
use crate::SETTINGS;
|
use crate::SETTINGS;
|
||||||
|
|
||||||
@@ -142,6 +146,8 @@ impl SystemGroup {
|
|||||||
pub struct Data {
|
pub struct Data {
|
||||||
/// databse pool
|
/// databse pool
|
||||||
pub db: PgPool,
|
pub db: PgPool,
|
||||||
|
/// database ops defined by db crates
|
||||||
|
pub dblib: Box<dyn MCDatabase>,
|
||||||
/// credential management configuration
|
/// credential management configuration
|
||||||
pub creds: Config,
|
pub creds: Config,
|
||||||
/// mCaptcha system: Redis cache, etc.
|
/// mCaptcha system: Redis cache, etc.
|
||||||
@@ -179,9 +185,19 @@ impl Data {
|
|||||||
.await
|
.await
|
||||||
.expect("Unable to form database pool");
|
.expect("Unable to form database pool");
|
||||||
|
|
||||||
|
let settings = &SETTINGS;
|
||||||
|
let pool = settings.database.pool;
|
||||||
|
let pool_options = PgPoolOptions::new().max_connections(pool);
|
||||||
|
let connection_options = ConnectionOptions::Fresh(Fresh {
|
||||||
|
pool_options,
|
||||||
|
url: settings.database.url.clone(),
|
||||||
|
});
|
||||||
|
let dblib = Box::new(connection_options.connect().await.unwrap());
|
||||||
|
|
||||||
let data = Data {
|
let data = Data {
|
||||||
creds,
|
creds,
|
||||||
db,
|
db,
|
||||||
|
dblib,
|
||||||
captcha: SystemGroup::new().await,
|
captcha: SystemGroup::new().await,
|
||||||
mailer: Self::get_mailer(),
|
mailer: Self::get_mailer(),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user