Skip to main content

PostArchiverManager

Struct PostArchiverManager 

Source
pub struct PostArchiverManager<C = Connection> {
    pub caches: Arc<Mutex<ManagerCaches>>,
    pub path: PathBuf,
    /* private fields */
}
Available on crate feature utils only.
Expand description

Core manager type for post archive operations with SQLite backend

Provides database connection management and access to entity operations through the Binded type via bind().

§Examples

use post_archiver::manager::PostArchiverManager;

let manager = PostArchiverManager::open_or_create("./data").unwrap();

Fields§

§caches: Arc<Mutex<ManagerCaches>>§path: PathBuf

Implementations§

Source§

impl PostArchiverManager

Source

pub fn create<P>(path: P) -> Result<Self>
where P: AsRef<Path>,

Creates a new archive at the specified path

§Panics

Panics if the path already contains a database file.

§Examples
use post_archiver::manager::PostArchiverManager;

let manager = PostArchiverManager::create("./new_archive").unwrap();
Source

pub fn open<P>(path: P) -> Result<Option<Self>>
where P: AsRef<Path>,

Opens an existing archive at the specified path

§Returns
  • Ok(Some(manager)) if archive exists and version is compatible
  • Ok(None) if archive doesn’t exist
  • Err(_) on database errors
§Examples
use post_archiver::manager::PostArchiverManager;

if let Some(manager) = PostArchiverManager::open("./archive").unwrap() {
    println!("Archive opened successfully");
}
Source

pub fn open_uncheck<P>(path: P) -> Result<Option<Self>>
where P: AsRef<Path>,

Opens an existing archive at the specified path without checking version.

§Returns
  • Ok(Some(manager)) if archive exists
  • Ok(None) if archive doesn’t exist
  • Err(_) on database errors
Source

pub fn open_or_create<P>(path: P) -> Result<Self>
where P: AsRef<Path>,

Opens an existing archive or creates a new one if it doesn’t exist

§Examples
use post_archiver::manager::PostArchiverManager;

let manager = PostArchiverManager::open_or_create("./archive").unwrap();
Source

pub fn open_in_memory() -> Result<Self>

Creates an in-memory database

§Examples
use post_archiver::manager::PostArchiverManager;

let manager = PostArchiverManager::open_in_memory().unwrap();
Source

pub fn transaction(&mut self) -> Result<PostArchiverManager<Transaction<'_>>>

Starts a new transaction

§Examples
use post_archiver::manager::PostArchiverManager;

let mut manager = PostArchiverManager::open_in_memory().unwrap();
let mut tx = manager.transaction().unwrap();
// ... perform operations
tx.commit().unwrap();
Source§

impl PostArchiverManager<Transaction<'_>>

Source

pub fn commit(self) -> Result<()>

Commits the transaction

Source§

impl<C> PostArchiverManager<C>

Source

pub fn conn(&self) -> &Connection

Returns a reference to the underlying database connection

Source

pub fn bind<Id: BindableId>(&self, id: Id) -> Binded<'_, Id, C>

Bind an entity ID to get a Binded context for update/delete/relation operations.

The type parameter is inferred from the ID argument — no turbofish needed.

§Examples
let binded = manager.bind(post_id);
// binded is Binded<'_, PostId>
Source§

impl<C: PostArchiverConnection> PostArchiverManager<C>

Source

pub fn authors(&self) -> AuthorQuery<'_, C>

Entry point for the author query builder.

Source

pub fn get_author(&self, id: AuthorId) -> Result<Option<Author>>

Fetch a single author by primary key. Returns None if not found.

Source

pub fn find_author_by_alias( &self, source: &str, platform: PlatformId, ) -> Result<Option<AuthorId>>

Find an author ID by alias (source + platform).

Source

pub fn list_author_aliases(&self, author: AuthorId) -> Result<Vec<Alias>>

Fetch all aliases belonging to the given author.

Source§

impl<C: PostArchiverConnection> PostArchiverManager<C>

Source

pub fn collections(&self) -> CollectionQuery<'_, C>

Entry point for the collection query builder.

Source

pub fn get_collection(&self, id: CollectionId) -> Result<Option<Collection>>

Fetch a single collection by primary key. Returns None if not found.

Source

pub fn find_collection(&self, name: &str) -> Result<Option<CollectionId>>

Find a collection ID by name (exact match).

Source

pub fn find_collection_by_source( &self, source: &str, ) -> Result<Option<CollectionId>>

Find a collection ID by its source field.

Source§

impl<C: PostArchiverConnection> PostArchiverManager<C>

Source

pub fn get_file_meta(&self, id: FileMetaId) -> Result<Option<FileMeta>>

Fetch a single FileMeta by primary key. Returns None if not found.

Source

pub fn find_file_meta( &self, post: PostId, filename: &str, ) -> Result<Option<FileMetaId>>

Find a FileMetaId by owning post and filename.

Source§

impl<C: PostArchiverConnection> PostArchiverManager<C>

Source

pub fn platforms(&self) -> PlatformQuery<'_, C>

Entry point for the platform query builder.

Source

pub fn get_platform(&self, id: PlatformId) -> Result<Option<Platform>>

Fetch a single platform by primary key. Returns None if not found.

Source

pub fn find_platform(&self, name: &str) -> Result<Option<PlatformId>>

Find a platform ID by name (exact match, case-sensitive).

Source§

impl<C: PostArchiverConnection> PostArchiverManager<C>

Source

pub fn posts(&self) -> PostQuery<'_, C>

Entry point for the post query builder.

Source

pub fn get_post(&self, id: PostId) -> Result<Option<Post>>

Fetch a single post by primary key. Returns None if not found.

Source

pub fn find_post(&self, source: &str) -> Result<Option<PostId>>

Look up a post ID by its source field.

Source

pub fn find_post_with_updated( &self, source: &str, updated: &DateTime<Utc>, ) -> Result<Option<PostId>>

Look up a post ID by its source field, but only if its updated timestamp is not earlier than the given value.

Source§

impl<C: PostArchiverConnection> PostArchiverManager<C>

Source

pub fn tags(&self) -> TagQuery<'_, C>

Entry point for the tag query builder.

Source

pub fn get_tag(&self, id: TagId) -> Result<Option<Tag>>

Fetch a single tag by primary key. Returns None if not found.

Source

pub fn find_tag( &self, name: &str, platform: Option<PlatformId>, ) -> Result<Option<TagId>>

Find a tag ID by name and optional platform (exact match).

Source§

impl<T> PostArchiverManager<T>

Source

pub fn import_author(&self, author: UnsyncAuthor) -> Result<AuthorId>

Available on crate feature importer only.

Import an author into the archive.

If the author already exists (by aliases), it updates their name, aliases, and updated date.

§Errors

Returns Error if there was an error accessing the database.

Source§

impl<T> PostArchiverManager<T>

Source

pub fn import_file_meta<U>( &self, post: PostId, file_meta: &UnsyncFileMeta<U>, ) -> Result<FileMetaId>

Available on crate feature importer only.

Create or update a file metadata entry in the archive.

Takes a file metadata object and either creates a new entry or updates an existing one. if a file metadata with the same filename (and post id) already exists, it only updates metadata

§Errors

Returns Error if there was an error accessing the database.

Source

pub fn import_file_meta_with_content<U>( &self, post: PostId, file_meta: &UnsyncFileMeta<U>, ) -> Result<FileMetaId>

Available on crate feature importer only.

Create or update a file metadata entry in the archive, and write file_meta.data to disk.

Behaves like import_file_meta for the database entry, then writes the content of file_meta.data to <archive_path>/<post_dir>/<filename>, creating intermediate directories as needed.

§Errors

Returns Error if there was an error accessing the database.

Source

pub fn import_file_meta_by_rename( &self, post: PostId, file_meta: &UnsyncFileMeta<PathBuf>, ) -> Result<FileMetaId>

Available on crate feature importer only.

Create or update a file metadata entry in the archive by moving a buffered file into it.

Behaves like import_file_meta for the database entry, then moves the already-buffered file at file_meta.data to <archive_path>/<post_dir>/<filename>, creating intermediate directories as needed.

Uses std::fs::rename for an atomic, zero-copy move. The source file and the archive must reside on the same filesystem; cross-device moves will fail. Use import_file_meta_with_content instead when the source and destination may be on different filesystems.

§Errors

Returns Error if there was an error accessing the database.

Source§

impl<T> PostArchiverManager<T>

Source

pub fn import_post<U>( &self, post: UnsyncPost<U>, update_relation: bool, ) -> Result<(PostId, Vec<AuthorId>, Vec<CollectionId>, Vec<(PathBuf, U)>)>

Available on crate feature importer only.

Import a post into the archive.

If the post already exists (by source), it updates its title, platform, published date,

§Parameters
  • update_relation: update the relations of authors and collections after importing.
§Errors

Returns Error if there was an error accessing the database.

Source

pub fn import_post_with_files<U: WritableFileMeta>( &self, post: UnsyncPost<U>, ) -> Result<PostId>

Available on crate feature importer only.
Source

pub fn import_post_with_rename_files( &self, post: UnsyncPost<PathBuf>, ) -> Result<PostId>

Available on crate feature importer only.
Source

pub fn import_posts<U>( &self, posts: impl IntoIterator<Item = UnsyncPost<U>>, update_relation: bool, ) -> Result<(Vec<PostId>, Vec<(PathBuf, U)>)>

Available on crate feature importer only.

Import multiple posts into the archive.

This function processes each post, importing its authors, collections, and files.

§Parameters
  • update_relation: update the relations of authors and collections after importing.
§Errors

Returns Error if there was an error accessing the database.

Source

pub fn import_posts_with_files<U: WritableFileMeta>( &self, posts: impl IntoIterator<Item = UnsyncPost<U>>, ) -> Result<Vec<PostId>>

Available on crate feature importer only.
Source

pub fn import_posts_with_rename_files( &self, posts: impl IntoIterator<Item = UnsyncPost<PathBuf>>, ) -> Result<Vec<PostId>>

Available on crate feature importer only.
Source§

impl<T> PostArchiverManager<T>

Source

pub fn import_collection( &self, collection: UnsyncCollection, ) -> Result<CollectionId>

Available on crate feature importer only.

Import a collection into the archive.

If the collection already exists (by source), it updates its name and returns the existing ID.

§Errors

Returns Error if there was an error accessing the database.

Source

pub fn import_collections( &self, collections: impl IntoIterator<Item = UnsyncCollection>, ) -> Result<Vec<CollectionId>>

Available on crate feature importer only.

Import multiple collections into the archive.

This method takes an iterator of UnsyncCollection and imports each one.

§Errors

Returns Error if there was an error accessing the database.

Source§

impl<T> PostArchiverManager<T>

Source

pub fn import_tag(&self, tag: UnsyncTag) -> Result<TagId>

Available on crate feature importer only.

Import a tag into the archive.

If the tag already exists, it returns the existing ID.

§Errors

Returns Error if there was an error accessing the database.

Source

pub fn import_tags( &self, tags: impl IntoIterator<Item = UnsyncTag>, ) -> Result<Vec<TagId>>

Available on crate feature importer only.

Import multiple tags into the archive.

If a tag already exists, it returns the existing ID.

§Errors

Returns Error if there was an error accessing the database.

Source§

impl<T> PostArchiverManager<T>

Source

pub fn import_platform(&self, platform: String) -> Result<PlatformId>

Available on crate feature importer only.

Import a platform into the archive.

If the platform already exists, it returns the existing ID.

§Errors

Returns Error if there was an error accessing the database.

Trait Implementations§

Source§

impl<C: Debug> Debug for PostArchiverManager<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C> Freeze for PostArchiverManager<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for PostArchiverManager<C>
where C: RefUnwindSafe,

§

impl<C> Send for PostArchiverManager<C>
where C: Send,

§

impl<C> Sync for PostArchiverManager<C>
where C: Sync,

§

impl<C> Unpin for PostArchiverManager<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for PostArchiverManager<C>
where C: UnsafeUnpin,

§

impl<C> UnwindSafe for PostArchiverManager<C>
where C: UnwindSafe,

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, 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, 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.