query records

This commit is contained in:
2026-01-12 20:47:53 +02:00
parent 178b9309ec
commit 25d3b525f6
7 changed files with 109 additions and 32 deletions
+46 -1
View File
@@ -5,6 +5,7 @@ use Lucent\Core\Data\RecordPreview;
use Lucent\Core\Data\QueryRecord;
use Lucent\Core\Data\RecordMode;
use Lucent\Core\Record\RecordModule;
use Lucent\Core\Edge\EdgeModule;
use Lucent\Core\Record\RecordFieldModule;
use stdClass;
@@ -61,8 +62,47 @@ class QueryModule
->map(RecordFieldModule::fromDb(...))
->toArray();
$recordEdges = DB::table("edges")
->select(
"edges.*",
"records.id as record_id",
"records.schema_id as record_schema_id",
"records_data.value as record_title",
)
->whereIn("edges.from", $recordIds)
->whereIn("edges.field_id", $columns)
->join("records", "edges.to", "=", "records.id")
->join("records_data", function ($join) {
$join
->on("records.id", "=", "records_data.record_id")
->on(
"records.title_field_id",
"=",
"records_data.field_id",
);
})
->where("edges.mode", "=", RecordMode::DRAFT)
->where("edges.locale", "=", "main")
->where("records_data.mode", "=", RecordMode::DRAFT)
->where("records_data.locale", "=", "main")
->orderBy("edges.rank", "asc")
->distinct()
->get()
->map(
fn($row) => RecordModule::edgeRecordPreviewFromDb(
$schemas,
$row,
),
)
->toArray();
return $records->map(
fn($row) => static::fromDB($row, $schemas, $recordData),
fn($row) => static::fromDB(
$row,
$schemas,
$recordData,
$recordEdges,
),
);
}
@@ -95,6 +135,7 @@ class QueryModule
stdClass $row,
$schemas,
array $recordData,
array $recordEdges,
): QueryRecord {
return new QueryRecord(
null,
@@ -111,6 +152,10 @@ class QueryModule
->where("recordId", $row->id)
->values()
->toArray(),
collect($recordEdges)
->where("edge.from", $row->id)
->values()
->toArray(),
);
}
}