def create_record(db: PartitionedDatabase, model_id_or_name: str, body: JsonDict) -> Tuple[JsonDict, int]: record_values = [body["values"]] x_bf_trace_id = AuditLogger.trace_id_header() record = db.create_records(model_id_or_name, record_values)[0] model = db.get_model(model_id_or_name) if model is None: raise NotFound(f"Model {model_id_or_name}") # Emit "CreateRecord" event: PennsieveJobsClient.get().send_changelog_event( organization_id=db.organization_id, dataset_id=db.dataset_id, user_id=db.user_id, event=CreateRecord(id=record.id, name=record.name, model_id=model.id), trace_id=TraceId(x_bf_trace_id), ) return record.to_dict(), 201
def create_records( db: PartitionedDatabase, model_id_or_name: str, body: List[Dict] ) -> Tuple[List[JsonDict], int]: x_bf_trace_id = AuditLogger.trace_id_header() record_values = [r["values"] for r in body] records = db.create_records(model_id_or_name, records=record_values) model = db.get_model(model_id_or_name) if model is None: raise NotFound(f"Model {model_id_or_name}") # Emit "CreateRecord" event: events = [CreateRecord(id=r.id, name=r.name, model_id=model.id) for r in records] PennsieveJobsClient.get().send_changelog_events( organization_id=db.organization_id, dataset_id=db.dataset_id, user_id=db.user_id, events=events, trace_id=TraceId(x_bf_trace_id), ) return [record.to_dict() for record in records], 201