raku-community-modules / DBIish

Database interface for Raku
89 stars 31 forks source link

Pg transactions? #198

Closed 0rir closed 4 years ago

0rir commented 4 years ago

In the Pg Connect object there appear to be stubs for commit and rollback, but not begin; so no surprise that DBDish::Pg is not handling transactions like P5 DBI did.

My question is does the driver need to handle transactions? More concretely will this approach to transactions work:

use v6.c; use DBIish;

shell 'createdb hell';

my $dbh = DBIish.connect( 'Pg', :database, :AutoCommit(False), :RaiseError(True) ); $dbh.do( 'begin'); $dbh.do( 'create table h (id integer)'); $dbh.do( 'rollback'); $dbh.do( 'begin'); $dbh.do( 'create table h (id integer)'); $dbh.do( 'commit'); $dbh.dispose; exit;

rbt commented 4 years ago

That will work. The driver doesn't do any fiddling at the moment with transactions.

That said, I recommend DBIish::Transaction for Pg. Even if you don't do anything advanced, it guarantees the database gets a ROLLBACK when things go wrong on the Raku side.

https://modules.raku.org/dist/DBIish::Transaction:cpan:RBT