Skip to content

Commit

Permalink
Reorganize the methods in Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Apr 24, 2024
1 parent bd6595f commit a189161
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ impl Connection {
Connection::open_with_flags(path, flags.with_full_mutex()).map(ConnectionThreadSafe)
}

#[doc(hidden)]
#[inline]
pub fn as_raw(&self) -> *mut ffi::sqlite3 {
self.raw.0
}
}

impl Connection {
/// Execute a statement without processing the resulting rows if any.
#[inline]
pub fn execute<T: AsRef<str>>(&self, statement: T) -> Result<()> {
Expand Down Expand Up @@ -132,6 +140,22 @@ impl Connection {
crate::statement::new(self.raw.0, statement)
}

/// Return the number of rows inserted, updated, or deleted by the most recent INSERT, UPDATE,
/// or DELETE statement.
#[inline]
pub fn change_count(&self) -> usize {
unsafe { ffi::sqlite3_changes(self.raw.0) as usize }
}

/// Return the total number of rows inserted, updated, and deleted by all INSERT, UPDATE, and
/// DELETE statements since the connection was opened.
#[inline]
pub fn total_change_count(&self) -> usize {
unsafe { ffi::sqlite3_total_changes(self.raw.0) as usize }
}
}

impl Connection {
/// Set a callback for handling busy events.
///
/// The callback is triggered when the database cannot perform an operation due to processing
Expand Down Expand Up @@ -179,7 +203,9 @@ impl Connection {
}
Ok(())
}
}

impl Connection {
/// Enable loading extensions.
#[cfg(feature = "extension")]
#[inline]
Expand Down Expand Up @@ -223,7 +249,9 @@ impl Connection {
}
Ok(())
}
}

impl Connection {
/// Set the encryption key.
#[cfg(feature = "encryption")]
#[inline]
Expand All @@ -245,7 +273,7 @@ impl Connection {
/// Change the encryption key.
#[cfg(feature = "encryption")]
#[inline]
pub fn reset_encryption_key<T: AsRef<str>>(&self, new_key: T) -> Result<()> {
pub fn change_encryption_key<T: AsRef<str>>(&self, new_key: T) -> Result<()> {
unsafe {
ok!(
self.raw.0,
Expand All @@ -259,26 +287,6 @@ impl Connection {
}
Ok(())
}

/// Return the number of rows inserted, updated, or deleted by the most recent INSERT, UPDATE,
/// or DELETE statement.
#[inline]
pub fn change_count(&self) -> usize {
unsafe { ffi::sqlite3_changes(self.raw.0) as usize }
}

/// Return the total number of rows inserted, updated, and deleted by all INSERT, UPDATE, and
/// DELETE statements since the connection was opened.
#[inline]
pub fn total_change_count(&self) -> usize {
unsafe { ffi::sqlite3_total_changes(self.raw.0) as usize }
}

#[doc(hidden)]
#[inline]
pub fn as_raw(&self) -> *mut ffi::sqlite3 {
self.raw.0
}
}

impl Drop for Connection {
Expand Down

0 comments on commit a189161

Please sign in to comment.