5 releases
new 0.1.4 | Feb 9, 2025 |
---|---|
0.1.3 | Feb 8, 2025 |
0.1.2 | Feb 8, 2025 |
0.1.1 | Nov 25, 2024 |
0.1.0 | Nov 23, 2024 |
#501 in Database interfaces
400 downloads per month
41KB
821 lines
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
:
[dependencies]
articles-rs = "0.1.3"
Usage Example
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(())
}
Dependencies
~38–51MB
~890K SLoC