33 lines
731 B
PHP
33 lines
731 B
PHP
|
|
<?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);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|