graphs
This commit is contained in:
@@ -20,7 +20,7 @@ class UserRepo
|
||||
*/
|
||||
public function all(): Collection
|
||||
{
|
||||
$usersData = DB::table("users")->whereNot("status", "invite")->get();
|
||||
$usersData = DB::table("users")->get();
|
||||
|
||||
$users = array_map(fn($userData) => User::fromArray((array)$userData), $usersData->toArray());
|
||||
return new Collection($users);
|
||||
|
||||
@@ -64,6 +64,7 @@ class RecordController extends Controller
|
||||
->parentsDepth(0)
|
||||
->runWithCount();
|
||||
|
||||
|
||||
$records = $graph->getRootRecords()->toArray();
|
||||
|
||||
|
||||
@@ -330,6 +331,12 @@ class RecordController extends Controller
|
||||
return ok();
|
||||
}
|
||||
|
||||
public function emptyTrash(Request $request){
|
||||
|
||||
$this->recordService->emptyTrash($request->route("schemaName"));
|
||||
return redirect($this->channelService->channel->lucentUrl."/content/".$request->route("schemaName"));
|
||||
}
|
||||
|
||||
public function delete(Request $request)
|
||||
{
|
||||
$ids = $request->input("ids");
|
||||
|
||||
@@ -72,6 +72,7 @@ Route::group([
|
||||
Route::middleware(["lucent.auth"])->prefix("/content")->group(function () {
|
||||
Route::get('/{schemaName}', [RecordController::class, 'index']);
|
||||
Route::get('/{schemaName}/csv', [RecordController::class, 'exportCSV']);
|
||||
Route::get('/{schemaName}/emptyTrash', [RecordController::class, 'emptyTrash']);
|
||||
});
|
||||
|
||||
Route::middleware(["lucent.auth"])->group(function () {
|
||||
|
||||
@@ -11,6 +11,9 @@ use Lucent\Commands\CompileSchemas;
|
||||
use Lucent\Commands\RebuildThumbnails;
|
||||
use Lucent\File\FileService;
|
||||
use Lucent\File\ImageService;
|
||||
use Lucent\Query\DatabaseGraph\DatabaseGraph;
|
||||
use Lucent\Query\DatabaseGraph\PgsqlDatabaseGraph;
|
||||
use Lucent\Query\DatabaseGraph\SqliteDatabaseGraph;
|
||||
|
||||
class LucentServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -27,6 +30,13 @@ class LucentServiceProvider extends ServiceProvider
|
||||
return new ImageManager(['driver' => 'imagick']);
|
||||
});
|
||||
|
||||
$this->app->bind(DatabaseGraph::class, function () {
|
||||
return match (config("database.lucent")) {
|
||||
"sqlite" => new SqliteDatabaseGraph(),
|
||||
"pgsql" => new PgsqlDatabaseGraph(),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -37,9 +47,9 @@ class LucentServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
$manifestPath = public_path('vendor/lucent/dist/manifest.json');
|
||||
$manifest = null;
|
||||
if(file_exists($manifestPath)){
|
||||
$manifest = json_decode(file_get_contents(public_path('vendor/lucent/dist/manifest.json')),true);
|
||||
$manifest = null;
|
||||
if (file_exists($manifestPath)) {
|
||||
$manifest = json_decode(file_get_contents(public_path('vendor/lucent/dist/manifest.json')), true);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +78,7 @@ class LucentServiceProvider extends ServiceProvider
|
||||
]);
|
||||
|
||||
$this->publishes([
|
||||
__DIR__.'/../front/dist' => public_path('vendor/lucent/dist'),
|
||||
__DIR__ . '/../front/dist' => public_path('vendor/lucent/dist'),
|
||||
], 'public');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Query\DatabaseGraph;
|
||||
|
||||
use Lucent\Query\QueryOptions;
|
||||
|
||||
interface DatabaseGraph
|
||||
{
|
||||
/**
|
||||
* @param array<string> $ids
|
||||
*/
|
||||
public function getChildren(array $ids, QueryOptions $options): array;
|
||||
public function getParents(array $ids, QueryOptions $options): array;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Query\DatabaseGraph;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Lucent\Query\QueryOptions;
|
||||
|
||||
class PgsqlDatabaseGraph implements DatabaseGraph
|
||||
{
|
||||
|
||||
/**
|
||||
* @param array<string> $ids
|
||||
*/
|
||||
public function getChildren(array $ids, QueryOptions $options): array
|
||||
{
|
||||
$subquery = DB::table('edges AS g')
|
||||
->select(DB::raw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field, 1 as depth '))
|
||||
->whereIn('source', $ids);
|
||||
|
||||
if (!empty($options->childrenFields)) {
|
||||
$subquery->whereIn('field', $options->childrenFields);
|
||||
}
|
||||
|
||||
$subquery->limit($options->childrenLimit)
|
||||
->unionAll(
|
||||
DB::table(DB::raw("edges AS g, search_graph AS sg "))
|
||||
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth')
|
||||
->whereRaw("g.source = sg.target")
|
||||
->where("depth", "<", $options->childrenDepth)
|
||||
->orderBy("rank")
|
||||
);
|
||||
|
||||
return DB::table('search_graph')
|
||||
// ->select(DB::raw("*, 1 as depth "))
|
||||
->withRecursiveExpression('search_graph', $subquery)
|
||||
->get()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> $ids
|
||||
*/
|
||||
public function getParents(array $ids, QueryOptions $options): array
|
||||
{
|
||||
$subquery = DB::table('edges AS g')
|
||||
->select(DB::raw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field, 1 as depth '))
|
||||
->limit($options->parentsLimit)
|
||||
->whereIn('g.target', $ids)
|
||||
->unionAll(
|
||||
DB::table(DB::raw("edges AS g, search_graph AS sg "))
|
||||
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth')
|
||||
->whereRaw("g.target = sg.source")
|
||||
->where("depth", "<", $options->parentsDepth)
|
||||
->orderBy("rank")
|
||||
);
|
||||
|
||||
return DB::table('search_graph')
|
||||
// ->select(DB::raw('sg.source,sg.target,sg.rank,sg."sourceSchema",sg."targetSchema",sg.field,sg.depth'))
|
||||
->withRecursiveExpression('search_graph', $subquery)
|
||||
->get()->toArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Query\DatabaseGraph;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Lucent\Query\QueryOptions;
|
||||
|
||||
class SqliteDatabaseGraph implements DatabaseGraph
|
||||
{
|
||||
/**
|
||||
* @param array<string> $ids
|
||||
*/
|
||||
public function getChildren(array $ids, QueryOptions $options): array
|
||||
{
|
||||
$subquery = DB::table('edges AS g')
|
||||
->select(DB::raw('g.source,g.target,g.rank,g.sourceSchema,g.targetSchema,g.field, 1 as depth '))
|
||||
->whereIn('source', $ids);
|
||||
|
||||
if (!empty($options->childrenFields)) {
|
||||
$subquery->whereIn('field', $options->childrenFields);
|
||||
}
|
||||
|
||||
$subquery->limit($options->childrenLimit)
|
||||
->unionAll(
|
||||
DB::table(DB::raw("edges AS g, search_graph AS sg "))
|
||||
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth')
|
||||
->whereRaw("g.source = sg.target")
|
||||
->where("depth", "<", $options->childrenDepth)
|
||||
->orderBy("rank")
|
||||
);
|
||||
|
||||
return DB::table('search_graph')
|
||||
// ->select(DB::raw("*, 1 as depth "))
|
||||
->withRecursiveExpression('search_graph', $subquery)
|
||||
->get()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> $ids
|
||||
*/
|
||||
public function getParents(array $ids, QueryOptions $options): array
|
||||
{
|
||||
$subquery = DB::table('edges AS g')
|
||||
->select(DB::raw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field, 1 as depth '))
|
||||
->limit($options->parentsLimit)
|
||||
->whereIn('g.target', $ids)
|
||||
->unionAll(
|
||||
DB::table(DB::raw("edges AS g, search_graph AS sg "))
|
||||
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth')
|
||||
->whereRaw("g.target = sg.source")
|
||||
->where("depth", "<", $options->parentsDepth)
|
||||
->orderBy("rank")
|
||||
);
|
||||
|
||||
return DB::table('search_graph')
|
||||
// ->select(DB::raw('sg.source,sg.target,sg.rank,sg."sourceSchema",sg."targetSchema",sg.field,sg.depth'))
|
||||
->withRecursiveExpression('search_graph', $subquery)
|
||||
->get()->toArray();
|
||||
}
|
||||
}
|
||||
+4
-37
@@ -6,6 +6,7 @@ use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Lucent\Edge\Edge;
|
||||
use Lucent\Primitive\Collection;
|
||||
use Lucent\Query\DatabaseGraph\DatabaseGraph;
|
||||
use Lucent\Query\Filter\AndFilter;
|
||||
use Lucent\Query\Filter\OrFilter;
|
||||
use Lucent\Record\InputFormatter;
|
||||
@@ -24,6 +25,7 @@ final class Query
|
||||
public function __construct(
|
||||
public readonly FilterParser $filterParser,
|
||||
public readonly InputFormatter $inputFormatter,
|
||||
public readonly DatabaseGraph $databaseGraph,
|
||||
)
|
||||
{
|
||||
$this->options = new QueryOptions();
|
||||
@@ -156,47 +158,12 @@ final class Query
|
||||
private
|
||||
function getChildren(array $ids): array
|
||||
{
|
||||
$subquery = DB::table('edges AS g')
|
||||
->select(DB::raw('g.source,g.target,g.rank,g.sourceSchema,g.targetSchema,g.field, 1 as depth '))
|
||||
->whereIn('source', $ids);
|
||||
|
||||
if (!empty($this->options->childrenFields)) {
|
||||
$subquery->whereIn('field', $this->options->childrenFields);
|
||||
}
|
||||
|
||||
$subquery->limit($this->options->childrenLimit)
|
||||
->unionAll(
|
||||
DB::table(DB::raw("edges AS g, search_graph AS sg "))
|
||||
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth')
|
||||
->whereRaw("g.source = sg.target")
|
||||
->where("depth", "<", $this->options->childrenDepth)
|
||||
->orderBy("rank")
|
||||
);
|
||||
|
||||
return DB::table('search_graph')
|
||||
// ->select(DB::raw("*, 1 as depth "))
|
||||
->withRecursiveExpression('search_graph', $subquery)
|
||||
->get()->toArray();
|
||||
return $this->databaseGraph->getChildren($ids, $this->options);
|
||||
}
|
||||
|
||||
private function getParents(array $ids): array
|
||||
{
|
||||
$subquery = DB::table('edges AS g')
|
||||
->select(DB::raw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field, 1 as depth '))
|
||||
->limit($this->options->parentsLimit)
|
||||
->whereIn('g.target', $ids)
|
||||
->unionAll(
|
||||
DB::table(DB::raw("edges AS g, search_graph AS sg "))
|
||||
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth')
|
||||
->whereRaw("g.target = sg.source")
|
||||
->where("depth", "<", $this->options->parentsDepth)
|
||||
->orderBy("rank")
|
||||
);
|
||||
|
||||
return DB::table('search_graph')
|
||||
// ->select(DB::raw('sg.source,sg.target,sg.rank,sg."sourceSchema",sg."targetSchema",sg.field,sg.depth'))
|
||||
->withRecursiveExpression('search_graph', $subquery)
|
||||
->get()->toArray();
|
||||
return $this->databaseGraph->getParents($ids, $this->options);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -48,4 +48,16 @@ class RecordRepo
|
||||
DB::table("edges")->whereIn("target", $ids)->delete();
|
||||
DB::table("revisions")->whereIn("recordId", $ids)->delete();
|
||||
}
|
||||
|
||||
public function deleteTrashedBySchema(
|
||||
string $schemaName,
|
||||
): void
|
||||
{
|
||||
$ids = DB::table("records")
|
||||
->where("schema", $schemaName)
|
||||
->where("status", Status::TRASHED->value)
|
||||
->get()->pluck("id")->toArray();
|
||||
|
||||
$this->deleteMany($ids);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,6 +226,15 @@ readonly class RecordService
|
||||
$this->recordRepo->deleteMany($recordsIds);
|
||||
}
|
||||
|
||||
public function emptyTrash(
|
||||
string $schemaName,
|
||||
): void
|
||||
{
|
||||
|
||||
$schema = $this->channelService->getSchema($schemaName)->get();
|
||||
$this->recordRepo->deleteTrashedBySchema($schemaName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws LucentException
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
<title>@yield('title') - Lucent Data Platform</title>
|
||||
<!-- if development -->
|
||||
@php
|
||||
echo '<script type="module" crossorigin src="http://127.0.0.1:5173/@vite/client"></script>';
|
||||
@endphp
|
||||
<script type="module" crossorigin src="http://127.0.0.1:5173/main.js"></script>
|
||||
{{-- @php--}}
|
||||
{{-- echo '<script type="module" crossorigin src="http://127.0.0.1:5173/@vite/client"></script>';--}}
|
||||
{{-- @endphp--}}
|
||||
{{-- <script type="module" crossorigin src="http://127.0.0.1:5173/main.js"></script>--}}
|
||||
<!-- if production -->
|
||||
{{-- <link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />--}}
|
||||
{{-- <script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>--}}
|
||||
<link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />
|
||||
<script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>
|
||||
|
||||
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
||||
|
||||
Reference in New Issue
Block a user