Files
lucent-laravel/src/Edge/EdgeRepo.php
T

33 lines
731 B
PHP
Raw Normal View History

2023-10-02 23:10:49 +03:00
<?php namespace Lucent\Edge;
use Illuminate\Support\Facades\DB;
use Lucent\LucentException;
use PDOException;
class EdgeRepo
{
public static function insert(Edge $edge): void
{
try {
DB::table("edges")->insert($edge->toDB());
} catch (PDOException $e) {
if ($e->getCode() == 23505) {
throw new LucentException("Edge already exists");
}
throw $e;
}
}
public static function update(string $from, EdgeCollection $edges): void
{
$edgesDB = collect($edges)->map(fn($e) => $e->toDB())->toArray();
DB::table("edges")->where("source", $from)->delete();
DB::table("edges")->insert($edgesDB);
}
}