From a13da7848e56fcc5e3d2c7f079a18a3b23a4755a Mon Sep 17 00:00:00 2001 From: Kononnable Date: Thu, 26 Sep 2019 20:35:10 +0200 Subject: [PATCH] new model files --- src/models/Column.ts | 33 +++++++++++++++++++++++++++++++++ src/models/Entity.ts | 15 +++++++++++++++ src/models/Index.ts | 5 +++++ src/models/Relation.ts | 19 +++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 src/models/Column.ts create mode 100644 src/models/Entity.ts create mode 100644 src/models/Index.ts create mode 100644 src/models/Relation.ts diff --git a/src/models/Column.ts b/src/models/Column.ts new file mode 100644 index 0000000..5f3fa82 --- /dev/null +++ b/src/models/Column.ts @@ -0,0 +1,33 @@ +import { ColumnType } from "typeorm"; + +export type Column = { + primary?: boolean; + + sqlType: ColumnType; + + typescriptType: any; + + name?: string; + + length?: number; + + width?: number; + + nullable?: boolean; + + generated?: true | "increment" | "uuid"; + + unique?: boolean; + + default?: boolean; + + precision?: number; + + scale?: number; + + unsigned?: boolean; + + enum?: string[]; + + array?: boolean; +}; diff --git a/src/models/Entity.ts b/src/models/Entity.ts new file mode 100644 index 0000000..c3a28db --- /dev/null +++ b/src/models/Entity.ts @@ -0,0 +1,15 @@ +import { Column } from "./Column"; +import { Relation } from "./Relation"; +import { Index } from "./Index"; + +export type Entity = { + sqlName: string; + typescriptName?: string; + + database?: string; + schema?: string; + + columns: Column[]; + relations?: Relation[]; + indices?: Index[]; +}; diff --git a/src/models/Index.ts b/src/models/Index.ts new file mode 100644 index 0000000..0de83cc --- /dev/null +++ b/src/models/Index.ts @@ -0,0 +1,5 @@ +export type Index = { + name?: string; + columns?: ((object?: any) => any[] | { [key: string]: number }) | string[]; + unique?: boolean; +}; diff --git a/src/models/Relation.ts b/src/models/Relation.ts new file mode 100644 index 0000000..153d4ec --- /dev/null +++ b/src/models/Relation.ts @@ -0,0 +1,19 @@ +import { OnUpdateType } from "typeorm/metadata/types/OnUpdateType"; +import { OnDeleteType } from "typeorm/metadata/types/OnDeleteType"; +import { RelationType } from "typeorm/metadata/types/RelationTypes"; +import { JoinTableOptions, JoinColumnOptions } from "typeorm"; +import { JoinTableMultipleColumnsOptions } from "typeorm/decorator/options/JoinTableMultipleColumnsOptions"; + +export type Relation = { + target: Function | string; + type: RelationType; + inverseSide?: string; + // lazy?: boolean; + // eager?: boolean; + // primary?: boolean; + joinTable?: boolean | JoinTableOptions | JoinTableMultipleColumnsOptions; + joinColumn?: boolean | JoinColumnOptions; + nullable?: boolean; + onDelete?: OnDeleteType; + onUpdate?: OnUpdateType; +};