quick-erd
Version:
quick and easy text-based ERD + code generator for migration, query, typescript types and orm entity
95 lines (94 loc) • 2.56 kB
TypeScript
import { Position } from './meta';
export declare function parse(input: string): ParseResult;
export type ParseResult = {
table_list: Table[];
zoom?: number;
view?: Position;
textBgColor?: string;
textColor?: string;
diagramBgColor?: string;
diagramTextColor?: string;
tableBgColor?: string;
tableTextColor?: string;
};
export declare class Parser implements ParseResult {
table_list: Table[];
line_list: string[];
zoom?: number;
view?: Position;
textBgColor?: string;
diagramTextColor?: string;
textColor?: string;
diagramBgColor?: string;
tableBgColor?: string;
tableTextColor?: string;
parse(input: string): void;
parseMeta(input: string): void;
peekLine(): string;
hasTable(): boolean | "";
parseTable(): Table;
parseField(): Field;
parseCollateValue(): string;
parseFieldModifiers(field: Field): void;
skipLine(line?: string): void;
parseEmptyLine(): void;
parseName(): string;
parseType(): string | undefined;
parseDefaultValue(field: Field): string;
parseRelationType(): RelationType;
parseForeignKeyReference(field: Field): ForeignKeyReference;
}
export declare function unwrapQuotedName(name: string): string;
export type Table = {
is_virtual?: boolean;
name: string;
field_list: Field[];
position?: {
x: number;
y: number;
color?: string;
};
};
export type Field = {
name: string;
type: string;
is_primary_key: boolean;
is_unique: boolean;
is_null: boolean;
is_unsigned: boolean;
is_zerofill: boolean;
references: ForeignKeyReference | undefined;
default_value: string | undefined;
collate: string | undefined;
};
export type ForeignKeyReference = {
type: RelationType;
table: string;
field: string;
};
export type Relation = {
from: {
table: string;
field: string;
};
to: {
table: string;
field: string;
};
/**
| Relation Type | Description |
| ---- | ----------- |
| - | one TO one |
| -< | one TO many |
| >- | many TO one |
| >-< | many TO many |
| -0 | one TO zero or one |
| 0- | zero or one TO one |
| 0-0 | zero or one TO zero or one |
| -0< | one TO zero or many |
| >0- | zero or many TO one |
*/
type: RelationType;
};
export type RelationType = (typeof RelationTypes)[number];
export declare const RelationTypes: ("-" | ">0-" | "-0<" | ">-<" | "0-0" | ">-" | "-<" | "0-" | "-0")[];