alaisi / postgres-async-driver

Asynchronous PostgreSQL Java driver
Apache License 2.0
287 stars 38 forks source link

Automatic Transaction commit #28

Open ufoscout opened 8 years ago

ufoscout commented 8 years ago

I wonder if it possible to auto commit a transaction without the need for calling tx.commit(). For example, instead of this:

db.begin()
    .flatMap(tx -> tx.querySet("insert into products (name) values ($1) returning id", "saw")
        .map(productsResult -> productsResult.row(0).getLong("id"))
        .flatMap(id -> tx.querySet("insert into promotions (product_id) values ($1)", id))
        .flatMap(promotionsResult -> tx.commit())
    ).subscribe(
        __ -> System.out.println("Transaction committed"),
        Throwable::printStackTrace);

would it be possible to have this:

boolean autoCommit = true;
db.begin(autoCommit)
    .flatMap(tx -> tx.querySet("insert into products (name) values ($1) returning id", "saw")
        .map(productsResult -> productsResult.row(0).getLong("id"))
        .flatMap(id -> tx.querySet("insert into promotions (product_id) values ($1)", id))
    ).subscribe(
        __ -> System.out.println("Transaction committed"),
        Throwable::printStackTrace);