# articles-rs
A Rust library for managing articles in a PostgreSQL database.
## Features
- CRUD operations for articles with fields like title, slug, description, content, etc.
- Support for article status tracking and publishing dates
- Optional hero image association
- Flexible filtering capabilities
- Async/await support using SQLx
- UUID-based article identification
## Installation
Add this to your `Cargo.toml`:
```toml
[dependencies]
articles-rs = "0.1.3"
```
## Usage Example
```rust
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(())
}