support pg

This commit is contained in:
xiaomlove
2026-04-15 03:27:30 +07:00
parent 4d54e08918
commit 00fdc2d08f
18 changed files with 129 additions and 59 deletions
+9
View File
@@ -0,0 +1,9 @@
<?php
namespace App\Models;
class Faq extends NexusModel
{
protected $table = 'faq';
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Models;
use App\Models\Traits\NexusActivityLogTrait;
class RegImage extends NexusModel
{
protected $table = 'regimages';
protected $fillable = ['imagehash', 'imagestring', 'dateline'];
}
+23 -1
View File
@@ -5,6 +5,7 @@ namespace App\Models;
use App\Repositories\TagRepository;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Nexus\Database\NexusDB;
class Torrent extends NexusModel
{
@@ -186,6 +187,19 @@ class Torrent extends NexusModel
self::NFO_VIEW_STYLE_WINDOWS => ['text' => 'Windows-vy'],
];
public function scopeWhereInfoHash($query, string $binaryHash)
{
if (NexusDB::isPgsql()) {
return $query->whereRaw(
"info_hash = decode(?, 'hex')",
[bin2hex($binaryHash)]
);
} elseif (NexusDB::isMysql()) {
return $query->where('info_hash', $binaryHash);
}
throw new \RuntimeException("Not supported database");
}
public function getPickInfoAttribute()
{
$info = self::$pickTypes[$this->picktype] ?? null;
@@ -521,8 +535,16 @@ class Torrent extends NexusModel
public function tags(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
$idsString = TagRepository::getOrderByFieldIdString();
if (NexusDB::isPgsql()) {
$orderByRaw = "array_position(ARRAY[$idsString]::int[], tags.id)";
} else if (NexusDB::isMysql()) {
$orderByRaw = "FIELD(tags.id, $idsString)";
} else {
throw new \RuntimeException("Unsupported database");
}
return $this->belongsToMany(Tag::class, 'torrent_tags', 'torrent_id', 'tag_id')
->orderByRaw(sprintf("field(`tags`.`id`,%s)", TagRepository::getOrderByFieldIdString()));
->orderByRaw($orderByRaw);
}
public function reward_logs(): \Illuminate\Database\Eloquent\Relations\HasMany