feat(analytics): add Projection type and use typed projections in models and table creation

This commit is contained in:
Nawaz Dhandala
2025-10-21 15:46:57 +01:00
parent 8c6bc331a4
commit c9e57fcb19
3 changed files with 13 additions and 7 deletions

View File

@@ -3,6 +3,7 @@ import Route from "../../../Types/API/Route";
import AnalyticsTableEngine from "../../../Types/AnalyticsDatabase/AnalyticsTableEngine";
import AnalyticsTableColumn from "../../../Types/AnalyticsDatabase/TableColumn";
import TableColumnType from "../../../Types/AnalyticsDatabase/TableColumnType";
import Projection from "../../../Types/AnalyticsDatabase/Projection";
import {
ColumnAccessControl,
TableAccessControl,
@@ -40,7 +41,7 @@ export default class AnalyticsBaseModel extends CommonModel {
enableWorkflowOn?: EnableWorkflowOn | undefined;
enableRealtimeEventsOn?: EnableRealtimeEventsOn | undefined;
partitionKey: string;
projections: Array<string> | undefined;
projections?: Array<Projection> | undefined;
}) {
super({
tableColumns: data.tableColumns,
@@ -252,11 +253,11 @@ export default class AnalyticsBaseModel extends CommonModel {
this._crudApiPath = v;
}
private _projections: Array<string> = [];
public get projections(): Array<string> {
private _projections: Array<Projection> = [];
public get projections(): Array<Projection> {
return this._projections;
}
public set projections(v: Array<string>) {
public set projections(v: Array<Projection>) {
this._projections = v;
}

View File

@@ -0,0 +1,4 @@
export default interface Projection {
name: string;
query: string;
}

View File

@@ -1,4 +1,5 @@
import { AnalyticsServices } from "Common/Server/Services/Index";
import Projection from "Common/Types/AnalyticsDatabase/Projection";
export default class AnalyticsTableManagement {
public static async createTables(): Promise<void> {
@@ -8,14 +9,14 @@ export default class AnalyticsTableManagement {
service.statementGenerator.toTableCreateStatement(),
);
const projections: Array<string> = service.model.projections;
const projections: Array<Projection> = service.model.projections;
for (const projection of projections) {
if (!projection || projection.trim().length === 0) {
if (!projection.query || projection.query.trim().length === 0) {
continue;
}
await service.execute(projection);
await service.execute(projection.query);
}
}
}