pub struct ChannelBuilder { /* private fields */ }
Expand description
Builder for channel subscriptions
Provides a fluent API for configuring realtime subscriptions.
§Examples
let client = Client::new("your-url", "your-key")?;
let subscription = client.realtime()
.channel("public-posts")
.table("posts")
.event(RealtimeEvent::Insert)
.filter("author_id=eq.123")
.subscribe(|message| {
println!("New post by author 123: {:?}", message);
})
.await?;
Implementations§
Source§impl ChannelBuilder
impl ChannelBuilder
Sourcepub fn table(self, table: &str) -> Self
pub fn table(self, table: &str) -> Self
Set the table to subscribe to
§Examples
let client = Client::new("your-url", "your-key")?;
let subscription = client.realtime()
.channel("posts")
.table("posts") // Subscribe to the 'posts' table
.subscribe(|_| {})
.await?;
Sourcepub fn schema(self, schema: &str) -> Self
pub fn schema(self, schema: &str) -> Self
Set the schema (default: “public”)
§Examples
let client = Client::new("your-url", "your-key")?;
let subscription = client.realtime()
.channel("admin-logs")
.schema("admin") // Subscribe to 'admin' schema
.table("logs")
.subscribe(|_| {})
.await?;
Sourcepub fn event(self, event: RealtimeEvent) -> Self
pub fn event(self, event: RealtimeEvent) -> Self
Set the event type filter
§Examples
let client = Client::new("your-url", "your-key")?;
// Only listen to INSERT events
let subscription = client.realtime()
.channel("new-posts")
.table("posts")
.event(RealtimeEvent::Insert)
.subscribe(|_| {})
.await?;
Sourcepub fn filter(self, filter: &str) -> Self
pub fn filter(self, filter: &str) -> Self
Set a filter for the subscription
§Examples
let client = Client::new("your-url", "your-key")?;
// Only posts by specific author
let subscription = client.realtime()
.channel("my-posts")
.table("posts")
.filter("author_id=eq.123")
.subscribe(|_| {})
.await?;
Sourcepub async fn subscribe<F>(self, callback: F) -> Result<String>
pub async fn subscribe<F>(self, callback: F) -> Result<String>
Subscribe with a callback function
§Examples
let client = Client::new("your-url", "your-key")?;
let subscription_id = client.realtime()
.channel("posts")
.table("posts")
.subscribe(|message| {
match message.event.as_str() {
"INSERT" => println!("New post created!"),
"UPDATE" => println!("Post updated!"),
"DELETE" => println!("Post deleted!"),
_ => println!("Other event: {}", message.event),
}
})
.await?;
Auto Trait Implementations§
impl Freeze for ChannelBuilder
impl !RefUnwindSafe for ChannelBuilder
impl Send for ChannelBuilder
impl Sync for ChannelBuilder
impl Unpin for ChannelBuilder
impl !UnwindSafe for ChannelBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more