export_database_to_bytes

Function export_database_to_bytes 

Source
pub async fn export_database_to_bytes(
    storage: &mut BlockStorage,
    max_size_bytes: Option<u64>,
) -> Result<Vec<u8>, DatabaseError>
Expand description

Export database from BlockStorage to SQLite .db file format

Reads all allocated blocks from storage and concatenates them into a standard SQLite database file that can be opened by any SQLite client.

§Arguments

  • storage - BlockStorage instance containing the database blocks

§Returns

  • Ok(Vec<u8>) - Complete SQLite database file as bytes
  • Err(DatabaseError) - If export fails

§Process

  1. Sync storage to ensure all changes are persisted
  2. Read block 0 (header) to determine database size
  3. Read all allocated blocks
  4. Concatenate blocks and truncate to exact database size

§Example

use absurder_sql::storage::export::export_database_to_bytes;
use absurder_sql::storage::BlockStorage;

async fn export_example(mut storage: BlockStorage) -> Result<Vec<u8>, absurder_sql::types::DatabaseError> {
    // Export with default 2GB limit
    let db_bytes = export_database_to_bytes(&mut storage, None).await?;
    // Save db_bytes to file or send to browser for download
    Ok(db_bytes)
}