Skip to main content

Dump

Struct Dump 

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

A PostgreSQL dump archive.

Implementations§

Source§

impl Dump

Source

pub fn load<P: AsRef<Path>>(path: P) -> Result<Self>

Load a dump from a file or directory.

Automatically detects the format:

  • Directory → directory format (-Fd)
  • File starting with PGDMP → custom format (-Fc)
  • File with ustar header → tar format (-Ft)
Source

pub fn new(dbname: &str, encoding: &str, appear_as: &str) -> Result<Self>

Create a new empty dump.

Source

pub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()>

Save the dump to a file or directory.

For custom format (-Fc), writes to a temporary file first, then atomically renames to avoid leaving a partial file on failure. For directory format (-Fd), writes directly to the directory.

Source

pub fn set_format(&mut self, format: Format)

Set the output format for writing.

Note: Tar format does not support compression. If compression is set when switching to tar format, it will be reset to None.

Source

pub fn version(&self) -> ArchiveVersion

The archive format version.

Source

pub fn compression(&self) -> CompressionAlgorithm

The compression algorithm used.

Source

pub fn dbname(&self) -> &str

The database name.

Source

pub fn server_version(&self) -> &str

The PostgreSQL server version string.

Source

pub fn dump_version(&self) -> &str

The pg_dump version string.

Source

pub fn timestamp(&self) -> &Timestamp

The archive creation timestamp.

Source

pub fn entries(&self) -> &[Entry]

All TOC entries.

Source

pub fn lookup_entry( &self, desc: &ObjectType, namespace: &str, tag: &str, ) -> Option<&Entry>

Look up an entry by object type, namespace, and tag.

Source

pub fn get_entry(&self, dump_id: i32) -> Option<&Entry>

Get an entry by dump_id.

Source

pub fn get_entry_mut(&mut self, dump_id: i32) -> Option<&mut Entry>

Get a mutable reference to an entry by dump_id.

Source

pub fn table_data( &self, namespace: &str, table: &str, ) -> Result<impl Iterator<Item = &str>>

Iterate over table data rows for the given namespace and table.

Each yielded item is a line from the COPY data (without the trailing newline).

Source

pub fn blobs(&self) -> Vec<(i32, &[u8])>

Iterate over all large objects (blobs) across all BLOBS entries.

Yields (oid, data) pairs where oid is the large object OID and data is the decompressed blob content.

Source

pub fn add_blob(&mut self, oid: i32, data: Vec<u8>) -> Result<i32>

Add a large object (blob) to a BLOBS entry.

If no BLOBS entry exists yet, one is created automatically. Returns the OID of the added blob.

Source

pub fn entry_data(&self, dump_id: i32) -> Option<&[u8]>

Get the raw data bytes for an entry by dump_id.

Source

pub fn add_entry( &mut self, desc: ObjectType, namespace: Option<&str>, tag: Option<&str>, owner: Option<&str>, defn: Option<&str>, drop_stmt: Option<&str>, copy_stmt: Option<&str>, dependencies: &[i32], ) -> Result<i32>

Add a new TOC entry.

Source

pub fn set_entry_data(&mut self, dump_id: i32, data: Vec<u8>) -> Result<()>

Set the data for an entry (raw COPY format bytes).

Source

pub fn set_compression(&mut self, alg: CompressionAlgorithm)

Set compression algorithm for writing.

Source

pub fn sort_entries(&mut self)

Sort TOC entries using the same weighted topological sort as pg_dump.

Entries are first sorted by object-type priority (schema before table, table before index, etc.), then by namespace and name. A topological sort pass then reorders only as needed to satisfy the dependency graph, preserving the cosmetic ordering wherever possible.

This is called automatically by Dump::save, but can also be called manually if you need the sorted order before writing.

Trait Implementations§

Source§

impl Debug for Dump

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Dump

§

impl RefUnwindSafe for Dump

§

impl Send for Dump

§

impl Sync for Dump

§

impl Unpin for Dump

§

impl UnsafeUnpin for Dump

§

impl UnwindSafe for Dump

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.