by jay patel
Laravel 5.7.17 is accessible with new query builder methods, a new message for detecting lost connections in MariaDB, and improvements to adding foreign keys in Postgres.
First, we have a new method in the query builder for the INSERT INTO SELECT statement, without loading data into memory. The insertUsing() method allows you to copy all (or some) columns from one database table to another using the following syntax:
$builder-> from ( ' table1 ' )-> insertUsing (
[ ' foo ' ] ,
function ( Builder $query ) {
$query-> select ( [ ' bar ' ] ) -> from ( ' table2 ' ) -> where ( ' foreign_id ' , ' = ', 5 ) ;
}
) ;
An example of the SQL INSERT INTO SELECT Statement might look like this:
INSERT INTO table2 ( column1 , column2 , column3 , ... )
SELECT column1 , column2 , column3 , ...
FROM table1
WHERE condition ;
Next, the query builder has a new havingBetween method for the SQL HAVING clause between two values:
$builder
-> select ( ' * ' )
-> from ( ' users ' )
-> havingBetween ( ' last_login_date ' , [ ' 2018-11-16' , ' 2018-12-16 ' ] ) ;
Which produces the following query:
select * from " users " having " last_login_date " between ? and ?
The next feature is not as glamorous but under the hood of the
DetectsLostConnections database trait, the new message “Packets out of order. Expected”. In MariaDB, exceptions like “Packets out of order. Expected 1 received 0. Packet size=30” can have an “Expected” value of more than one, so this message matches the various error messages for the “Packets out of order” exception.
The last new feature in Laravel 5.7.17 is another “behind the scenes” contribution which adds a “not valid” option for skipping validation when adding Postgres foreign keys.
Your email address will not be published. Required fields are marked *