pub struct AssetDB { /* private fields */ }Implementations§
Source§impl AssetDB
impl AssetDB
Sourcepub fn with_backend(backend: Box<dyn StorageBackend>) -> Result<Arc<Self>>
pub fn with_backend(backend: Box<dyn StorageBackend>) -> Result<Arc<Self>>
Create a new AssetDB with the given storage backend.
Sourcepub fn add_listener(&self, listener: Arc<dyn DeltaListener>)
pub fn add_listener(&self, listener: Arc<dyn DeltaListener>)
Register a delta listener. Returns index for removal.
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Arc<Self>>
pub fn open(path: impl AsRef<Path>) -> Result<Arc<Self>>
Open a file-backed AssetDB at the given path (native only).
Sourcepub fn put(&self, id: &str, data: &[u8], metadata: Value) -> Result<()>
pub fn put(&self, id: &str, data: &[u8], metadata: Value) -> Result<()>
Put (upsert) an asset by ID. If the ID already exists, the data and metadata are replaced. The blob is content-addressed, so re-storing identical data is free.
Sourcepub fn put_json(
&self,
id: &str,
json_data: Value,
metadata: Value,
) -> Result<()>
pub fn put_json( &self, id: &str, json_data: Value, metadata: Value, ) -> Result<()>
Put JSON inline (materials, skeletons, configs). Upsert by ID.
Sourcepub fn tag(&self, id: &str, tags: &[&str]) -> Result<()>
pub fn tag(&self, id: &str, tags: &[&str]) -> Result<()>
Tag an entity. Additive — doesn’t remove existing tags.
Sourcepub fn get(&self, id: &str) -> Result<Asset>
pub fn get(&self, id: &str) -> Result<Asset>
Get a single asset by exact ID. This is the primary access path.
let mesh = db.get("snake:mesh")?;Sourcepub fn get_entry(&self, id: &str) -> Result<AssetEntry>
pub fn get_entry(&self, id: &str) -> Result<AssetEntry>
Get just the metadata for an entity (no blob load).
Sourcepub fn store(
&self,
asset_type: &str,
name: &str,
data: &[u8],
metadata: Value,
tags: &[&str],
) -> Result<AssetId>
pub fn store( &self, asset_type: &str, name: &str, data: &[u8], metadata: Value, tags: &[&str], ) -> Result<AssetId>
Store with auto-generated ID. Returns the ID.
Sourcepub fn store_json(
&self,
asset_type: &str,
name: &str,
json_data: Value,
metadata: Value,
tags: &[&str],
) -> Result<AssetId>
pub fn store_json( &self, asset_type: &str, name: &str, json_data: Value, metadata: Value, tags: &[&str], ) -> Result<AssetId>
Store JSON with auto-generated ID. Returns the ID.
Sourcepub fn load_by_name(&self, name: &str) -> Result<Asset>
pub fn load_by_name(&self, name: &str) -> Result<Asset>
Load by name (convenience — looks up “name:*” pattern).
Sourcepub fn set_component(
&self,
entity: &str,
component: &str,
data: &[u8],
metadata: Value,
) -> Result<()>
pub fn set_component( &self, entity: &str, component: &str, data: &[u8], metadata: Value, ) -> Result<()>
Set a component on an entity. Upserts “entity:component” in the DB.
Sourcepub fn set_component_json(
&self,
entity: &str,
component: &str,
data: Value,
metadata: Value,
) -> Result<()>
pub fn set_component_json( &self, entity: &str, component: &str, data: Value, metadata: Value, ) -> Result<()>
Set a JSON component on an entity.
Sourcepub fn merge_component_json(
&self,
entity: &str,
component: &str,
patch: Value,
metadata: Value,
) -> Result<()>
pub fn merge_component_json( &self, entity: &str, component: &str, patch: Value, metadata: Value, ) -> Result<()>
Merge fields into an existing JSON component. Creates if missing.
Only the keys present in patch are overwritten; all other fields preserved.
Sourcepub fn get_component(&self, entity: &str, component: &str) -> Result<Asset>
pub fn get_component(&self, entity: &str, component: &str) -> Result<Asset>
Get a component from an entity.
Sourcepub fn has_component(&self, entity: &str, component: &str) -> bool
pub fn has_component(&self, entity: &str, component: &str) -> bool
Check if an entity has a specific component.
Sourcepub fn remove_component(&self, entity: &str, component: &str) -> Result<()>
pub fn remove_component(&self, entity: &str, component: &str) -> Result<()>
Remove a component from an entity.
Sourcepub fn components_of(&self, entity: &str) -> Result<Vec<String>>
pub fn components_of(&self, entity: &str) -> Result<Vec<String>>
List all component types attached to an entity.
db.components_of("player") → ["transform", "rigidbody", "collider", "mesh"]Sourcepub fn entities_with(&self, components: &[&str]) -> Result<Vec<String>>
pub fn entities_with(&self, components: &[&str]) -> Result<Vec<String>>
Find all entity names that have ALL of the specified components.
db.entities_with(&["rigidbody", "transform"])
→ ["player", "enemy_1", "crate_3"]Sourcepub fn entities_with_any(&self, components: &[&str]) -> Result<Vec<String>>
pub fn entities_with_any(&self, components: &[&str]) -> Result<Vec<String>>
Find all entity names that have ANY of the specified components.
Sourcepub fn entity_snapshot(&self, entity: &str) -> Result<Value>
pub fn entity_snapshot(&self, entity: &str) -> Result<Value>
Get all components for an entity as a JSON object. Loads inline_data for JSON components, metadata for binary ones.
db.entity_snapshot("player")
→ { "transform": { "position": [0,1,0], ... },
"rigidbody": { "mass": 1.0, ... } }Sourcepub fn spawn_from(&self, template_entity: &str, new_entity: &str) -> Result<()>
pub fn spawn_from(&self, template_entity: &str, new_entity: &str) -> Result<()>
Spawn an entity from a template (prefab). Copies all components from source entity to a new entity name.
Sourcepub fn destroy_entity(&self, entity: &str) -> Result<()>
pub fn destroy_entity(&self, entity: &str) -> Result<()>
Delete all components for an entity.
Sourcepub fn query_dsl(&self, dsl: &Value) -> Result<Vec<AssetEntry>>
pub fn query_dsl(&self, dsl: &Value) -> Result<Vec<AssetEntry>>
Query from JSON DSL — primary interface for DAG actors.
{ "type": "mesh", "tags": ["snake"], "$sort": "newest", "$limit": 5 }Sourcepub fn query(&self, q: &AssetQuery) -> Result<Vec<AssetEntry>>
pub fn query(&self, q: &AssetQuery) -> Result<Vec<AssetEntry>>
Query metadata (no blob data).