DEV Community

Cover image for Database Transactions Made Simple in Doppar
Francisco Navarro
Francisco Navarro

Posted on

Database Transactions Made Simple in Doppar

When building real-world applications, database transactions are not optional — they’re essential. Whether you’re creating orders, updating records, or syncing data across services, you need consistency, safety, and retries.

If you’re coming from Laravel, you already know how valuable transaction handling is. The good news? Doppar supports transactions just as cleanly — and sometimes even more elegantly.

Let’s take a look.

Declarative Transactions with Attributes

Doppar embraces PHP attributes to keep your code expressive and readable. Instead of wrapping logic inside transaction blocks manually, you declare your intent right where it matters — above your controller method.

Creating an Order (PostgreSQL)

#[Transaction(connection: 'pgsql', attempts: 3)]
#[Route(uri: 'orders', methods: ['POST'])]
public function store()
{
    // pgsql connection + 3 retry attempts
}
Enter fullscreen mode Exit fullscreen mode

What’s happening here?

  • A database transaction is automatically started
  • Uses the PostgreSQL connection
  • Retries the transaction up to 3 times if it fails
  • Commits on success, rolls back on failure
  • Your business logic stays clean and focused

No boilerplate. No manual beginTransaction() or commit() calls.

Updating an Order (MySQL)

#[Transaction(connection: 'mysql', attempts: 3)]
#[Route(uri: 'orders/{id}', methods: ['PUT'])]
public function update()
{
    // mysql connection + 3 retry attempts
}
Enter fullscreen mode Exit fullscreen mode

Why this is powerful

  • You can switch database connections per endpoint
  • Transactions are automatically scoped to the request
  • Failures are retried without extra code
  • Works perfectly for distributed or multi-DB systems

Doppar’s transaction handling gives you enterprise-grade safety without sacrificing developer experience. If you love Laravel’s simplicity but want a lighter, more declarative framework, Doppar delivers — especially when it comes to transactions.

Top comments (0)