diff --git a/lib/snippets/database/classes/Column.ts b/lib/snippets/database/classes/Column.ts deleted file mode 100644 index d256d98..0000000 --- a/lib/snippets/database/classes/Column.ts +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) SapphireCode - All Rights Reserved - * This file is part of Snippeteer which is released under BSD-3-Clause. - * See file 'LICENSE' for full license details. - * Created by Timo Hocker , May 2020 - */ - -import { ColumnType } from './ColumnType'; -import { Relation } from './Relation'; - -export class Column { - public name: string; - public type: ColumnType; - public relation?: Relation; - - public constructor (name: string, type: ColumnType) { - this.name = name; - this.type = type; - } -} diff --git a/lib/snippets/database/classes/ColumnType.ts b/lib/snippets/database/classes/ColumnType.ts deleted file mode 100644 index a7cf81b..0000000 --- a/lib/snippets/database/classes/ColumnType.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) SapphireCode - All Rights Reserved - * This file is part of Snippeteer which is released under BSD-3-Clause. - * See file 'LICENSE' for full license details. - * Created by Timo Hocker , May 2020 - */ - -export enum ColumnType { - string = 'string', - text = 'text', - integer = 'integer', - big_integer = 'bigInteger', - float = 'float', - decimal = 'decimal', - increments = 'increments', - big_increments = 'bigIncrements', - boolean = 'boolean', - date = 'date', - date_time ='datetime', - time = 'time', - timestamp = 'timestamp', - binary = 'binary', - enum = 'enu', - json='json', - jsonb='jsonb', - uuid='uuid' -} diff --git a/lib/snippets/database/classes/Database.ts b/lib/snippets/database/classes/Database.ts deleted file mode 100644 index 45f98c9..0000000 --- a/lib/snippets/database/classes/Database.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) SapphireCode - All Rights Reserved - * This file is part of Snippeteer which is released under BSD-3-Clause. - * See file 'LICENSE' for full license details. - * Created by Timo Hocker , May 2020 - */ - -import { Table } from './Table'; - -export class Database { - public tables: Array = []; - - public get_table (name: string): Table|null { - for (const table of this.tables) { - if (table.name === name) - return table; - } - - return null; - } -} diff --git a/lib/snippets/database/classes/PatchAction.ts b/lib/snippets/database/classes/PatchAction.ts deleted file mode 100644 index 2f4799b..0000000 --- a/lib/snippets/database/classes/PatchAction.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (C) SapphireCode - All Rights Reserved - * This file is part of Snippeteer which is released under BSD-3-Clause. - * See file 'LICENSE' for full license details. - * Created by Timo Hocker , May 2020 - */ - -import { Database } from './Database'; - -export interface PatchAction { - apply(db: Database): void; - assign_object(obj: Record):void; -} diff --git a/lib/snippets/database/classes/Relation.ts b/lib/snippets/database/classes/Relation.ts deleted file mode 100644 index 66e7e63..0000000 --- a/lib/snippets/database/classes/Relation.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) SapphireCode - All Rights Reserved - * This file is part of Snippeteer which is released under BSD-3-Clause. - * See file 'LICENSE' for full license details. - * Created by Timo Hocker , May 2020 - */ - -export class Relation { - public column: string; - public table: string; - - public constructor (table: string, column: string) { - this.column = column; - this.table = table; - } -} diff --git a/lib/snippets/database/classes/Table.ts b/lib/snippets/database/classes/Table.ts deleted file mode 100644 index dd9d9de..0000000 --- a/lib/snippets/database/classes/Table.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) SapphireCode - All Rights Reserved - * This file is part of Snippeteer which is released under BSD-3-Clause. - * See file 'LICENSE' for full license details. - * Created by Timo Hocker , May 2020 - */ - -import { Column } from './Column'; - -export class Table { - public name: string; - public columns: Array = []; - - public constructor (name: string) { - this.name = name; - } - - public get_column (name: string): Column|null { - for (const col of this.columns) { - if (col.name === name) - return col; - } - - return null; - } -} diff --git a/lib/snippets/database/index.ts b/lib/snippets/database/index.ts deleted file mode 100644 index 90a666d..0000000 --- a/lib/snippets/database/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) SapphireCode - All Rights Reserved - * This file is part of Snippeteer which is released under BSD-3-Clause. - * See file 'LICENSE' for full license details. - * Created by Timo Hocker , May 2020 - */ - -import { Snippet } from '../../Snippet'; -import { MainMenu } from './menu/MainMenu'; -import { Database as DatabaseClass } from './classes/Database'; - -export default class Database implements Snippet { - public is_active (): boolean { - return false; - } - - public async start (): Promise { - await (new MainMenu (new DatabaseClass)) - .run (); - } -} diff --git a/lib/snippets/database/menu/MainMenu.ts b/lib/snippets/database/menu/MainMenu.ts deleted file mode 100644 index be26786..0000000 --- a/lib/snippets/database/menu/MainMenu.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) SapphireCode - All Rights Reserved - * This file is part of Snippeteer which is released under BSD-3-Clause. - * See file 'LICENSE' for full license details. - * Created by Timo Hocker , June 2020 - */ - -import { Database } from '../classes/Database'; -import { Menu } from './Menu'; - -export class MainMenu extends Menu { - public constructor (db: Database) { - super ('Snippeteer Database'); - this.register_option ('quit', () => { - // noop - }); - this.register_option ('create table', () => { - console.log ('table'); - }); - } -} diff --git a/lib/snippets/database/menu/Menu.ts b/lib/snippets/database/menu/Menu.ts deleted file mode 100644 index 87d0bfe..0000000 --- a/lib/snippets/database/menu/Menu.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) SapphireCode - All Rights Reserved - * This file is part of Snippeteer which is released under BSD-3-Clause. - * See file 'LICENSE' for full license details. - * Created by Timo Hocker , June 2020 - */ - -import { StringOption } from '@sapphirecode/console-app'; - -export class Menu { - private _options: Recordvoid|Promise> = {}; - private _title: string; - - public constructor (title: string) { - this._title = title; - } - - public async run (): Promise { - const options = Object.keys (this._options); - const selected = await (new StringOption ({ - name: 'menu_select', - message: this._title, - sources: { console: false }, - exit_on_interrupt: true, - preset: options - })) - .parse (); - if (typeof this._options[selected] !== 'undefined') - await new Promise (this._options[selected]); - } - - public register_option (name:string, callback:()=>void|Promise): void { - this._options[name] = callback; - } -} diff --git a/lib/snippets/database/patch_actions/ActionFactory.ts b/lib/snippets/database/patch_actions/ActionFactory.ts deleted file mode 100644 index 704afb9..0000000 --- a/lib/snippets/database/patch_actions/ActionFactory.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { PatchAction } from '../classes/PatchAction'; - -export class ActionFactory { - private static _actions: RecordPatchAction> = {}; - - public static get (name:string, json:string): PatchAction { - return this._actions[name] (json); - } - - public static register ( - name:string, - constr: (json:string)=>PatchAction - ):void { - this._actions[name] = constr; - } -} diff --git a/lib/snippets/database/patch_actions/AddTable.ts b/lib/snippets/database/patch_actions/AddTable.ts deleted file mode 100644 index cf629f3..0000000 --- a/lib/snippets/database/patch_actions/AddTable.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Persistent } from '@sapphirecode/modelling'; -import { PatchAction } from '../classes/PatchAction'; -import { Database } from '../classes/Database'; -import { Table } from '../classes/Table'; -import { Column } from '../classes/Column'; -import { ColumnType } from '../classes/ColumnType'; - -export class AddTable extends Persistent implements PatchAction { - public get name ():string { - return this.get ('name') as string; - } - - public constructor (name:string) { - super (); - this.properties.name = 'string'; - - this.set ('name', name); - } - - public apply (db: Database):void { - if (typeof db.get_table (this.name) !== 'undefined') - throw new Error ('table already exists'); - - const table = new Table (this.name); - table.columns.push (new Column ('id', ColumnType.increments)); - - db.tables.push (table); - } -} diff --git a/lib/snippets/database/patch_actions/PatchActions.ts b/lib/snippets/database/patch_actions/PatchActions.ts deleted file mode 100644 index 2c5af90..0000000 --- a/lib/snippets/database/patch_actions/PatchActions.ts +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) SapphireCode - All Rights Reserved - * This file is part of Snippeteer which is released under BSD-3-Clause. - * See file 'LICENSE' for full license details. - * Created by Timo Hocker , June 2020 - */ - -import { PatchAction } from '../classes/PatchAction'; -import { ActionFactory } from './ActionFactory'; -import { RenameColumn } from './RenameColumn'; -import { AddTable } from './AddTable'; - - -/* - * export { AddColumn } from './AddColumn'; - * export { DropColumn } from './DropColumn'; - * export { AddRelation } from './AddRelation'; - * export { DropRelation } from './DropRelation'; - * export { SetColumnType } from './SetColumnType'; - * export { DropTable } from './DropTable'; - * export { RenameTable } from './RenameTable'; - * export { InsertData } from './InsertData'; - * export { UpdateData } from './UpdateData'; - * export { MutateDate } from './MutateDate'; - * export { DeleteData } from './DeleteData'; - */ - -function assign_json (patch:PatchAction, json:string):PatchAction { - const obj = JSON.parse (json); - patch.assign_object (obj); - return patch; -} - -function init ():void { - ActionFactory.register ( - 'rename_column', - (json:string) => assign_json (new RenameColumn ('', '', ''), json) - ); - - ActionFactory.register ( - 'add_table', - (json:string) => assign_json (new AddTable (''), json) - ); -} - -export { - init, - RenameColumn, - AddTable -}; diff --git a/lib/snippets/database/patch_actions/RenameColumn.ts b/lib/snippets/database/patch_actions/RenameColumn.ts deleted file mode 100644 index a1cf8e8..0000000 --- a/lib/snippets/database/patch_actions/RenameColumn.ts +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) SapphireCode - All Rights Reserved - * This file is part of Snippeteer which is released under BSD-3-Clause. - * See file 'LICENSE' for full license details. - * Created by Timo Hocker , May 2020 - */ - -import { Persistent } from '@sapphirecode/modelling'; -import { PatchAction } from '../classes/PatchAction'; -import { Database } from '../classes/Database'; - -export class RenameColumn extends Persistent implements PatchAction { - public get table (): string { - return this.get ('table') as string; - } - - public get column (): string { - return this.get ('column') as string; - } - - public get new_name (): string { - return this.get ('new_name') as string; - } - - public constructor ( - column: string, - new_name: string, - table: string - ) { - super (); - this.properties.column = 'string'; - this.properties.table = 'string'; - this.properties.new_name = 'string'; - - this.set ('column', column); - this.set ('new_name', new_name); - this.set ('table', table); - } - - public apply (db: Database): void { - const table = db.get_table (this.table); - if (typeof table === 'undefined' || table === null) { - throw new Error ( - `table ${this.table} not found` - ); - } - const column = table.get_column (this.column); - if (typeof column === 'undefined' || column === null) { - throw new Error ( - `column ${this.column} not found in table ${this.table}` - ); - } - - column.name = this.new_name; - } -}