---
name: "Mojo::Pg::Transaction"
section: "3pm"
platform: "linux"
package: "libmojo-pg-perl"
version: "4.27-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Mojo::Pg::Transaction"
---

# Mojo::Pg::Transaction(3pm)

Transaction

## NAME

Mojo::Pg::Transaction - Transaction

## SYNOPSIS

```
  use Mojo::Pg::Transaction;
  my $tx = Mojo::Pg::Transaction->new(db => $db);
  $tx->commit;
```

## DESCRIPTION

Mojo::Pg::Transaction is a scope guard for DBD::Pg transactions used by Mojo::Pg::Database.

## ATTRIBUTES

Mojo::Pg::Transaction implements the following attributes.

### db

```
  my $db = $tx->db;
  $tx    = $tx->db(Mojo::Pg::Database->new);
```

Mojo::Pg::Database object this transaction belongs to. Note that this attribute is weakened.

## METHODS

Mojo::Pg::Transaction inherits all methods from Mojo::Base and implements the following new ones.

### commit

```
  $tx->commit;
```

Commit transaction.

### new

```
  my $tx = Mojo::Pg::Transaction->new;
  my $tx = Mojo::Pg::Transaction->new(db => Mojo::Pg::Database->new);
  my $tx = Mojo::Pg::Transaction->new({db => Mojo::Pg::Database->new});
```

Construct a new Mojo::Pg::Transaction object.

## SEE ALSO

Mojo::Pg, Mojolicious::Guides, \<https://mojolicious.org\>.
