pg support of duplicate key update

This commit is contained in:
xiaomlove
2026-04-25 03:22:38 +07:00
parent dc77ab7b40
commit 7d18a7f76a
14 changed files with 62 additions and 29 deletions
+2 -2
View File
@@ -244,8 +244,8 @@ class AttendanceRepository extends BaseRepository
return 0;
}
$sql = sprintf(
"insert into `%s` (`uid`, `points`, `date`) values %s on duplicate key update `uid` = values(`uid`)",
$table, implode(',', $insert)
'insert into %s (uid, points, "date") values %s %s',
$table, implode(',', $insert), NexusDB::upsertField(['uid'], ['uid'])
);
NexusDB::statement($sql);
$insertCount = count($insert);
+2 -2
View File
@@ -1049,13 +1049,13 @@ class ExamRepository extends BaseRepository
if ($donateStatus == User::DONATE_YES) {
$baseQuery->where(function (Builder $query) {
$query->where('donor', 'yes')->where(function (Builder $query) {
$query->where('donoruntil', '0000-00-00 00:00:00')->orWhereNull('donoruntil')->orWhere('donoruntil', '>=', Carbon::now());
$query->whereNull('donoruntil')->orWhere('donoruntil', '>=', Carbon::now());
});
});
} elseif ($donateStatus == User::DONATE_NO) {
$baseQuery->where(function (Builder $query) {
$query->where('donor', 'no')->orWhere(function (Builder $query) {
$query->where('donoruntil', '!=','0000-00-00 00:00:00')->whereNotNull('donoruntil')->where('donoruntil', '<', Carbon::now());
$query->whereNotNull('donoruntil')->where('donoruntil', '<', Carbon::now());
});
});
} else {
+1 -1
View File
@@ -400,7 +400,7 @@ class HitAndRunRepository extends BaseRepository
->selectRaw("count(*) as counts, uid")
->where('status', HitAndRun::STATUS_UNREACHED)
->groupBy('uid')
->having("counts", '>=', $disableCounts)
->havingRaw("count(*) >= $disableCounts")
;
if ($setting['diff_in_section']) {
$query->whereHas('torrent.basic_category', function (Builder $query) use ($setting) {
+2 -2
View File
@@ -45,8 +45,8 @@ class SettingRepository extends BaseRepository
return true;
}
$sql = sprintf(
"insert into `%s` (`name`, `value`) values %s on duplicate key update `value` = values(`value`)",
$settingModel->getTable(), implode(', ', $values)
'insert into %s (name, "value") values %s %s',
$settingModel->getTable(), implode(', ', $values), NexusDB::upsertField(['name'], ['value'])
);
$result = DB::insert($sql);
do_log("sql: $sql, result: $result");
+1 -1
View File
@@ -133,7 +133,7 @@ class TagRepository extends BaseRepository
}
$page++;
}
$sql .= sprintf("%s on duplicate key update updated_at = values(updated_at)", implode(', ', $values));
$sql .= sprintf("%s %s", implode(', ', $values), NexusDB::upsertField(['torrent_id', 'tag_id'], ['updated_at']));
do_log("migrate sql: $sql");
NexusDB::statement($sql);
do_log("[MIGRATE_TORRENT_TAG] done!");
+1 -1
View File
@@ -749,7 +749,7 @@ class TorrentRepository extends BaseRepository
$values[] = sprintf("(%s, %s, '%s', '%s')", $torrentId, $tagId, $time, $time);
}
}
$sql .= implode(', ', $values) . " on duplicate key update updated_at = values(updated_at)";
$sql .= implode(', ', $values) . " " . NexusDB::upsertField(['torrent_id', 'tag_id'], ['updated_at']);
if ($remove) {
TorrentTag::query()->whereIn('torrent_id', $idArr)->delete();
}