diff options
author | Tim Starling <tstarling@wikimedia.org> | 2023-09-08 10:06:59 +1000 |
---|---|---|
committer | Tim Starling <tstarling@wikimedia.org> | 2023-09-08 10:16:08 +1000 |
commit | 95bd40b25cd6eea81c39d0e88170a214520f7c77 (patch) | |
tree | 5eb0426f77cbf2bde662dd2646dc55dfc79424ba /includes/SiteStats/SiteStatsInit.php | |
parent | 7bbc107f164a3ddc20641471b08380794559e53a (diff) | |
download | mediawikicore-95bd40b25cd6eea81c39d0e88170a214520f7c77.tar.gz mediawikicore-95bd40b25cd6eea81c39d0e88170a214520f7c77.zip |
In query builders, use insertInto() and deleteFrom() instead of insert() and delete()
The design principle for SelectQueryBuilder was to make the chained
builder calls look as much like SQL as possible, so that developers
could leverage their knowledge of SQL to understand what the query
builder is doing.
That's why SelectQueryBuilder::select() takes a list of fields, and by
the same principle, it makes sense for UpdateQueryBuilder::update() to
take a table. However with "insert" and "delete", the SQL designers
chose to add prepositions "into" and "from", and I think it makes sense
to follow that here.
In terms of natural language, we update a table, but we don't delete a
table, or insert a table. We delete rows from a table, or insert rows
into a table. The table is not the object of the verb.
So, add insertInto() as an alias for insert(), and add deleteFrom() as
an alias for delete(). Use the new methods in MW core callers where
PHPStorm knows the type.
Change-Id: Idb327a54a57a0fb2288ea067472c1e9727016000
Diffstat (limited to 'includes/SiteStats/SiteStatsInit.php')
-rw-r--r-- | includes/SiteStats/SiteStatsInit.php | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/includes/SiteStats/SiteStatsInit.php b/includes/SiteStats/SiteStatsInit.php index ba16f5974cdb..84d7182f29c6 100644 --- a/includes/SiteStats/SiteStatsInit.php +++ b/includes/SiteStats/SiteStatsInit.php @@ -166,7 +166,7 @@ class SiteStatsInit { $exists = (bool)$dbw->selectField( 'site_stats', '1', [ 'ss_row_id' => 1 ], __METHOD__ ); if ( !$exists ) { $dbw->newInsertQueryBuilder() - ->insert( 'site_stats' ) + ->insertInto( 'site_stats' ) ->ignore() ->row( [ 'ss_row_id' => 1 ] + array_fill_keys( SiteStats::selectFields(), 0 ) ) ->caller( __METHOD__ )->execute(); @@ -199,7 +199,7 @@ class SiteStatsInit { ]; $row = [ 'ss_row_id' => $i ] + $set; self::getDB( DB_PRIMARY )->newInsertQueryBuilder() - ->insert( 'site_stats' ) + ->insertInto( 'site_stats' ) ->row( $row ) ->onDuplicateKeyUpdate() ->uniqueIndexFields( [ 'ss_row_id' ] ) @@ -217,7 +217,7 @@ class SiteStatsInit { $row = [ 'ss_row_id' => 1 ] + $set; self::getDB( DB_PRIMARY )->newInsertQueryBuilder() - ->insert( 'site_stats' ) + ->insertInto( 'site_stats' ) ->row( $row ) ->onDuplicateKeyUpdate() ->uniqueIndexFields( [ 'ss_row_id' ] ) |