DB Provider Wrapper (src/db_provider.rs)

gears-rust · libs/toolkit-db/src/db_provider.rs · rust · Apache-2.0
database, lang:rust, tag:provider, tag:async, tag:arc

Provides non-transactional and transactional DB access for services, wrapping gear-scoped Db.

// Source: https://github.com/constructorfabric/gears-rust | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
use std::{future::Future, marker::PhantomData, pin::Pin, sync::Arc};

use crate::secure::{DbConn, DbTx, TxConfig};
use crate::{Db, DbError};

/// Thin, reusable DB entrypoint for application services.
///
/// This wraps a gear-scoped `Db` and provides:
/// - `conn()` for non-transactional operations
/// - `transaction(...)` for transactional operations without exposing `DbHandle`
///
/// Services can store this behind an `Arc` and use:
///
/// ```ignore
/// let conn = self.db.conn()?;
/// let out = self.db.transaction(|tx| Box::pin(async move { /* ... */ })).await?;
/// ```
p

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key