mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-10 15:57:53 +00:00
feat(api): update rust deps, move /private/meta endpoint to rust-api
This commit is contained in:
parent
f14c421e23
commit
e415c6704f
20 changed files with 1835 additions and 244 deletions
42
lib/libpk/src/db/mod.rs
Normal file
42
lib/libpk/src/db/mod.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
use fred::pool::RedisPool;
|
||||
use sqlx::postgres::{PgConnectOptions, PgPool, PgPoolOptions};
|
||||
use std::str::FromStr;
|
||||
use tracing::info;
|
||||
|
||||
pub mod repository;
|
||||
|
||||
pub async fn init_redis() -> anyhow::Result<RedisPool> {
|
||||
info!("connecting to redis");
|
||||
let redis = fred::pool::RedisPool::new(
|
||||
fred::types::RedisConfig::from_url_centralized(crate::config.db.data_redis_addr.as_ref())
|
||||
.expect("redis url is invalid"),
|
||||
10,
|
||||
)?;
|
||||
|
||||
let redis_handle = redis.connect(Some(fred::types::ReconnectPolicy::default()));
|
||||
tokio::spawn(async move { redis_handle });
|
||||
|
||||
Ok(redis)
|
||||
}
|
||||
|
||||
pub async fn init_data_db() -> anyhow::Result<PgPool> {
|
||||
info!("connecting to database");
|
||||
|
||||
let mut options = PgConnectOptions::from_str(&crate::config.db.data_db_uri)?;
|
||||
|
||||
if let Some(password) = crate::config.db.db_password.clone() {
|
||||
options = options.password(&password);
|
||||
}
|
||||
|
||||
let mut pool = PgPoolOptions::new();
|
||||
|
||||
if let Some(max_conns) = crate::config.db.data_db_max_connections {
|
||||
pool = pool.max_connections(max_conns);
|
||||
}
|
||||
|
||||
if let Some(min_conns) = crate::config.db.data_db_min_connections {
|
||||
pool = pool.min_connections(min_conns);
|
||||
}
|
||||
|
||||
Ok(pool.connect_with(options).await?)
|
||||
}
|
||||
2
lib/libpk/src/db/repository/mod.rs
Normal file
2
lib/libpk/src/db/repository/mod.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
mod stats;
|
||||
pub use stats::*;
|
||||
13
lib/libpk/src/db/repository/stats.rs
Normal file
13
lib/libpk/src/db/repository/stats.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
pub async fn get_stats(pool: &sqlx::postgres::PgPool) -> anyhow::Result<Counts> {
|
||||
let counts: Counts = sqlx::query_as("select * from info").fetch_one(pool).await?;
|
||||
Ok(counts)
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, sqlx::FromRow)]
|
||||
pub struct Counts {
|
||||
pub system_count: i64,
|
||||
pub member_count: i64,
|
||||
pub group_count: i64,
|
||||
pub switch_count: i64,
|
||||
pub message_count: i64,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue