feat: adding initial uuid support

This commit is contained in:
dswbx
2025-06-06 20:46:01 +02:00
parent abbd372ddf
commit 9a18e354cd
22 changed files with 184 additions and 52 deletions

View File

@@ -9,6 +9,7 @@ import {
import type { RepoQuery } from "../server/query";
import type { RelationType } from "./relation-types";
import * as tbbox from "@sinclair/typebox";
import type { PrimaryFieldType } from "core";
const { Type } = tbbox;
const directions = ["source", "target"] as const;
@@ -72,7 +73,7 @@ export abstract class EntityRelation<
reference: string,
): KyselyQueryBuilder;
getReferenceQuery(entity: Entity, id: number, reference: string): Partial<RepoQuery> {
getReferenceQuery(entity: Entity, id: PrimaryFieldType, reference: string): Partial<RepoQuery> {
return {};
}

View File

@@ -1,6 +1,6 @@
import { type Static, StringEnum } from "core/utils";
import type { EntityManager } from "../entities";
import { Field, baseFieldConfigSchema } from "../fields";
import { Field, baseFieldConfigSchema, primaryFieldTypes } from "../fields";
import type { EntityRelation } from "./EntityRelation";
import type { EntityRelationAnchor } from "./EntityRelationAnchor";
import * as tbbox from "@sinclair/typebox";
@@ -15,6 +15,7 @@ export const relationFieldConfigSchema = Type.Composite([
reference: Type.String(),
target: Type.String(), // @todo: potentially has to be an instance!
target_field: Type.Optional(Type.String({ default: "id" })),
target_field_type: Type.Optional(StringEnum(["integer", "text"], { default: "integer" })),
on_delete: Type.Optional(StringEnum(CASCADES, { default: "set null" })),
}),
]);
@@ -45,6 +46,7 @@ export class RelationField extends Field<RelationFieldConfig> {
reference: target.reference,
target: target.entity.name,
target_field: target.entity.getPrimaryField().name,
target_field_type: target.entity.getPrimaryField().fieldType,
});
}
@@ -63,7 +65,7 @@ export class RelationField extends Field<RelationFieldConfig> {
override schema() {
return Object.freeze({
...super.schema()!,
type: "integer",
type: this.config.target_field_type ?? "integer",
references: `${this.config.target}.${this.config.target_field}`,
onDelete: this.config.on_delete ?? "set null",
});