records and edgs
This commit is contained in:
+47
-3
@@ -25,7 +25,31 @@ class EdgeRepo
|
||||
|
||||
}
|
||||
|
||||
public function update(string $from, EdgeCollection $edges): void
|
||||
/**
|
||||
* @param list<Edge> $edges
|
||||
* @return void
|
||||
* @throws LucentException
|
||||
*/
|
||||
public function insertMany(array $edges): void
|
||||
{
|
||||
$edgesDB = collect($edges)->map(fn($e) => $e->toDB())->toArray();
|
||||
try {
|
||||
DB::table("edges")->insert($edgesDB);
|
||||
} catch (PDOException $e) {
|
||||
if ($e->getCode() == 23505) {
|
||||
throw new LucentException("Edge already exists");
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $from
|
||||
* @param list<Edge> $edges
|
||||
* @return void
|
||||
*/
|
||||
public function replaceForRecord(string $from, array $edges): void
|
||||
{
|
||||
$edgesDB = collect($edges)->map(fn($e) => $e->toDB())->toArray();
|
||||
DB::table("edges")->where("source", $from)->delete();
|
||||
@@ -33,10 +57,19 @@ class EdgeRepo
|
||||
}
|
||||
|
||||
|
||||
public function findAll(): EdgeCollection
|
||||
/**
|
||||
* @return list<Edge>
|
||||
*/
|
||||
public function findAll(): array
|
||||
{
|
||||
$edges = DB::table("edges")->get();
|
||||
return new EdgeCollection(...$edges->map([$this, 'mapEdge'])->toArray());
|
||||
return $edges->map([$this, 'mapEdge'])->toArray();
|
||||
}
|
||||
|
||||
public function findForSource(string $recordId): array
|
||||
{
|
||||
$edges = DB::table("edges")->where("source", $recordId)->get();
|
||||
return $edges->map([$this, 'mapEdge'])->toArray();
|
||||
}
|
||||
|
||||
public function mapEdge(stdClass $edge): Edge
|
||||
@@ -65,4 +98,15 @@ class EdgeRepo
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function findLastEdgeRank(string $source, string $field): string
|
||||
{
|
||||
$data = DB::table("edges")
|
||||
->where("source", $source)
|
||||
->where("field", $field)
|
||||
->orderBy("rank", "desc")
|
||||
->first();
|
||||
|
||||
return $data->rank ?? "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user