51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Lucent\Record;
|
||
|
|
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
|
||
|
|
class RecordRepo
|
||
|
|
{
|
||
|
|
|
||
|
|
|
||
|
|
public static function create(Record $record): void
|
||
|
|
{
|
||
|
|
$recordToDB = $record->toDB();
|
||
|
|
DB::table("records")->insert($recordToDB);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param array<string> $ids
|
||
|
|
*/
|
||
|
|
public static function updateStatusBulk(RecordStatus $status, array $ids): void
|
||
|
|
{
|
||
|
|
DB::table("records")->whereIn("id", $ids)->update([
|
||
|
|
'_sys->status' => $status->value()
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function update(Record $record): void
|
||
|
|
{
|
||
|
|
|
||
|
|
$recordToDB = $record->toDB();
|
||
|
|
DB::table("records")->where("id", $record->id)->update($recordToDB);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param string[] $ids
|
||
|
|
*/
|
||
|
|
public static function deleteMany(
|
||
|
|
array $ids,
|
||
|
|
): void
|
||
|
|
{
|
||
|
|
|
||
|
|
DB::table("records")
|
||
|
|
->whereIn("id", $ids)->delete();
|
||
|
|
DB::table("edges")->whereIn("source", $ids)->delete();
|
||
|
|
DB::table("edges")->whereIn("target", $ids)->delete();
|
||
|
|
DB::table("revisions")->whereIn("recordId", $ids)->delete();
|
||
|
|
}
|
||
|
|
}
|