Files
georm/examples/postgres/users-comments-and-followers/src/cli/mod.rs
Lucien Cartier-Tilet 190c4d7b1d feat(examples): add PostgreSQL example with user relationship
Adds an example demonstrating user, comment, and follower relationship
including:
- User management with profiles
- Comments (not really useful, just for showcasing)
- Follower/follozing relationships
- Ineractive CLI interface with CRUD operations
- Database migrations for the example schema
2025-06-09 21:30:35 +02:00

41 lines
975 B
Rust

use clap::{Parser, Subcommand};
mod comments;
mod followers;
mod users;
type Result = crate::Result<()>;
pub trait Executable {
async fn execute(&self, pool: &sqlx::PgPool) -> Result;
}
#[derive(Debug, Clone, Parser)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
impl Executable for Cli {
async fn execute(&self, pool: &sqlx::PgPool) -> Result {
self.command.execute(pool).await
}
}
#[derive(Debug, Clone, Subcommand)]
pub enum Commands {
Users(users::UserArgs),
Followers(followers::FollowersArgs),
Comments(comments::CommentArgs),
}
impl Executable for Commands {
async fn execute(&self, pool: &sqlx::PgPool) -> Result {
match self {
Commands::Users(user_args) => user_args.execute(pool).await,
Commands::Followers(followers_args) => followers_args.execute(pool).await,
Commands::Comments(comment_args) => comment_args.execute(pool).await,
}
}
}