def get_schema_graph(db: PartitionedDatabase) -> JsonDict: with db.transaction() as tx: structure = db.graph_schema_structure_tx(tx) models: List[Model] = structure.models model_ids: List[ModelId] = [m.id for m in models] property_counts: Dict[ModelId, int] = db.get_property_counts_tx(tx, model_ids) one_to_one, one_to_many = partition( lambda r: r.one_to_many, structure.relationships ) legacy_models = [ dict(type="concept", **to_concept_dict(m, property_counts[m.id])) for m in models ] legacy_model_relationships = [ dict(type="schemaRelationship", **to_legacy_relationship(r)) for r in one_to_many ] legacy_schema_linked_properties = [ to_schema_linked_property(r) for r in one_to_one ] return ( legacy_models + legacy_model_relationships + legacy_schema_linked_properties )
def get_related_concepts(db: PartitionedDatabase, id_or_name: str) -> List[JsonDict]: with db.transaction() as tx: models = db.get_related_models_tx(tx, id_or_name) property_counts = db.get_property_counts_tx( tx, [model.id for model in models]) return [to_concept_dict(m, property_counts[m.id]) for m in models]
def update_concept( db: PartitionedDatabase, concept_id_or_name: str, body: JsonDict ) -> JsonDict: x_bf_trace_id = AuditLogger.trace_id_header() with db.transaction() as tx: model = db.update_model_tx(tx, concept_id_or_name, **filter_model_dict(body)) property_count = db.get_property_counts_tx(tx, [model.id])[model.id] # Emit "UpdateModel" event: PennsieveJobsClient.get().send_changelog_event( organization_id=db.organization_id, dataset_id=db.dataset_id, user_id=db.user_id, event=UpdateModel(id=UUID(model.id), name=model.name), trace_id=TraceId(x_bf_trace_id), ) return to_concept_dict(model, property_count)
def get_concept(db: PartitionedDatabase, concept_id_or_name: str) -> JsonDict: with db.transaction() as tx: model = db.get_model_tx(tx, concept_id_or_name) property_count = db.get_property_counts_tx(tx, [model.id])[model.id] return to_concept_dict(model, property_count)
def get_all_concepts(db: PartitionedDatabase) -> List[JsonDict]: with db.transaction() as tx: models = db.get_models_tx(tx) property_counts = db.get_property_counts_tx(tx, [model.id for model in models]) return [to_concept_dict(m, property_counts[m.id]) for m in models]