init
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user