use crate::errors::Result;
use sqlx::PgPool;
#[derive(Clone)]
pub struct NotifyService {
pool: PgPool,
}
impl NotifyService {
pub fn new(pool: PgPool) -> Self {
Self { pool }
}
pub async fn notify(&self, channel: &str, payload: &str) -> Result<()> {
sqlx::query("SELECT pg_notify($1, $2)")
.bind(channel)
.bind(payload)
.execute(&self.pool)
.await?;
Ok(())
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_channel_formatting() {
let channel = format!("events.{}", "user_123");
assert_eq!(channel, "events.user_123");
}
}