2020-06-28 16:55:44 +02:00

30 lines
845 B
TypeScript

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);
}
}