<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Nette Framework forum : Development of Nette Framework : Discussion on development : Please test Nette Database 3.3 RC</title>
<link>https://forum.nette.org/en</link>
<description>Nette Framework forum</description>
<language>en</language>
<docs>http://backend.userland.com/rss</docs>
<item>
	<title>Please test Nette Database 3.3 RC (Discussion on development)</title>
	<dc:creator>David Grudl</dc:creator>
	<link>https://forum.nette.org/en/36997#p229156</link>
	<guid isPermaLink="false">229156@http://forum.nette.org/en</guid>
	<description>&lt;p&gt;Hi, I&apos;ve released &lt;strong&gt;nette/database 3.3.0-RC1&lt;/strong&gt; and I&apos;d like to
ask you to test it. It brings some great new features, but what I care about
most is whether your existing code still works with it, especially inserting
rows, where the behavior of &lt;code&gt;insert()&lt;/code&gt; has changed.&lt;/p&gt;

&lt;pre
class=&quot;language-bash&quot;&gt;&lt;code&gt;composer require nette/database:^3.3.0-RC1&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It requires &lt;strong&gt;PHP 8.4&lt;/strong&gt; or newer and Tracy 2.12.&lt;/p&gt;

&lt;h4&gt;insert() and insertMany()&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;insert()&lt;/code&gt; has always returned the inserted row as an
&lt;code&gt;ActiveRow&lt;/code&gt;. To do that, it sent a &lt;code&gt;SELECT&lt;/code&gt; right after
the &lt;code&gt;INSERT&lt;/code&gt;, even when you never used the result. And that&apos;s a very
common case: you insert a row and do nothing more with it, or read its ID
at most.&lt;/p&gt;

&lt;p&gt;Now the row is loaded lazily. For a table with an integer primary key
(typically an auto-increment ID), the returned object holds only the ID and
sends the &lt;code&gt;SELECT&lt;/code&gt; only when you touch one of the other columns. If
you don&apos;t read the row, no extra query is sent:&lt;/p&gt;

&lt;pre
class=&quot;language-php&quot;&gt;&lt;code&gt;$row = $explorer-&amp;gt;table(&apos;users&apos;)-&amp;gt;insert([
	&apos;name&apos; =&amp;gt; &apos;John Doe&apos;,
	&apos;email&apos; =&amp;gt; &apos;john.doe@example.com&apos;,
]);
echo $row-&amp;gt;id;         // no extra query
echo $row-&amp;gt;created_at; // only now is the row loaded from the database&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So most inserts are now one query cheaper. But this touches a method that
pretty much every application uses, which is why I&apos;d love you to try it on your
own code.&lt;/p&gt;

&lt;p&gt;The values still come from the database, not from the array you passed in,
because the database may have changed them (column type, default value,
trigger). When the row can&apos;t be identified by its primary key (the table has
none, or part of a composite key is missing), &lt;code&gt;insert()&lt;/code&gt; now
returns &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To insert several rows in a single query, there&apos;s the new
&lt;code&gt;insertMany()&lt;/code&gt;, which returns the number of inserted rows:&lt;/p&gt;

&lt;pre
class=&quot;language-php&quot;&gt;&lt;code&gt;$count = $explorer-&amp;gt;table(&apos;users&apos;)-&amp;gt;insertMany([
	[&apos;name&apos; =&amp;gt; &apos;John&apos;, &apos;year&apos; =&amp;gt; 1994],
	[&apos;name&apos; =&amp;gt; &apos;Jack&apos;, &apos;year&apos; =&amp;gt; 1995],
]);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Passing several rows (or a &lt;code&gt;Selection&lt;/code&gt;) directly to
&lt;code&gt;insert()&lt;/code&gt; is &lt;strong&gt;deprecated&lt;/strong&gt;. It still works exactly as
before, it just emits a deprecation notice, so you can switch to
&lt;code&gt;insertMany()&lt;/code&gt; whenever it suits you.&lt;/p&gt;

&lt;h4&gt;Other behavior changes&lt;/h4&gt;

&lt;p&gt;Most applications won&apos;t notice them, but just in case:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;&lt;code&gt;ResultSet::fetch()&lt;/code&gt; consumes the row, so a following
	&lt;code&gt;foreach&lt;/code&gt; or &lt;code&gt;fetchAll()&lt;/code&gt; starts with the next one.
	Previously it returned that row again.&lt;/li&gt;

	&lt;li&gt;&lt;code&gt;min()&lt;/code&gt;, &lt;code&gt;max()&lt;/code&gt; and &lt;code&gt;sum()&lt;/code&gt; over an empty
	group in &lt;code&gt;GroupedSelection&lt;/code&gt; return &lt;code&gt;null&lt;/code&gt; instead of
	&lt;code&gt;0&lt;/code&gt;, just like SQL and a plain &lt;code&gt;Selection&lt;/code&gt; do.&lt;/li&gt;

	&lt;li&gt;A multi-insert via &lt;code&gt;?values&lt;/code&gt; warns when the rows don&apos;t have the
	same columns. Previously a missing value was silently filled with NULL and an
	extra column dropped.&lt;/li&gt;

	&lt;li&gt;A custom driver has to return the &lt;code&gt;scale&lt;/code&gt; key from
	&lt;code&gt;getColumns()&lt;/code&gt; as well.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The full list is in &lt;a
href=&quot;https://github.com/nette/database/blob/v3.3/docs/upgrading.md&quot;&gt;upgrading.md&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;What&apos;s new&lt;/h4&gt;

&lt;p&gt;There&apos;s quite a lot of new stuff this time and I think you&apos;re going to love
it. I&apos;ll introduce it properly in a blog post, so here&apos;s just a taste:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;&lt;strong&gt;entity mapping&lt;/strong&gt;: Explorer can return rows as your own
	classes (&lt;code&gt;ProductRow&lt;/code&gt; extending &lt;code&gt;ActiveRow&lt;/code&gt;) and
	optionally translate a &lt;code&gt;created_at&lt;/code&gt; column to a
	&lt;code&gt;$row-&amp;gt;createdAt&lt;/code&gt; property&lt;/li&gt;

	&lt;li&gt;&lt;code&gt;transaction()&lt;/code&gt; can automatically retry the whole transaction
	after a deadlock or a lock timeout&lt;/li&gt;

	&lt;li&gt;AI agents can now read the Tracy panel too, plus
	&lt;code&gt;isInTransaction()&lt;/code&gt; and a few smaller things&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can read about all of it in the &lt;a
href=&quot;https://doc.nette.org/en/database&quot;&gt;documentation&lt;/a&gt; today, for example &lt;a
href=&quot;https://doc.nette.org/en/database/mapping&quot;&gt;entity mapping&lt;/a&gt; or &lt;a
href=&quot;https://doc.nette.org/en/database/transactions&quot;&gt;retrying
transactions&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Just install the RC, clear the cache and click through your application, or
run your tests. If something stops working or you run into unexpected
deprecation notices or warnings, please let me know. Thanks!&lt;/p&gt;
</description>
	<pubDate>Thu, 03 Dec 2026 08:02:21 +0100</pubDate>
</item>
</channel>
</rss>
