Skip to main content

dataplane_sdk/core/db/
tx.rs

1//  Copyright (c) 2026 Metaform Systems, Inc
2//
3//  This program and the accompanying materials are made available under the
4//  terms of the Apache License, Version 2.0 which is available at
5//  https://www.apache.org/licenses/LICENSE-2.0
6//
7//    SPDX-License-Identifier: Apache-2.0
8//
9//    Contributors:
10//         Metaform Systems, Inc. - initial API and implementation
11//
12
13use crate::core::error::DbResult;
14
15#[async_trait::async_trait]
16#[cfg_attr(test, mockall::automock(type Transaction = MockTransaction;))]
17pub trait TransactionalContext: Send + Sync {
18    type Transaction: Transaction;
19
20    /// Begin a new transaction.
21    async fn begin(&self) -> DbResult<Self::Transaction>;
22}
23
24#[async_trait::async_trait]
25#[cfg_attr(test, mockall::automock)]
26pub trait Transaction {
27    /// Commit the transaction.
28    async fn commit(self) -> DbResult<()>;
29
30    /// Rollback the transaction.
31    async fn rollback(self) -> DbResult<()>;
32}