SeaQL/sea-orm · error

Not SQLite Connection

Error message

Not SQLite Connection

What it means

get_sqlite_connection_pool() returns the underlying sqlx::SqlitePool. It panics when the inner connection is not SqlxSqlitePoolConnection — e.g. MySQL, Postgres, mock, proxy, rusqlite, or Disconnected. Note a rusqlite-backed connection also does not satisfy this; only the sqlx-sqlite pool does.

Source

Thrown at sea-orm-sync/src/database/db_connection.rs:808

    /// Panics if [DbConn] is not a Postgres connection.
    #[cfg(feature = "sqlx-postgres")]
    pub fn get_postgres_connection_pool(&self) -> &sqlx::PgPool {
        match &self.inner {
            DatabaseConnectionType::SqlxPostgresPoolConnection(conn) => &conn.pool,
            _ => panic!("Not Postgres Connection"),
        }
    }

    /// Get [sqlx::SqlitePool]
    ///
    /// # Panics
    ///
    /// Panics if [DbConn] is not a SQLite connection.
    #[cfg(feature = "sqlx-sqlite")]
    pub fn get_sqlite_connection_pool(&self) -> &sqlx::SqlitePool {
        match &self.inner {
            DatabaseConnectionType::SqlxSqlitePoolConnection(conn) => &conn.pool,
            _ => panic!("Not SQLite Connection"),
        }
    }
}

impl DbBackend {
    /// Check if the URI is the same as the specified database backend.
    /// Returns true if they match.
    ///
    /// # Panics
    ///
    /// Panics if `base_url` cannot be parsed as `Url`.
    pub fn is_prefix_of(self, base_url: &str) -> bool {
        let base_url_parsed = Url::parse(base_url).expect("Fail to parse database URL");
        match self {
            Self::Postgres => {
                base_url_parsed.scheme() == "postgres" || base_url_parsed.scheme() == "postgresql"
            }
            Self::MySql => base_url_parsed.scheme() == "mysql",

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Connect with a sqlite:// URL (sqlx-sqlite feature) before requesting the pool
  2. Guard with get_database_backend() == DbBackend::Sqlite and confirm the connection is sqlx-backed, not rusqlite-backed
  3. Handle connect() errors so a Disconnected connection never reaches pool access

Example fix

// before
let conn = Database::connect("postgres://...").await?;
let pool = conn.get_sqlite_connection_pool(); // panics
// after
let conn = Database::connect("sqlite://app.db?mode=rwc").await?;
let pool = conn.get_sqlite_connection_pool(); // ok
Defensive patterns

Strategy: validation

Validate before calling

assert_eq!(conn.get_database_backend(), DbBackend::Sqlite, "raw pool access requires a sqlx SQLite connection");
let pool = conn.get_sqlite_connection_pool();

Type guard

fn as_sqlite_pool(conn: &DatabaseConnection) -> Option<&sqlx::SqlitePool> {
    (conn.get_database_backend() == DbBackend::Sqlite).then(|| conn.get_sqlite_connection_pool())
}

Try / catch

let pool = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| conn.get_sqlite_connection_pool()));
if pool.is_err() { return Err(anyhow!("not a sqlx SQLite connection")); }

Prevention

When it happens

Trigger: Calling get_sqlite_connection_pool() on a connection created for another backend, on a MockDatabase or rusqlite connection, or a Disconnected connection.

Common situations: App connected to a server database but test/CLI code assumed SQLite; using the rusqlite feature and expecting this pool accessor to work; connect() failed leaving a Disconnected handle.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10). Data as JSON: /api/errors/3f6e9acd8b9f9b56. Report an issue: GitHub.