@@ -23,6 +23,13 @@ type TpDataServicesConfig struct {
23
23
TimeField []string
24
24
}
25
25
26
+ //表面结构体
27
+ type TableInfo struct {
28
+ TableName string `json:"table_name" alias:"名称" gorm:"column:table_name"`
29
+ Comment string `json:"comment" alias:"描述" gorm:"column:table_description"`
30
+ }
31
+
32
+ //获取一条数详情
26
33
func (* TpDataServicesConfig ) GetTpDataServicesConfigDetail (id string ) models.TpDataServicesConfig {
27
34
var TpDataServicesConfig models.TpDataServicesConfig
28
35
psql .Mydb .First (& TpDataServicesConfig , "id = ? " , id )
@@ -37,15 +44,6 @@ func (*TpDataServicesConfig) GetTpDataServicesConfigList(PaginationValidate vali
37
44
if PaginationValidate .Name != "" {
38
45
db .Where ("name like ?" , "%" + PaginationValidate .Name + "%" )
39
46
}
40
- // if PaginationValidate.AppKey != "" {
41
- // db.Where("app_key like ?", "%"+PaginationValidate.AppKey+"%")
42
- // }
43
- // if PaginationValidate.SignatureMode != "" {
44
- // db.Where("SignatureMode = ?", PaginationValidate.SignatureMode)
45
- // }
46
- // if PaginationValidate.IpWhitelist != "" {
47
- // db.Where("ip_whitelist like ?", "%"+PaginationValidate.IpWhitelist+"%")
48
- // }
49
47
if PaginationValidate .EnableFlag != "" {
50
48
db .Where ("enable_flag = ?" , PaginationValidate .EnableFlag )
51
49
}
@@ -207,3 +205,39 @@ func (*TpDataServicesConfig) GetDataByAppkey(reqData valid.GetDataPaginationVali
207
205
}
208
206
return result , nil
209
207
}
208
+
209
+ func (* TpDataServicesConfig ) GetTableNames () ([]TableInfo , error ) {
210
+ var tableNames []TableInfo
211
+ sql := `SELECT table_name, obj_description (c.oid) AS table_description
212
+ FROM information_schema.tables t
213
+ LEFT JOIN pg_class c ON t.table_name = c.relname
214
+ WHERE table_type = 'BASE TABLE' AND table_schema = 'public'`
215
+ result := psql .Mydb .Raw (sql ).Scan (& tableNames )
216
+ if result .Error != nil {
217
+ logs .Error (result .Error , gorm .ErrRecordNotFound )
218
+ return tableNames , result .Error
219
+ }
220
+ return tableNames , nil
221
+
222
+ }
223
+ func (* TpDataServicesConfig ) GetTableField (table string ) ([]map [string ]interface {}, error ) {
224
+ sql := `SELECT
225
+ a.attname AS field,
226
+ format_type ( a.atttypid,a.atttypmod ) AS TYPE,
227
+ col_description(a.attrelid, a.attnum) AS comment
228
+ FROM
229
+ pg_class as c,
230
+ pg_attribute as a
231
+ WHERE
232
+ c.relname = 'asset'
233
+ AND a.attnum > 0
234
+ AND a.attrelid = c.oid`
235
+ var result []map [string ]interface {}
236
+ db := psql .Mydb .Raw (sql ).Scan (& result )
237
+ if db .Error != nil {
238
+ logs .Error (db .Error , gorm .ErrRecordNotFound )
239
+ return result , db .Error
240
+
241
+ }
242
+ return result , nil
243
+ }
0 commit comments