Use with Tauri

Keep the database in Rust application state and expose focused commands to your webview.

Use the native Rust SDK in a Tauri app. Keep the database in Rust state and expose application operations such as adding or searching notes to the webview.

Add the oliphaunt dependency to the Tauri Rust application as shown in the Rust quickstart. The SDK includes its matching runtime resources.

Open persistent application storage

Use AsyncOliphaunt so database work does not block Tauri's async executor. This helper opens a root beneath the application-data directory and prepares a table:

use oliphaunt::{AsyncOliphaunt, DatabaseStorage};
use std::path::PathBuf;

struct AppDatabase(AsyncOliphaunt);

async fn open_database(app_data: PathBuf) -> oliphaunt::Result<AsyncOliphaunt> {
    let db = AsyncOliphaunt::builder()
        .storage(DatabaseStorage::Directory(app_data.join("postgres")))
        .direct()
        .open()
        .await?;
    db.execute("CREATE TABLE IF NOT EXISTS notes (body text NOT NULL)").await?;
    Ok(db)
}

During your existing Tauri builder's setup, resolve the directory and register the handle:

use tauri::Manager;

// Add this setup callback to your existing tauri::Builder.
.setup(|app| {
    let app_data = app.path().app_data_dir()?;
    let db = tauri::async_runtime::block_on(open_database(app_data))?;
    app.manage(AppDatabase(db));
    Ok(())
})

Expose application commands

Use managed state in an async command, bind user values, and register the command with tauri::generate_handler![add_note]:

#[tauri::command]
async fn add_note(
    db: tauri::State<'_, AppDatabase>,
    body: String,
) -> Result<(), String> {
    db.0.execute_with_params("INSERT INTO notes (body) VALUES ($1)", [body])
        .await
        .map_err(|error| error.to_string())?;
    Ok(())
}

The webview calls the command through Tauri:

import { invoke } from '@tauri-apps/api/core';

await invoke('add_note', { body: 'First note' });

Validate inputs and expose only operations the frontend needs. Keep database paths and raw SQL out of the frontend command contract.

Use a PostgreSQL driver or ORM

If your Rust integration expects a connection URL and independent sessions, start an AsyncOliphauntServer. Return and retain the server handle, not only its URL:

use oliphaunt::AsyncOliphauntServer;

async fn start_server(app_data: PathBuf) -> oliphaunt::Result<AsyncOliphauntServer> {
    AsyncOliphauntServer::builder()
        .storage(DatabaseStorage::Directory(app_data.join("postgres")))
        .start()
        .await
}

Store the server alongside the application's driver or pool. Create the pool using server.connection_string(). During shutdown, close the pool before awaiting server.close().

Package and shut down

Ship the native runtime and any selected extensions with each desktop build. Test the packaged application; a development run may resolve files that are absent from the final bundle.

Stop accepting application work before closing the database. Await db.close() through your app's shutdown path to observe errors. Use the SDK's backup API for direct/broker storage and PostgreSQL tools for server workflows.

See Tauri's state management and calling Rust documentation for application wiring.