| Crates.io | articles-rs |
| lib.rs | articles-rs |
| version | 0.1.4 |
| created_at | 2024-11-23 02:19:49.065735+00 |
| updated_at | 2025-02-09 19:26:04.564474+00 |
| description | interfaces with an articles database |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1458180 |
| size | 50,569 |
A Rust library for managing articles in a PostgreSQL database.
Add this to your Cargo.toml:
[dependencies]
articles-rs = "0.1.3"
use chrono::Utc;
use crate::{articles::ArticleService, config::DbConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the service
let config = DbConfig {
host: "localhost".to_string(),
port: 5432,
username: "postgres".to_string(),
password: "password".to_string(),
database: "blog_db".to_string(),
};
let service = ArticleService::new(config).await;
// Create a new article
let article_id = service
.create_article(
"My First Article",
"my-first-article",
"This is a test article",
"John Doe",
None,
)
.await?;
// Retrieve the article
let article = service.get_article_by_id(article_id).await?;
println!("Created article: {:?}", article);
// Update the article with some images
service
.update_article(
article_id,
"Updated Title",
"my-first-article",
"Updated description",
vec!["John Doe".to_string()],
Some("PUBLISHED"),
None,
"Article content goes here...",
vec!["images/hero.jpg".to_string()],
"",
None,
None,
)
.await?;
Ok(())
}