coleifer/peewee — pull request #268 by jhorman (2013-12-06 18:51:37+00:00)
Title: Adds support for nested transactions to postgres via savepoints

Postgres supports nested transactions by way of savepoints.

http://www.postgresql.org/docs/8.1/static/sql-savepoint.html

An example usage is

BEGIN;
INSERT INTO table1 VALUES (1);
SAVEPOINT my_savepoint;
INSERT INTO table1 VALUES (2);
ROLLBACK TO SAVEPOINT my_savepoint;
INSERT INTO table1 VALUES (3);
COMMIT;

This patch adds savepoint support to the peewee PostgresqlDatabase. As is, PostgresqlDatabase doesn't implement begin, or support nested transactions. Nested transactions will only setup/rollback/release savepoints, the outermost transaction will do the commit/rollback.

begin: now creates a savepoint, and increments the nesting depth.
commit: releases the savepoint, and calls commit if not still nested.
rollback: rolls back to the savepoint, and calls rollback if not still nested.