Fix incorrect title in Transactions.pod
[dbsrgits/DBIx-Class-Manual-SQLHackers.git] / lib / DBIx / Class / Manual / SQLHackers / Transactions.pod
CommitLineData
6c2a4396 1=head1 NAME
2
bf3e7004 3DBIx::Class::Manual::SQLHackers::Transactions - DBIx::Class for SQL Hackers - DELETE
6c2a4396 4
5=over
6
7=item L<Introduction|DBIx::Class::Manual::SQLHackers::Introduction>
8
9=item L<CREATE|DBIx::Class::Manual::SQLHackers::CREATE>
10
11=item L<INSERT|DBIx::Class::Manual::SQLHackers::INSERT>
12
13=item L<SELECT|DBIx::Class::Manual::SQLHackers::SELECT>
14
15=item L<UPDATE|DBIx::Class::Manual::SQLHackers::UPDATE>
16
17=item L<DELETE|DBIx::Class::Manual::SQLHackers::DELETE>
18
19=item BEGIN, COMMIT
20
21=back
22
23=head1 Transactions
24
25 BEGIN;
26 SELECT users.id, users.username FROM users WHERE id = 1;
27 UPDATE users SET username = 'fred' WHERE id = 1;
28 COMMIT;
29
2f41b1a9 30To create a transaction, put all your changes inside a coderef, and pass it to the B<txn_do> method on the Schema object. Transactions can also be safely nested,
31in which case all but the top level transaction blocks become noops.
6c2a4396 32
33=over
34
35=item 1. Create a Schema object representing the database you are working with:
36
37 my $schema = MyDatabase::Schema->connect('dbi:SQLite:my.db');
38
39=item 2. Call the B<txn_do> method on the Schema object:
40
41 $schema->txn_do( sub {
42 my $user = $schema->resultset('User')->find({ id => 1 });
43 die if(!$user);
44 $user->update({ username => 'fred' });
45 } );
46
47=back
48