forked from DhanushNehru/ToolJet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_source.entity.ts
More file actions
98 lines (80 loc) · 2.23 KB
/
Copy pathdata_source.entity.ts
File metadata and controls
98 lines (80 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { DataSourceTypes } from 'src/helpers/data_source.constants';
import {
Entity,
Column,
PrimaryGeneratedColumn,
CreateDateColumn,
UpdateDateColumn,
ManyToOne,
JoinColumn,
BaseEntity,
OneToMany,
JoinTable,
ManyToMany,
AfterLoad,
} from 'typeorm';
import { App } from './app.entity';
import { AppVersion } from './app_version.entity';
import { DataQuery } from './data_query.entity';
import { DataSourceOptions } from './data_source_options.entity';
import { Plugin } from './plugin.entity';
@Entity({ name: 'data_sources' })
export class DataSource extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ name: 'name' })
name: string;
@Column({ name: 'kind' })
kind: string;
@Column({
type: 'enum',
enumName: 'type',
name: 'type',
enum: [DataSourceTypes.STATIC, DataSourceTypes.DEFAULT, DataSourceTypes.SAMPLE],
default: DataSourceTypes.DEFAULT,
})
type: string;
@Column({ name: 'plugin_id' })
pluginId: string;
@Column({ name: 'app_version_id' })
appVersionId: string;
@Column({ name: 'organization_id' })
organizationId: string;
@Column({ type: 'enum', enumName: 'scope', enum: ['local', 'global'], default: 'local' })
scope: string;
@CreateDateColumn({ default: () => 'now()', name: 'created_at' })
createdAt: Date;
@UpdateDateColumn({ default: () => 'now()', name: 'updated_at' })
updatedAt: Date;
@ManyToOne(() => AppVersion, (appVersion) => appVersion.id, {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'app_version_id' })
appVersion: AppVersion;
@ManyToMany(() => App)
@JoinTable({
name: 'app_versions',
joinColumn: {
name: 'id',
referencedColumnName: 'appVersionId',
},
inverseJoinColumn: {
name: 'app_id',
referencedColumnName: 'id',
},
})
apps: App[];
app: App;
@ManyToOne(() => Plugin, (plugin) => plugin.id, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'plugin_id' })
plugin: Plugin;
@OneToMany(() => DataSourceOptions, (dso) => dso.dataSource)
dataSourceOptions: DataSourceOptions[];
@OneToMany(() => DataQuery, (dq) => dq.dataSource)
dataQueries: DataQuery[];
options: any;
@AfterLoad()
updateApp() {
if (this.apps?.length) this.app = this.apps[0];
}
}