preliminary DB support
This commit is contained in:
parent
3b103e12d4
commit
ee798408f0
6 changed files with 131 additions and 3 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use cfg_if::cfg_if;
|
||||
use rnex_core::common::setup;
|
||||
use rnex_core::executables::common::DB_POOL;
|
||||
use rnex_core::executables::common::new_simple_backend;
|
||||
use rnex_core::executables::friends_backend::start_friends_backend;
|
||||
use rnex_core::nex::matchmake::MatchmakeManager;
|
||||
|
|
@ -8,6 +9,7 @@ use rnex_core::nex::user::User;
|
|||
use rnex_core::rmc::protocols::{RemoteDisconnectable, RmcPureRemoteObject};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicU32;
|
||||
use sqlx::PgPool;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
|
@ -16,6 +18,15 @@ async fn main() {
|
|||
cfg_if! {
|
||||
if #[cfg(feature = "friends")]{
|
||||
start_friends_backend().await;
|
||||
} else if #[cfg(feature = "datastore")] {
|
||||
let database_url = std::env::var("RNEX_DATASTORE_DATABASE_URL")
|
||||
.expect("RNEX_DATASTORE_DATABASE_URL must be set");
|
||||
|
||||
let pool = PgPool::connect(&database_url)
|
||||
.await
|
||||
.expect("Failed to create pool");
|
||||
|
||||
DB_POOL.set(pool).expect("failed to set global DB_POOL");
|
||||
} else {
|
||||
use rnex_core::executables::regular_backend;
|
||||
regular_backend::start_regular_backend().await
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ use std::net::{Ipv4Addr, SocketAddrV4};
|
|||
use std::sync::Arc;
|
||||
use tokio::net::TcpListener;
|
||||
use std::sync::LazyLock;
|
||||
use std::sync::OnceLock;
|
||||
use sqlx::postgres::PgPool;
|
||||
|
||||
use log::error;
|
||||
use std::error::Error;
|
||||
|
|
@ -17,6 +19,16 @@ use crate::reggie::UnitPacketRead;
|
|||
|
||||
const IP_REQ_SERVICE_URL: &str = "https://ipinfo.io/ip";
|
||||
|
||||
pub static RNEX_DATASTORE_DATABASE_URL: LazyLock<String> = LazyLock::new(|| {
|
||||
std::env::var("RNEX_DATASTORE_DATABASE_URL")
|
||||
.expect("RNEX_DATASTORE_DATABASE_URL must be set")
|
||||
});
|
||||
|
||||
pub static DB_POOL: OnceLock<PgPool> = OnceLock::new();
|
||||
|
||||
pub fn get_db() -> &'static PgPool {
|
||||
DB_POOL.get().expect("db_pool not initialized")
|
||||
}
|
||||
pub static RNEX_DATASTORE_S3_ENDPOINT: LazyLock<String> = LazyLock::new(|| {
|
||||
std::env::var("RNEX_DATASTORE_S3_ENDPOINT")
|
||||
.expect("RNEX_DATASTORE_S3_ENDPOINT must be set")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue