From 7abc6311ba1b8d4ec74d4f4463fbf0ee73a528c7 Mon Sep 17 00:00:00 2001 From: Logan Date: Mon, 28 Jun 2021 16:20:58 +0100 Subject: [PATCH] Added Alias Support --- public/Database/Example.dbml | 28 +++++++++++++++++++--------- src/App.tsx | 1 + src/Components/Navigation.tsx | 5 +++++ src/Lib/DBMLLib.ts | 3 ++- src/Lib/Declarations.ts | 7 +++++++ src/Pages/Table.tsx | 19 ++++++++++++++++--- 6 files changed, 50 insertions(+), 13 deletions(-) diff --git a/public/Database/Example.dbml b/public/Database/Example.dbml index 01aafe7..3a42032 100644 --- a/public/Database/Example.dbml +++ b/public/Database/Example.dbml @@ -6,18 +6,28 @@ Project Example { ''' } -Table Users { - id int [primary key, not null, Note: 'This is the ID Column', default: 10] - username varchar - - Note: 'This is the User Table' +Table Users as U { + ID integer [primary key] + Username varchar + Role varchar + created_at timestamp + Note: 'Users Table' } Table Posts { - id int [primary key, not null, default: 10] - user_id int + ID integer [primary key] + Title varchar + Body text [note: 'Content of the Post'] + User integer + Status Post_Status + created_at timestamp + Note: 'Posts Table' +} - Note: 'This is the Posts Table' +Enum Post_Status { + Draft + Published + Private [note: 'Visible Via URL Only'] } -Ref UserPosts: Posts.user_id > Users.id \ No newline at end of file +Ref PostsUserID: Posts.User > Users.ID // Many to One \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index 44c3b52..49ddc46 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -84,6 +84,7 @@ export default class App extends React.Component { { /> + Tables {this.props.Database.Tables.filter(x => x.Name.toLowerCase().includes(this.state.Search.toLowerCase())).map((table, index) => { return ( { /> ); })} + {this.props.Database.Enums !== undefined && + Enums + } diff --git a/src/Lib/DBMLLib.ts b/src/Lib/DBMLLib.ts index 6d6deed..23381e6 100644 --- a/src/Lib/DBMLLib.ts +++ b/src/Lib/DBMLLib.ts @@ -35,7 +35,8 @@ export function DBML2JSON(dbml: string): DBML { var tableNote = item.match(/(?<=Note: ').*\w/g) as string[]; var table: Table = { - Name: item.match(/(?<=Table ).*\w/g)?.toString() as string, + Name: item.match(/(?<=Table )[^]+?(?= )/g)?.toString() as string, + Alias: item.match(/(?<=as )[^]+?(?= {)/g)?.toString() as string, Columns: columns, Note: tableNote[tableNote?.length - 1] as string, }; diff --git a/src/Lib/Declarations.ts b/src/Lib/Declarations.ts index 6d0e408..5adc658 100644 --- a/src/Lib/Declarations.ts +++ b/src/Lib/Declarations.ts @@ -3,11 +3,13 @@ export interface DBML { database_type: string; Note: string; Tables: Table[]; + Enums: Enum[]; References: Reference[]; } export interface Table { Name: string; + Alias: string; Columns: Column[]; Note: string; } @@ -20,6 +22,11 @@ export interface Column { Note: string; } +export interface Enum { + Name: string; + Items: string[]; +} + export interface Reference { Name: string; Type: ConnectionType; diff --git a/src/Pages/Table.tsx b/src/Pages/Table.tsx index a198e6e..15290f3 100644 --- a/src/Pages/Table.tsx +++ b/src/Pages/Table.tsx @@ -39,6 +39,7 @@ const styles = (theme: Theme) => createStyles({ interface ITableProps extends WithStyles { Name: string; + Alias: string; Columns: Column[]; Note: string; References: Reference[]; @@ -83,9 +84,21 @@ class Table extends React.Component { <> - - {this.props.Name} - + {this.props.Alias === undefined && + + {this.props.Name} + + } + {this.props.Alias !== undefined && + <> + + {this.props.Alias} + + + Table Name: {this.props.Name} + + + }