chore (backend-rs): change function names

This commit is contained in:
naskya 2024-06-06 17:10:39 +09:00
parent 3cf1e306b1
commit 7413866885
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
3 changed files with 12 additions and 11 deletions

View file

@ -1,8 +1,9 @@
//! Interfaces for accessing PostgreSQL and Redis
pub use postgresql::db_conn;
pub use postgresql::get_conn as db_conn;
pub use redis::key as redis_key;
pub use redis::redis_conn;
pub use redis::get_conn as redis_conn;
pub use redis::RedisConnError;
pub mod cache;

View file

@ -29,7 +29,7 @@ async fn init_conn() -> Result<&'static DbConn, DbErr> {
}
/// Returns an async PostgreSQL connection that can be used with [sea_orm] utilities.
pub async fn db_conn() -> Result<&'static DbConn, DbErr> {
pub async fn get_conn() -> Result<&'static DbConn, DbErr> {
match DB_CONN.get() {
Some(conn) => Ok(conn),
None => init_conn().await,
@ -38,11 +38,11 @@ pub async fn db_conn() -> Result<&'static DbConn, DbErr> {
#[cfg(test)]
mod unit_test {
use super::db_conn;
use super::get_conn;
#[tokio::test]
async fn connect() {
assert!(db_conn().await.is_ok());
assert!(db_conn().await.is_ok());
assert!(get_conn().await.is_ok());
assert!(get_conn().await.is_ok());
}
}

View file

@ -88,7 +88,7 @@ pub enum RedisConnError {
}
/// Returns an async [redis] connection managed by a [bb8] connection pool.
pub async fn redis_conn(
pub async fn get_conn(
) -> Result<PooledConnection<'static, RedisConnectionManager>, RedisConnError> {
if !CONN_POOL.initialized() {
let init_res = init_conn_pool().await;
@ -114,19 +114,19 @@ pub fn key(key: impl ToString) -> String {
#[cfg(test)]
mod unit_test {
use super::redis_conn;
use super::get_conn;
use pretty_assertions::assert_eq;
use redis::AsyncCommands;
#[tokio::test]
async fn connect() {
assert!(redis_conn().await.is_ok());
assert!(redis_conn().await.is_ok());
assert!(get_conn().await.is_ok());
assert!(get_conn().await.is_ok());
}
#[tokio::test]
async fn access() {
let mut redis = redis_conn().await.unwrap();
let mut redis = get_conn().await.unwrap();
let key = "CARGO_UNIT_TEST_KEY";
let value = "CARGO_UNIT_TEST_VALUE";