27 lines
742 B
TypeScript
27 lines
742 B
TypeScript
|
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}`;
|
||
|
}
|
||
|
}
|