Skip to main content

ocpp_service/db/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Kevin Vavelin, Codetics (https://codetics.fr)
3
4//! PostgreSQL access. Queries are plain SQL checked by the integration tests
5//! (no compile-time database connection required).
6
7pub mod charging;
8pub mod events;
9pub mod reservations;
10pub mod stations;
11pub mod tariffs;
12pub mod tokens;
13pub mod transactions;
14mod ts;
15
16pub use ts::Ts;
17
18use sqlx::postgres::{PgPool, PgPoolOptions};
19
20pub type Db = PgPool;
21
22pub async fn connect(url: &str, max_connections: u32) -> Result<Db, sqlx::Error> {
23    PgPoolOptions::new()
24        .max_connections(max_connections)
25        .acquire_timeout(std::time::Duration::from_secs(10))
26        .connect(url)
27        .await
28}
29
30pub async fn migrate(db: &Db) -> Result<(), sqlx::migrate::MigrateError> {
31    sqlx::migrate!("./migrations").run(db).await
32}