use netabase_store::{NetabaseModel, netabase, netabase_definition_module, streams};
#[netabase_definition_module(SimpleBlogDefinition, SimpleBlogKeys)]
#[streams(UserTopic, PostTopic)]
mod simple_blog {
use super::*;
#[derive(
NetabaseModel,
Clone,
Debug,
PartialEq,
bincode::Encode,
bincode::Decode,
serde::Serialize,
serde::Deserialize,
)]
#[netabase(SimpleBlogDefinition)]
pub struct User {
#[primary_key]
pub id: u64,
pub username: String,
}
#[derive(
NetabaseModel,
Clone,
Debug,
PartialEq,
bincode::Encode,
bincode::Decode,
serde::Serialize,
serde::Deserialize,
)]
#[netabase(SimpleBlogDefinition)]
pub struct Post {
#[primary_key]
pub id: u64,
pub title: String,
pub author_id: u64,
}
}
use simple_blog::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("🚀 Simple Netabase Streams Test");
println!("================================\n");
println!("📋 Testing basic subscription functionality...");
let user_topic = SimpleBlogDefinitionSubscriptions::UserTopic;
let post_topic = SimpleBlogDefinitionSubscriptions::PostTopic;
println!(" - UserTopic: {}", user_topic.as_str());
println!(" - PostTopic: {}", post_topic.as_str());
println!("\n🔧 Testing subscription manager...");
let manager = SimpleBlogDefinitionSubscriptionManager::new();
println!(" ✅ Manager created successfully");
println!("\n🌲 Testing subscription tree access:");
if let Some(_user_tree) = manager.get_tree(user_topic) {
println!(" ✅ UserTopic tree accessible");
}
if let Some(_post_tree) = manager.get_tree(post_topic) {
println!(" ✅ PostTopic tree accessible");
}
println!("\n✨ Simple streams test completed successfully!");
println!("\n💡 This demonstrates:");
println!(" - Streams macro integration with netabase_definition_module");
println!(" - Generated subscription topics enum");
println!(" - Subscription manager creation");
println!(" - Topic-based tree access");
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_subscription_enum_generation() {
let user_topic = SimpleBlogDefinitionSubscriptions::UserTopic;
let post_topic = SimpleBlogDefinitionSubscriptions::PostTopic;
assert_eq!(user_topic.as_str(), "UserTopic");
assert_eq!(post_topic.as_str(), "PostTopic");
}
#[test]
fn test_subscription_manager() {
let manager = SimpleBlogDefinitionSubscriptionManager::new();
assert!(
manager
.get_tree(SimpleBlogDefinitionSubscriptions::UserTopic)
.is_some()
);
assert!(
manager
.get_tree(SimpleBlogDefinitionSubscriptions::PostTopic)
.is_some()
);
}
#[test]
fn test_topic_names() {
let topic_names = SimpleBlogDefinitionSubscriptions::all_topics();
assert!(topic_names.contains(&"UserTopic"));
assert!(topic_names.contains(&"PostTopic"));
assert_eq!(topic_names.len(), 2);
}
}