database structure

This commit is contained in:
Timo Hocker 2020-04-18 20:43:02 +02:00
parent dde41c085e
commit 858d778039
9 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,13 @@
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;
}
}

View File

@ -0,0 +1,20 @@
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'
}

View File

@ -0,0 +1,5 @@
import { Table } from './Table';
export class Database {
public tables: Array<Table> = [];
}

View File

@ -0,0 +1,15 @@
export enum PatchActions {
rename_column = 'rc',
add_column = 'ac',
drop_column = 'dc',
add_relation = 'ar',
drop_relation = 'dr',
set_column_type = 'tc',
add_table = 'at',
drop_table = 'dt',
rename_table = 'rt',
insert_data = 'id',
update_data = 'ud',
mutate_data = 'md',
delete_data = 'dd'
}

View File

@ -0,0 +1,9 @@
export class Relation {
public column: string;
public table: string;
public constructor (table: string, column: string) {
this.column = column;
this.table = table;
}
}

View File

@ -0,0 +1,3 @@
export interface Serializable {
serialize(): string;
}

View File

@ -0,0 +1,10 @@
import { Column } from './Column';
export class Table {
public name: string;
public columns: Array<Column> = [];
public constructor (name: string) {
this.name = name;
}
}

View File

@ -0,0 +1,7 @@
import { Snippet } from '../../Snippet';
export default class Database implements Snippet {
public start (): Promise<void> {
// noop
}
}

View File

@ -0,0 +1,26 @@
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}`;
}
}