Skip to main content

Database

Struct Database 

Source
pub struct Database { /* private fields */ }
Expand description

Database handle for queue and history persistence.

Implementations§

Source§

impl Database

Source

pub fn open(path: &Path) -> Result<Self, NzbError>

Open (or create) the database at the given path.

Source

pub fn open_memory() -> Result<Self, NzbError>

Open an in-memory database (for testing).

Source

pub fn get_setting(&self, key: &str) -> Option<String>

Read a setting by key.

Source

pub fn set_setting(&self, key: &str, value: &str)

Write a setting (upsert).

Source

pub fn queue_insert(&self, job: &NzbJob) -> Result<(), NzbError>

Insert a new job into the queue.

Source

pub fn queue_update_progress( &self, id: &str, status: JobStatus, downloaded_bytes: u64, articles_downloaded: usize, articles_failed: usize, files_completed: usize, ) -> Result<(), NzbError>

Update job progress in the queue.

Source

pub fn queue_update_priority( &self, id: &str, priority: i32, ) -> Result<(), NzbError>

Update job priority in the queue.

Source

pub fn queue_remove(&self, id: &str) -> Result<(), NzbError>

Remove a job from the queue.

Source

pub fn queue_list(&self) -> Result<Vec<NzbJob>, NzbError>

List all jobs in the queue, ordered by priority then add time.

Source

pub fn history_insert(&self, entry: &HistoryEntry) -> Result<(), NzbError>

Move a completed/failed job to history.

Source

pub fn history_list(&self, limit: usize) -> Result<Vec<HistoryEntry>, NzbError>

List history entries, most recent first.

Source

pub fn history_get_nzb_data( &self, id: &str, ) -> Result<Option<Vec<u8>>, NzbError>

Get the raw NZB data for a history entry (for retry).

Source

pub fn history_enforce_retention( &self, max_entries: usize, ) -> Result<(), NzbError>

Enforce history retention limit by deleting oldest entries.

Source

pub fn history_get(&self, id: &str) -> Result<Option<HistoryEntry>, NzbError>

Get a single history entry by ID.

Source

pub fn queue_store_job_data( &self, id: &str, data: &[u8], ) -> Result<(), NzbError>

Store serialized job file/article state for resume support.

Source

pub fn queue_load_job_data(&self, id: &str) -> Result<Option<Vec<u8>>, NzbError>

Load serialized job file/article state for resume.

Source

pub fn queue_store_nzb_data( &self, id: &str, nzb_data: &[u8], ) -> Result<(), NzbError>

Store raw NZB data for a queue job.

Source

pub fn queue_get_nzb_data(&self, id: &str) -> Result<Option<Vec<u8>>, NzbError>

Get raw NZB data from a queue job.

Source

pub fn history_count(&self) -> Result<usize, NzbError>

Count history entries.

Source

pub fn history_remove(&self, id: &str) -> Result<(), NzbError>

Remove a history entry.

Source

pub fn history_clear(&self) -> Result<(), NzbError>

Clear all history.

Source

pub fn history_store_logs( &self, id: &str, logs_json: &str, ) -> Result<(), NzbError>

Store per-job logs for a history entry.

Source

pub fn history_get_logs(&self, id: &str) -> Result<Option<String>, NzbError>

Get per-job logs for a history entry.

Source

pub fn rss_item_upsert(&self, item: &RssItem) -> Result<(), NzbError>

Upsert an RSS feed item (insert or ignore if already exists).

Source

pub fn rss_items_batch_upsert( &self, items: &[RssItem], ) -> Result<usize, NzbError>

Batch upsert RSS feed items in a single transaction. Returns the number of newly inserted items.

Source

pub fn rss_item_exists(&self, id: &str) -> Result<bool, NzbError>

Check if an RSS item ID already exists in the database.

Source

pub fn rss_items_list( &self, feed_name: Option<&str>, limit: usize, ) -> Result<Vec<RssItem>, NzbError>

List RSS items, optionally filtered by feed name, ordered by first_seen_at DESC.

Source

pub fn rss_item_get(&self, id: &str) -> Result<Option<RssItem>, NzbError>

Get a single RSS item by ID.

Source

pub fn rss_item_mark_downloaded( &self, id: &str, category: Option<&str>, ) -> Result<(), NzbError>

Mark an RSS item as downloaded.

Source

pub fn rss_item_count(&self) -> Result<usize, NzbError>

Count total RSS items.

Source

pub fn rss_items_prune(&self, keep: usize) -> Result<usize, NzbError>

Prune RSS items to keep only the N most recent (by first_seen_at).

Source

pub fn rss_rule_insert(&self, rule: &RssRule) -> Result<(), NzbError>

Insert a new RSS download rule. feed_names is stored as comma-separated string in the DB.

Source

pub fn rss_rule_list(&self) -> Result<Vec<RssRule>, NzbError>

List all RSS download rules.

Source

pub fn rss_rule_update(&self, rule: &RssRule) -> Result<(), NzbError>

Update an RSS download rule.

Source

pub fn rss_rule_delete(&self, id: &str) -> Result<(), NzbError>

Delete an RSS download rule.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more