Untitled

mail@pastecode.io avatar
unknown
plain_text
23 days ago
2.3 kB
2
Indexable
Never
pub async fn fetch_edit_gallery_videos() -> Result<Vec<EditGalleryVideo>, Error> {
    // Connect to the PostgreSQL database
    let (client, connection) = tokio_postgres::connect("postgresql://postgres:095165Aa@localhost:5432/cosmoem", NoTls)
        .await
        .expect("Failed to connect to database");

    // Spawn a task to handle the connection
    tokio::spawn(async move {
        if let Err(e) = connection.await {
            eprintln!("Connection error: {}", e);
        }
    });

    // Prepare and execute the SQL query
    let query = "SELECT * FROM gallery";
    let statement: Statement = client.prepare(query).await.expect("Failed to prepare statement");

    let rows = client.query(&statement, &[]).await?;

    // Process the rows into Video structs
    let mut videos = Vec::new();
    for row in rows {
        let video = EditGalleryVideo::new(
            row.get("video_name"),
            row.get("video_path"),
            row.get("childs_from_video"),
            row.get("created_at"),
        );

        videos.push(video);
    }

    // Return the fetched videos
    Ok(videos)
}

pub async fn fetch_gallery_videos() -> Result<Vec<GalleryVideo>, Error> {
    // Connect to the PostgreSQL database
    let (client, connection) = tokio_postgres::connect("postgresql://postgres:095165Aa@localhost:5432/cosmoem", NoTls)
        .await
        .expect("Failed to connect to database");

    // Spawn a task to handle the connection
    tokio::spawn(async move {
        if let Err(e) = connection.await {
            eprintln!("Connection error: {}", e);
        }
    });

    // Prepare and execute the SQL query
    let query = "SELECT * FROM gallery";
    let statement: Statement = client.prepare(query).await.expect("Failed to prepare statement");

    let rows = client.query(&statement, &[]).await?;

    // Process the rows into Video structs
    let mut videos = Vec::new();
    for row in rows {
        let video = GalleryVideo::new(
            row.get("video_name"),
            row.get("video_path"),
            row.get("derived_from"),
            row.get("created_at"),
        );

        videos.push(video);
    }

    // Return the fetched videos
    Ok(videos)
}
Leave a Comment