News in Nette Database 3.1

11 days ago by David Grudl     edit

With an elegant way of working with a transaction comes a new method transaction(). You pass in a callback that runs in the transaction. If any exception is thrown, the transaction is rolled back. If everything goes well, the transaction will be committed.

Method Connection::transaction() returns the value returned by the callback, so you can pass the insert id for example:

$id = $database->transaction(function () use ($database) {
	$database->query('DELETE FROM ...');
	$database->query('INSERT INTO ...');
	// ...
	return $database->getInsertId();
});

Clarity

Because the name Database Explorer has been used for the part of library allowing easy object access to the database, the base class Nette\Database\Context changes its name to Nette\Database\Explorer. Furthermore, Nette gradually leaves the prefix I in the interface names, which also applies to the Database library.

Of course, the original names still work as aliases.

Other Changes

  • The SQL statement translator, which is the heart of the whole library, is a bit more careful and checks the inputs more.
  • MySqlDriver driver uses subqueries.
  • The minimum required version of PHP is 7.2.