pub struct Dump { /* private fields */ }Expand description
A PostgreSQL dump archive.
Implementations§
Source§impl Dump
impl Dump
Sourcepub fn load<P: AsRef<Path>>(path: P) -> Result<Self>
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)
Sourcepub fn new(dbname: &str, encoding: &str, appear_as: &str) -> Result<Self>
pub fn new(dbname: &str, encoding: &str, appear_as: &str) -> Result<Self>
Create a new empty dump.
Sourcepub fn save<P: AsRef<Path>>(&self, path: P) -> Result<()>
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.
Sourcepub fn set_format(&mut self, format: Format)
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.
Sourcepub fn version(&self) -> ArchiveVersion
pub fn version(&self) -> ArchiveVersion
The archive format version.
Sourcepub fn compression(&self) -> CompressionAlgorithm
pub fn compression(&self) -> CompressionAlgorithm
The compression algorithm used.
Sourcepub fn server_version(&self) -> &str
pub fn server_version(&self) -> &str
The PostgreSQL server version string.
Sourcepub fn dump_version(&self) -> &str
pub fn dump_version(&self) -> &str
The pg_dump version string.
Sourcepub fn lookup_entry(
&self,
desc: &ObjectType,
namespace: &str,
tag: &str,
) -> Option<&Entry>
pub fn lookup_entry( &self, desc: &ObjectType, namespace: &str, tag: &str, ) -> Option<&Entry>
Look up an entry by object type, namespace, and tag.
Sourcepub fn get_entry_mut(&mut self, dump_id: i32) -> Option<&mut Entry>
pub fn get_entry_mut(&mut self, dump_id: i32) -> Option<&mut Entry>
Get a mutable reference to an entry by dump_id.
Sourcepub fn table_data(
&self,
namespace: &str,
table: &str,
) -> Result<impl Iterator<Item = &str>>
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).
Sourcepub fn blobs(&self) -> Vec<(i32, &[u8])>
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.
Sourcepub fn add_blob(&mut self, oid: i32, data: Vec<u8>) -> Result<i32>
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.
Sourcepub fn entry_data(&self, dump_id: i32) -> Option<&[u8]>
pub fn entry_data(&self, dump_id: i32) -> Option<&[u8]>
Get the raw data bytes for an entry by dump_id.
Sourcepub 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>
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.
Sourcepub fn set_entry_data(&mut self, dump_id: i32, data: Vec<u8>) -> Result<()>
pub fn set_entry_data(&mut self, dump_id: i32, data: Vec<u8>) -> Result<()>
Set the data for an entry (raw COPY format bytes).
Sourcepub fn set_compression(&mut self, alg: CompressionAlgorithm)
pub fn set_compression(&mut self, alg: CompressionAlgorithm)
Set compression algorithm for writing.
Sourcepub fn sort_entries(&mut self)
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.