-
Notifications
You must be signed in to change notification settings - Fork 2
[draft] Collecting documentation for app runner #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
new deploy snippet |
|
Snippet for core Finding EntitiesThe module provides several methods for retrieving entities: # Find a single entity
project = Project.find(id=123, client=client)
# Find multiple entities efficiently
project_ids = [123, 456, 789]
projects = Project.find_all(ids=project_ids, client=client)
# Find entities matching a query
matching_projects = Project.find_by({"name": "My Project"}, client=client)When working with multiple entities, always prefer Working with RelationshipsEntities can have relationships with other entities, defined using # One-to-one relationship
sample = Sample.find(id=123, client=client)
project = sample.project # Automatically loads the related project
# One-to-many relationship
project = Project.find(id=456, client=client)
for sample in project.samples: # Automatically loads all related samples
print(sample.id)
# Access just the IDs without loading entities
sample_ids = project.samples.ids
# Convert to a list or DataFrame
samples_list = project.samples.list
samples_df = project.samples.polarsPerformance TipsFor optimal performance:
Developer GuideThis section is for developers who want to extend or modify the Module StructureThe module consists of several components:
Creating a New Entity TypeTo create a new entity type: from bfabric.entities.core.entity import Entity
from bfabric.entities.core.has_one import HasOne
from bfabric.entities.core.has_many import HasMany
class MyEntity(Entity):
ENDPOINT = "MyEntityEndpoint" # B-Fabric endpoint name
# Define relationships
parent = HasOne("ParentEntity", bfabric_field="parent")
children = HasMany("ChildEntity", bfabric_field="children")
# Add custom methods if needed
def custom_method(self):
return f"Custom functionality for {self.id}"Design PrinciplesWhen extending the module, follow these principles:
Entity Lookup CacheThe from bfabric.experimental.entity_lookup_cache import EntityLookupCache
# Singleton instance
cache = EntityLookupCache.instance()
# Cache operations
cache.put(entity_type=MyEntity, entity_id=123, entity=my_entity)
cached_entity = cache.get(entity_type=MyEntity, entity_id=123)API ReferenceKey Features
|
No description provided.