Untitled
unknown
plain_text
a year ago
2.3 kB
9
Indexable
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)
}Editor is loading...
Leave a Comment