boboko lulnar
This commit is contained in:
+35
-23
@@ -6,16 +6,13 @@ use Lucent\Database\Database;
|
||||
|
||||
class RecordRepo
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
public function __construct() {}
|
||||
|
||||
public static function create(Record $record): void
|
||||
{
|
||||
$recordToDB = $record->toDB();
|
||||
|
||||
Database::make()->table("records")->insert($recordToDB);
|
||||
|
||||
Database::make()->table("lucent_records")->insert($recordToDB);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,40 +20,55 @@ class RecordRepo
|
||||
*/
|
||||
public static function updateStatusBulk(Status $status, array $ids): void
|
||||
{
|
||||
Database::make()->table("records")->whereIn("id", $ids)->update([
|
||||
'status' => $status->value
|
||||
]);
|
||||
Database::make()
|
||||
->table("lucent_records")
|
||||
->whereIn("id", $ids)
|
||||
->update([
|
||||
"status" => $status->value,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function update(Record $record): void
|
||||
{
|
||||
$recordToDB = $record->toDB();
|
||||
Database::make()->table("records")->where("id", $record->id)->update($recordToDB);
|
||||
Database::make()
|
||||
->table("lucent_records")
|
||||
->where("id", $record->id)
|
||||
->update($recordToDB);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string[] $ids
|
||||
*/
|
||||
public function deleteMany(
|
||||
array $ids,
|
||||
): void
|
||||
public function deleteMany(array $ids): void
|
||||
{
|
||||
|
||||
Database::make()->table("records")->whereIn("id", $ids)->delete();
|
||||
Database::make()->table("edges")->whereIn("source", $ids)->delete();
|
||||
Database::make()->table("edges")->whereIn("target", $ids)->delete();
|
||||
Database::make()->table("revisions")->whereIn("recordId", $ids)->delete();
|
||||
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();
|
||||
}
|
||||
|
||||
public function deleteTrashedBySchema(
|
||||
string $schemaName,
|
||||
): void
|
||||
public function deleteTrashedBySchema(string $schemaName): void
|
||||
{
|
||||
$ids = Database::make()->table("records")
|
||||
$ids = Database::make()
|
||||
->table("lucent_records")
|
||||
->where("schema", $schemaName)
|
||||
->where("status", Status::TRASHED->value)
|
||||
->get()->pluck("id")->toArray();
|
||||
->get()
|
||||
->pluck("id")
|
||||
->toArray();
|
||||
|
||||
$this->deleteMany($ids);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user