mirror of
https://github.com/Phundrak/georm.git
synced 2025-12-16 09:41:53 +01:00
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
41 lines
975 B
Rust
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,
|
|
}
|
|
}
|
|
}
|