Skip to content

Commit b111da1

Browse files
committed
fix(mongodb): cursor timeout bug and warnings
1 parent 157d02a commit b111da1

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use thiserror::Error;
22

33
/// Errors that can occur during migration
44
#[derive(Error, Debug)]
5+
#[allow(dead_code)]
56
pub enum MigrationError {
67
/// MongoDB connection error
78
#[error("MongoDB connection error: {0}")]
@@ -53,8 +54,10 @@ pub enum MigrationError {
5354
}
5455

5556
/// Result type alias for migration operations
57+
#[allow(dead_code)]
5658
pub type MigrationResult<T> = Result<T, MigrationError>;
5759

60+
#[allow(dead_code)]
5861
impl MigrationError {
5962
/// Create a new schema inference error
6063
pub fn schema_inference<S: Into<String>>(msg: S) -> Self {

src/libsql_client.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ use tracing::{debug, info};
55

66
/// LibSQL client wrapper supporting both local and remote (Turso) databases
77
pub struct LibSqlClient {
8+
#[allow(dead_code)]
89
database: Database,
910
connection: Connection,
11+
#[allow(dead_code)]
1012
mode: ConnectionMode,
1113
}
1214

1315
/// Connection mode for LibSQL
1416
#[derive(Debug, Clone)]
17+
#[allow(dead_code)]
1518
enum ConnectionMode {
1619
Local(String),
1720
Remote { url: String },
@@ -105,6 +108,7 @@ impl LibSqlClient {
105108
///
106109
/// # Returns
107110
/// Total number of rows affected
111+
#[allow(dead_code)]
108112
pub async fn execute_batch(&self, statements: Vec<String>) -> Result<u64> {
109113
debug!("Executing batch of {} statements", statements.len());
110114

@@ -143,6 +147,7 @@ impl LibSqlClient {
143147
///
144148
/// # Returns
145149
/// Total number of rows inserted
150+
#[allow(dead_code)]
146151
pub async fn execute_batch_inserts<P>(
147152
&self,
148153
sql: &str,
@@ -198,6 +203,7 @@ impl LibSqlClient {
198203
///
199204
/// # Returns
200205
/// Rows result set
206+
#[allow(dead_code)]
201207
pub async fn query(&self, sql: &str) -> Result<libsql::Rows> {
202208
debug!("Querying: {}", sql);
203209
let rows = self.connection.query(sql, ()).await?;
@@ -208,6 +214,7 @@ impl LibSqlClient {
208214
///
209215
/// # Returns
210216
/// String describing the connection mode
217+
#[allow(dead_code)]
211218
pub fn connection_info(&self) -> String {
212219
match &self.mode {
213220
ConnectionMode::Local(path) => format!("Local file: {}", path),
@@ -219,6 +226,7 @@ impl LibSqlClient {
219226
///
220227
/// # Returns
221228
/// True if using local SQLite file, false if using Turso
229+
#[allow(dead_code)]
222230
pub fn is_local(&self) -> bool {
223231
matches!(self.mode, ConnectionMode::Local(_))
224232
}
@@ -227,6 +235,7 @@ impl LibSqlClient {
227235
///
228236
/// # Returns
229237
/// Optional path to the local SQLite file
238+
#[allow(dead_code)]
230239
pub fn output_path(&self) -> Option<String> {
231240
match &self.mode {
232241
ConnectionMode::Local(path) => Some(path.clone()),

src/mongodb_client.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,13 @@ impl MongoClient {
135135
let db = self.client.database(database_name);
136136
let collection = db.collection::<Document>(collection_name);
137137

138-
let cursor = collection.find(doc! {}, None).await?;
138+
// Configure find options to prevent cursor timeout
139+
let find_options = mongodb::options::FindOptions::builder()
140+
.no_cursor_timeout(true) // Prevent 10-minute cursor timeout
141+
.batch_size(1000) // Process in batches
142+
.build();
143+
144+
let cursor = collection.find(doc! {}, find_options).await?;
139145

140146
Ok(cursor)
141147
}
@@ -147,6 +153,7 @@ impl MongoClient {
147153
///
148154
/// # Returns
149155
/// True if the database exists, false otherwise
156+
#[allow(dead_code)]
150157
pub async fn database_exists(&self, database_name: &str) -> Result<bool> {
151158
let db_names = self.client.list_database_names(doc! {}, None).await?;
152159
Ok(db_names.contains(&database_name.to_string()))
@@ -160,6 +167,7 @@ impl MongoClient {
160167
///
161168
/// # Returns
162169
/// True if the collection exists, false otherwise
170+
#[allow(dead_code)]
163171
pub async fn collection_exists(
164172
&self,
165173
database_name: &str,
@@ -173,6 +181,7 @@ impl MongoClient {
173181
///
174182
/// # Returns
175183
/// Reference to the MongoDB client
184+
#[allow(dead_code)]
176185
pub fn client(&self) -> &Client {
177186
&self.client
178187
}

0 commit comments

Comments
 (0)