Newer
Older
NocodeToolOnRDL / src / types / table.ts
@Sakoda2269 Sakoda2269 12 days ago 878 bytes initial commit

export const DataType =  {
    String: "string",
    Int: "int"
} as const;

export type DataType = typeof DataType[keyof typeof DataType];

export function translateDataType(dataType: DataType): string {
    switch (dataType) {
        case DataType.String: return "文字列"
        case DataType.Int: return "整数"
    }
}

export interface TableData {
    _id: string,
    projectId: string,
    name: string,
    columns: Column[]
}

export interface Table {
    id: string,
    name: string,
    columns: Column[]
}

export function fromTableData(tableData: TableData): Table {
    return {
        id: tableData._id,
        name: tableData.name,
        columns: tableData.columns
    }
}

export interface Column {
    name: string, //unique
    isPrimary: boolean,
    type: DataType | "foreign",
    foreignTableName?: string,
    foreignTableColumns?: string[]
}