chore: remove sqlx dependency from Cargo.toml and Cargo.lock
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -49,7 +49,6 @@ dependencies = [
|
|||||||
"password-auth",
|
"password-auth",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sqlx",
|
|
||||||
"thiserror 2.0.17",
|
"thiserror 2.0.17",
|
||||||
"time",
|
"time",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|||||||
@@ -9,12 +9,10 @@ default = ["sqlite"]
|
|||||||
sqlite = [
|
sqlite = [
|
||||||
"infra/sqlite",
|
"infra/sqlite",
|
||||||
"tower-sessions-sqlx-store/sqlite",
|
"tower-sessions-sqlx-store/sqlite",
|
||||||
"sqlx/sqlite",
|
|
||||||
]
|
]
|
||||||
postgres = [
|
postgres = [
|
||||||
"infra/postgres",
|
"infra/postgres",
|
||||||
"tower-sessions-sqlx-store/postgres",
|
"tower-sessions-sqlx-store/postgres",
|
||||||
"sqlx/postgres",
|
|
||||||
"k-core/postgres",
|
"k-core/postgres",
|
||||||
]
|
]
|
||||||
broker-nats = ["infra/broker-nats"]
|
broker-nats = ["infra/broker-nats"]
|
||||||
@@ -65,7 +63,6 @@ tracing = "0.1"
|
|||||||
tracing-subscriber = { version = "0.3.22", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.22", features = ["env-filter"] }
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
sqlx = { version = "0.8.6", features = ["sqlite", "runtime-tokio"] }
|
|
||||||
dotenvy = "0.15.7"
|
dotenvy = "0.15.7"
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
|
|||||||
@@ -21,52 +21,38 @@ use crate::state::AppState;
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
// 1. Initialize logging
|
logging::init("api");
|
||||||
logging::init("template-api");
|
|
||||||
|
|
||||||
// 2. Load configuration
|
|
||||||
// We use dotenvy explicitly here since config crate might not pick up .env automatically reliably
|
|
||||||
dotenvy::dotenv().ok();
|
dotenvy::dotenv().ok();
|
||||||
let config = Config::new().expect("Failed to load configuration");
|
let config = Config::new().expect("Failed to load configuration");
|
||||||
|
|
||||||
info!("Starting server on {}:{}", config.host, config.port);
|
info!("Starting server on {}:{}", config.host, config.port);
|
||||||
|
|
||||||
// 3. Connect to database
|
|
||||||
// k-core handles the "Which DB are we using?" logic internally based on feature flags
|
|
||||||
// and returns the correct Enum variant.
|
|
||||||
let db_config = k_core::db::DatabaseConfig {
|
let db_config = k_core::db::DatabaseConfig {
|
||||||
url: config.database_url.clone(),
|
url: config.database_url.clone(),
|
||||||
max_connections: 5,
|
max_connections: 5,
|
||||||
acquire_timeout: StdDuration::from_secs(30),
|
acquire_timeout: StdDuration::from_secs(30),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns k_core::db::DatabasePool
|
|
||||||
let db_pool = k_core::db::connect(&db_config).await?;
|
let db_pool = k_core::db::connect(&db_config).await?;
|
||||||
|
|
||||||
// 4. Run migrations (using the re-export if you kept it, or direct k_core)
|
|
||||||
infra::db::run_migrations(&db_pool).await?;
|
infra::db::run_migrations(&db_pool).await?;
|
||||||
|
|
||||||
// 5. Initialize Services
|
|
||||||
let user_repo = build_user_repository(&db_pool).await?;
|
let user_repo = build_user_repository(&db_pool).await?;
|
||||||
let user_service = UserService::new(user_repo.clone());
|
let user_service = UserService::new(user_repo.clone());
|
||||||
|
|
||||||
// 6. Setup Session Store
|
|
||||||
let session_store = build_session_store(&db_pool).await?;
|
let session_store = build_session_store(&db_pool).await?;
|
||||||
|
|
||||||
let session_layer = SessionManagerLayer::new(session_store)
|
let session_layer = SessionManagerLayer::new(session_store)
|
||||||
.with_secure(false) // Set to true in production with HTTPS
|
.with_secure(false) // Set to true in production with HTTPS
|
||||||
.with_expiry(Expiry::OnInactivity(time::Duration::hours(1)));
|
.with_expiry(Expiry::OnInactivity(time::Duration::hours(1)));
|
||||||
|
|
||||||
// 7. Setup Auth
|
|
||||||
let auth_layer = auth::setup_auth_layer(session_layer, user_repo.clone()).await?;
|
let auth_layer = auth::setup_auth_layer(session_layer, user_repo.clone()).await?;
|
||||||
|
|
||||||
// 8. Create App State
|
|
||||||
let state = AppState::new(user_service, config.clone());
|
let state = AppState::new(user_service, config.clone());
|
||||||
|
|
||||||
// 9. Build Router
|
|
||||||
let app = routes::api_v1_router().layer(auth_layer).with_state(state);
|
let app = routes::api_v1_router().layer(auth_layer).with_state(state);
|
||||||
|
|
||||||
// 10. Start Server
|
|
||||||
let addr: SocketAddr = format!("{}:{}", config.host, config.port).parse()?;
|
let addr: SocketAddr = format!("{}:{}", config.host, config.port).parse()?;
|
||||||
let listener = TcpListener::bind(addr).await?;
|
let listener = TcpListener::bind(addr).await?;
|
||||||
axum::serve(listener, app).await?;
|
axum::serve(listener, app).await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user