Files
lucent-laravel/src/Record/RecordRepo.php
T

76 lines
1.8 KiB
PHP
Raw Normal View History

2023-10-02 23:10:49 +03:00
<?php
namespace Lucent\Record;
2024-09-07 13:22:58 +03:00
use Lucent\Database\Database;
2023-10-02 23:10:49 +03:00
class RecordRepo
{
2026-04-20 21:07:35 +03:00
public function __construct() {}
2023-10-02 23:10:49 +03:00
public static function create(Record $record): void
{
$recordToDB = $record->toDB();
2023-10-22 16:09:36 +03:00
2026-04-20 21:07:35 +03:00
Database::make()->table("lucent_records")->insert($recordToDB);
2023-10-02 23:10:49 +03:00
}
/**
* @param array<string> $ids
*/
2023-10-04 13:32:30 +03:00
public static function updateStatusBulk(Status $status, array $ids): void
2023-10-02 23:10:49 +03:00
{
2026-04-20 21:07:35 +03:00
Database::make()
->table("lucent_records")
->whereIn("id", $ids)
->update([
"status" => $status->value,
]);
2023-10-02 23:10:49 +03:00
}
public static function update(Record $record): void
{
$recordToDB = $record->toDB();
2026-04-20 21:07:35 +03:00
Database::make()
->table("lucent_records")
->where("id", $record->id)
->update($recordToDB);
2023-10-02 23:10:49 +03:00
}
/**
* @param string[] $ids
*/
2026-04-20 21:07:35 +03:00
public function deleteMany(array $ids): void
2023-10-02 23:10:49 +03:00
{
2026-04-20 21:07:35 +03:00
Database::make()
->table("lucent_records")
->whereIn("id", $ids)
->delete();
Database::make()
->table("lucent_edges")
->whereIn("source", $ids)
->delete();
Database::make()
->table("lucent_edges")
->whereIn("target", $ids)
->delete();
Database::make()
->table("lucent_revisions")
->whereIn("recordId", $ids)
->delete();
2023-10-02 23:10:49 +03:00
}
2023-10-15 23:40:34 +03:00
2026-04-20 21:07:35 +03:00
public function deleteTrashedBySchema(string $schemaName): void
2023-10-15 23:40:34 +03:00
{
2026-04-20 21:07:35 +03:00
$ids = Database::make()
->table("lucent_records")
2023-10-15 23:40:34 +03:00
->where("schema", $schemaName)
->where("status", Status::TRASHED->value)
2026-04-20 21:07:35 +03:00
->get()
->pluck("id")
->toArray();
2023-10-15 23:40:34 +03:00
$this->deleteMany($ids);
}
2023-10-02 23:10:49 +03:00
}