Repository: launchbadge/sqlx
File: sqlx-core/src/sqlite/connection/mod.rs (Rust)

Code before:
pub struct SqliteConnection {
    pub(crate) handle: ConnectionHandle,
    pub(crate) worker: StatementWorker,

    // cache of semi-persistent statements
    pub(crate) statements: StatementCache<SqliteStatement>,

    // most recent non-persistent statement
    pub(crate) statement: Option<SqliteStatement>,

    // working memory for the active row's column information
    scratch_row_column_names: Arc<HashMap<UStr, usize>>,
}

impl SqliteConnection {
    /// Returns the underlying sqlite3* connection handle
    pub fn as_raw_handle(&mut self) -> *mut sqlite3 {
        self.handle.as_ptr()
    }

    pub fn create_collation(
        &mut self,
        name: &str,
        collation: impl Fn(&str, &str) -> Ordering + Send + Sync + UnwindSafe + 'static,
    ) -> &mut SqliteConnection {
        collation::create_collation(&self.handle, name, collation);
        self
    }
}

impl Debug for SqliteConnection {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        f.debug_struct("SqliteConnection").finish()
    }
}

impl Connection for SqliteConnection {
    type Database = Sqlite;

    fn close(self) -> BoxFuture<'static, Result<(), Error>> {
        // nothing explicit to do; connection will close in drop
        Box::pin(future::ok(()))
    }

    fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>> {
        // For SQLite connections, PING does effectively nothing
        Box::pin(future::ok(()))
    }

    fn cached_statements_size(&self) -> usize {
        self.statements.len()

Review comment (bug):
Please bubble the error here and return `Result<(), Error>`. We shouldn't need this to enable chaining.

Code after:

/// A connection to a [Sqlite] database.
pub struct SqliteConnection {
    pub(crate) handle: ConnectionHandle,
    pub(crate) worker: StatementWorker,

    // cache of semi-persistent statements
    pub(crate) statements: StatementCache<SqliteStatement>,

    // most recent non-persistent statement
    pub(crate) statement: Option<SqliteStatement>,

    // working memory for the active row's column information
    scratch_row_column_names: Arc<HashMap<UStr, usize>>,
}

impl SqliteConnection {
    /// Returns the underlying sqlite3* connection handle
    pub fn as_raw_handle(&mut self) -> *mut sqlite3 {
        self.handle.as_ptr()
    }

    pub fn create_collation(
        &mut self,
        name: &str,
        compare: impl Fn(&str, &str) -> Ordering + Send + Sync + 'static,
    ) -> Result<(), Error> {
        collation::create_collation(&self.handle, name, compare)
    }
}

impl Debug for SqliteConnection {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        f.debug_struct("SqliteConnection").finish()
    }
}

impl Connection for SqliteConnection {
    type Database = Sqlite;

    fn close(self) -> BoxFuture<'static, Result<(), Error>> {
        // nothing explicit to do; connection will close in drop
        Box::pin(future::ok(()))
    }

    fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>> {
        // For SQLite connections, PING does effectively nothing
        Box::pin(future::ok(()))
    }

    fn cached_statements_size(&self) -> usize {