27 lines
742 B
TypeScript
Raw Normal View History

2020-04-18 20:43:02 +02:00
import { Serializable } from '../classes/Serializable';
export class RenameColumn implements Serializable {
public column: string;
public new_name: string;
public constructor (column: string, new_name = null) {
if (new_name === null) {
const regex = /(?<column>[a-z_]+) (?<new_name>[a-z_]+)/iu;
const res = regex.exec (column);
if (res === null || typeof res.groups === 'undefined')
throw new Error ('invalid string to deserialize');
this.column = res.groups.column;
this.new_name = res.groups.new_name;
return;
}
this.column = column;
this.new_name = new_name as unknown as string;
}
public serialize (): string {
return `${this.column} ${this.new_name}`;
}
}