db()->lastInsertId() always returns 0 even after an insert into a table with an AUTO_INCREMENT column (MySQL).
Investigation shows that every call to db() reconnects to the db instead of keeping the existing connection. As a consequence, the value of lastInsertId is not kept by the PDO driver.
This is due to a mistake in src/Db/Core.php, line 361 :
361 if (!($this->connection['default'] ?? false) && $this->config('deferred')) {
shoud be replaced by
361 if (!($this->connections['default'] ?? false) && $this->config('deferred')) {
in order to use the 'default' connection created during a previous call to db().