-
Notifications
You must be signed in to change notification settings - Fork 690
Expand file tree
/
Copy pathdatasource.py
More file actions
209 lines (162 loc) · 6.18 KB
/
datasource.py
File metadata and controls
209 lines (162 loc) · 6.18 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel
from sqlalchemy import Column, Text, BigInteger, DateTime, Identity
from sqlalchemy.dialects.postgresql import JSONB
from sqlmodel import SQLModel, Field
class CoreDatasource(SQLModel, table=True):
__tablename__ = "core_datasource"
id: int = Field(sa_column=Column(BigInteger, Identity(always=True), nullable=False, primary_key=True))
name: str = Field(max_length=128, nullable=False)
description: str = Field(max_length=512, nullable=True)
type: str = Field(max_length=64)
type_name: str = Field(max_length=64, nullable=True)
configuration: str = Field(sa_column=Column(Text))
create_time: datetime = Field(sa_column=Column(DateTime(timezone=False), nullable=True))
create_by: int = Field(sa_column=Column(BigInteger()))
status: str = Field(max_length=64, nullable=True)
num: str = Field(max_length=256, nullable=True)
oid: int = Field(sa_column=Column(BigInteger()))
table_relation: List = Field(sa_column=Column(JSONB, nullable=True))
embedding: str = Field(sa_column=Column(Text, nullable=True))
recommended_config: int = Field(sa_column=Column(BigInteger()))
class CoreTable(SQLModel, table=True):
__tablename__ = "core_table"
id: int = Field(sa_column=Column(BigInteger, Identity(always=True), nullable=False, primary_key=True))
ds_id: int = Field(sa_column=Column(BigInteger()))
checked: bool = Field(default=True)
table_name: str = Field(sa_column=Column(Text))
table_comment: str = Field(sa_column=Column(Text))
custom_comment: str = Field(sa_column=Column(Text))
embedding: str = Field(sa_column=Column(Text, nullable=True))
class DsRecommendedProblem(SQLModel, table=True):
__tablename__ = "ds_recommended_problem"
id: int = Field(sa_column=Column(BigInteger, Identity(always=True), nullable=False, primary_key=True))
datasource_id: int = Field(sa_column=Column(BigInteger()))
question: str = Field(sa_column=Column(Text))
remark: str = Field(sa_column=Column(Text))
sort: int = Field(sa_column=Column(BigInteger()))
create_time: datetime = Field(sa_column=Column(DateTime(timezone=False), nullable=True))
create_by: int = Field(sa_column=Column(BigInteger()))
class CoreField(SQLModel, table=True):
__tablename__ = "core_field"
id: int = Field(sa_column=Column(BigInteger, Identity(always=True), nullable=False, primary_key=True))
ds_id: int = Field(sa_column=Column(BigInteger()))
table_id: int = Field(sa_column=Column(BigInteger()))
checked: bool = Field(default=True)
field_name: str = Field(sa_column=Column(Text))
field_type: str = Field(max_length=128, nullable=True)
field_comment: str = Field(sa_column=Column(Text))
custom_comment: str = Field(sa_column=Column(Text))
field_index: int = Field(sa_column=Column(BigInteger()))
# datasource create obj
class CreateDatasource(BaseModel):
id: int = None
name: str = ''
description: str = ''
type: str = ''
configuration: str = ''
create_time: Optional[datetime] = None
create_by: int = 0
status: str = ''
num: str = ''
oid: int = 1
tables: List[CoreTable] = []
recommended_config: int = 1
class RecommendedProblemResponse:
def __init__(self, datasource_id, recommended_config, questions):
self.datasource_id = datasource_id
self.recommended_config = recommended_config
self.questions = questions
datasource_id: int = None
recommended_config: int = None
questions: str = None
class RecommendedProblemBase(BaseModel):
datasource_id: int = None
recommended_config: int = None
problemInfo: List[DsRecommendedProblem] = []
class RecommendedProblemBaseChat:
def __init__(self, content):
self.content = content
content: List[str] = []
# edit local saved table and fields
class TableObj(BaseModel):
table: CoreTable = None
fields: List[CoreField] = []
# datasource config info
class DatasourceConf(BaseModel):
host: str = ''
port: int = 0
username: str = ''
password: str = ''
database: str = ''
driver: str = ''
extraJdbc: str = ''
dbSchema: str = ''
filename: str = ''
sheets: List = ''
mode: str = ''
timeout: int = 30
lowVersion: bool = False
ssl: bool = False
def to_dict(self):
return {
"host": self.host,
"port": self.port,
"username": self.username,
"password": self.password,
"database": self.database,
"driver": self.driver,
"extraJdbc": self.extraJdbc,
"dbSchema": self.dbSchema,
"filename": self.filename,
"sheets": self.sheets,
"mode": self.mode,
"timeout": self.timeout,
"lowVersion": self.lowVersion,
"ssl": self.ssl
}
class TableSchema:
def __init__(self, attr1, attr2):
self.tableName = attr1
self.tableComment = attr2 if attr2 is None or isinstance(attr2, str) else attr2.decode("utf-8")
tableName: str
tableComment: str
class TableSchemaResponse(BaseModel):
tableName: str = ''
tableComment: str | None = ''
class ColumnSchema:
def __init__(self, attr1, attr2, attr3):
self.fieldName = attr1
self.fieldType = attr2
self.fieldComment = attr3 if attr3 is None or isinstance(attr3, str) else attr3.decode("utf-8")
fieldName: str
fieldType: str
fieldComment: str
class ColumnSchemaResponse(BaseModel):
fieldName: str | None = ''
fieldType: str | None = ''
fieldComment: str | None = ''
class TableAndFields:
def __init__(self, schema, table, fields):
self.schema = schema
self.table = table
self.fields = fields
schema: str
table: CoreTable
fields: List[CoreField]
class FieldObj(BaseModel):
fieldName: str | None
class PreviewResponse(BaseModel):
fields: List | None = []
data: List | None = []
sql: str | None = ''
class FieldInfo(BaseModel):
fieldName: str
fieldType: str
class SheetFields(BaseModel):
sheetName: str
fields: List[FieldInfo]
class ImportRequest(BaseModel):
filePath: str
sheets: List[SheetFields]