mirror of
https://github.com/Phundrak/georm.git
synced 2025-12-16 17:51:52 +01:00
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
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user