Skip to content

Commit or rollback a connection pool #218

Open
@CromFr

Description

@CromFr

I'm trying to use manual commit / rollback with a MySQL connection pool, but I can't find a reasonable way to send the "COMMIT" / "ROLLBACK" statements to all used connections in the pool.

auto connPool = new MySQLPool("...");
connPool.onNewConnection = delegate(conn){
	conn.exec("SET autocommit=0");
};

// Lock several connections and send transactions
// [...]

// I'd like to do something like this:
writeln("Apply transactions? (y/n)");
if(readln() == "y\n")
	connPool.execAll("COMMIT");
else
	connPool.execAll("ROLLBACK");

// or this:
if(readln() == "y\n")
	foreach(ref conn ; connPool.connections)
		conn.exec("COMMIT");
else
	foreach(ref conn ; connPool.connections)
		conn.exec("ROLLBACK");

Is there something I'm missing?

I'm willing to send you a PR if we agree on a simple solution ;)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions