database structure
This commit is contained in:
parent
dde41c085e
commit
858d778039
13
lib/snippets/database/classes/Column.ts
Normal file
13
lib/snippets/database/classes/Column.ts
Normal 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;
|
||||
}
|
||||
}
|
20
lib/snippets/database/classes/ColumnType.ts
Normal file
20
lib/snippets/database/classes/ColumnType.ts
Normal 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'
|
||||
}
|
5
lib/snippets/database/classes/Database.ts
Normal file
5
lib/snippets/database/classes/Database.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { Table } from './Table';
|
||||
|
||||
export class Database {
|
||||
public tables: Array<Table> = [];
|
||||
}
|
15
lib/snippets/database/classes/PatchActions.ts
Normal file
15
lib/snippets/database/classes/PatchActions.ts
Normal 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'
|
||||
}
|
9
lib/snippets/database/classes/Relation.ts
Normal file
9
lib/snippets/database/classes/Relation.ts
Normal 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;
|
||||
}
|
||||
}
|
3
lib/snippets/database/classes/Serializable.ts
Normal file
3
lib/snippets/database/classes/Serializable.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export interface Serializable {
|
||||
serialize(): string;
|
||||
}
|
10
lib/snippets/database/classes/Table.ts
Normal file
10
lib/snippets/database/classes/Table.ts
Normal 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;
|
||||
}
|
||||
}
|
7
lib/snippets/database/index.ts
Normal file
7
lib/snippets/database/index.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { Snippet } from '../../Snippet';
|
||||
|
||||
export default class Database implements Snippet {
|
||||
public start (): Promise<void> {
|
||||
// noop
|
||||
}
|
||||
}
|
26
lib/snippets/database/patch_actions/RenameColumn.ts
Normal file
26
lib/snippets/database/patch_actions/RenameColumn.ts
Normal 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}`;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user