MCPcopy Create free account
hub / github.com/dataease/SQLBot / get_table_obj_by_ds

Function get_table_obj_by_ds

backend/apps/datasource/crud/datasource.py:403–432  ·  view source on GitHub ↗
(session: SessionDep, current_user: CurrentUser, ds: CoreDatasource)

Source from the content-addressed store, hash-verified

401
402
403def get_table_obj_by_ds(session: SessionDep, current_user: CurrentUser, ds: CoreDatasource) -> List[TableAndFields]:
404 _list: List = []
405 tables = session.query(CoreTable).filter(
406 and_(CoreTable.ds_id == ds.id, CoreTable.checked == True)
407 ).all()
408 conf = DatasourceConf(**json.loads(aes_decrypt(ds.configuration))) if ds.type != "excel" else get_engine_config()
409 schema = conf.dbSchema if conf.dbSchema is not None and conf.dbSchema != "" else conf.database
410
411 # get all field
412 table_ids = [table.id for table in tables]
413 all_fields = session.query(CoreField).filter(
414 and_(CoreField.table_id.in_(table_ids), CoreField.checked == True)).all()
415 # build dict
416 fields_dict = {}
417 for field in all_fields:
418 if fields_dict.get(field.table_id):
419 fields_dict.get(field.table_id).append(field)
420 else:
421 fields_dict[field.table_id] = [field]
422
423 contain_rules = session.query(DsRules).all()
424 for table in tables:
425 # fields = session.query(CoreField).filter(and_(CoreField.table_id == table.id, CoreField.checked == True)).all()
426 fields = fields_dict.get(table.id)
427
428 # do column permissions, filter fields
429 fields = get_column_permission_fields(session=session, current_user=current_user, table=table, fields=fields,
430 contain_rules=contain_rules)
431 _list.append(TableAndFields(schema=schema, table=table, fields=fields))
432 return _list
433
434
435def get_table_sample_data(ds: CoreDatasource, table_name: str, fields: list) -> str:

Callers 2

get_tables_sample_dataFunction · 0.85
get_table_schemaFunction · 0.85

Calls 8

aes_decryptFunction · 0.90
get_engine_configFunction · 0.90
DatasourceConfClass · 0.85
TableAndFieldsClass · 0.85
getMethod · 0.65
filterMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected