Skip to content

Commit cd133a0

Browse files
hongkongkiwiclaude
andcommitted
fix: Fix rustfmt and taplo CI issues
Co-Authored-By: Claude <[email protected]>
1 parent 52eec76 commit cd133a0

File tree

6 files changed

+151
-130
lines changed

6 files changed

+151
-130
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
107107
uuid = { version = "1", features = ["v4"] }
108108

109109
[features]
110+
d1 = ["worker/d1", "mock"]
110111
debug-print = []
111112
default = [
112113
"macros",
@@ -150,7 +151,6 @@ runtime-tokio = ["sqlx?/runtime-tokio"]
150151
runtime-tokio-native-tls = ["sqlx?/runtime-tokio-native-tls", "runtime-tokio"]
151152
runtime-tokio-rustls = ["sqlx?/runtime-tokio-rustls", "runtime-tokio"]
152153
rusqlite = []
153-
d1 = ["worker/d1", "mock"]
154154
schema-sync = ["sea-schema"]
155155
sea-orm-internal = []
156156
seaography = ["sea-orm-macros/seaography"]

examples/d1_example/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ wasm-opt = false
1717

1818
[lib]
1919
crate-type = ["cdylib"]
20-
path = "src/lib.rs"
20+
path = "src/lib.rs"
2121

2222
[dependencies]
23-
serde = { version = "1", features = ["derive"] }
24-
serde_json = "1"
23+
serde = { version = "1", features = ["derive"] }
24+
serde_json = "1"
2525

26-
worker = { version = "0.7", features = ["d1"] }
26+
worker = { version = "0.7", features = ["d1"] }
2727

2828
sea-orm = { path = "../../", default-features = false, features = [
2929
"d1",
3030
"with-json",
3131
"macros",
32-
]}
32+
] }

src/database/db_connection.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ impl ConnectionTrait for DatabaseConnection {
203203
conn.execute(stmt).await
204204
}
205205
#[cfg(feature = "d1")]
206-
DatabaseConnectionType::D1Connection(_) => {
207-
Err(conn_err("D1 connections require direct access via as_d1_connection(). See https://docs.sea-ql.org/sea-orm/master/feature-flags.html#d1 for details."))
208-
}
206+
DatabaseConnectionType::D1Connection(_) => Err(conn_err(
207+
"D1 connections require direct access via as_d1_connection(). See https://docs.sea-ql.org/sea-orm/master/feature-flags.html#d1 for details.",
208+
)),
209209
DatabaseConnectionType::Disconnected => Err(conn_err("Disconnected")),
210210
}
211211
}
@@ -252,9 +252,9 @@ impl ConnectionTrait for DatabaseConnection {
252252
}
253253
// D1 connections must use as_d1_connection() directly
254254
#[cfg(feature = "d1")]
255-
DatabaseConnectionType::D1Connection(_) => {
256-
Err(conn_err("D1 connections require direct access via as_d1_connection(). See https://docs.sea-ql.org/sea-orm/master/feature-flags.html#d1 for details."))
257-
}
255+
DatabaseConnectionType::D1Connection(_) => Err(conn_err(
256+
"D1 connections require direct access via as_d1_connection(). See https://docs.sea-ql.org/sea-orm/master/feature-flags.html#d1 for details.",
257+
)),
258258
DatabaseConnectionType::Disconnected => Err(conn_err("Disconnected")),
259259
}
260260
}
@@ -293,9 +293,9 @@ impl ConnectionTrait for DatabaseConnection {
293293
}
294294
// D1 connections must use as_d1_connection() directly
295295
#[cfg(feature = "d1")]
296-
DatabaseConnectionType::D1Connection(_) => {
297-
Err(conn_err("D1 connections require direct access via as_d1_connection(). See https://docs.sea-ql.org/sea-orm/master/feature-flags.html#d1 for details."))
298-
}
296+
DatabaseConnectionType::D1Connection(_) => Err(conn_err(
297+
"D1 connections require direct access via as_d1_connection(). See https://docs.sea-ql.org/sea-orm/master/feature-flags.html#d1 for details.",
298+
)),
299299
DatabaseConnectionType::Disconnected => Err(conn_err("Disconnected")),
300300
}
301301
}
@@ -334,9 +334,9 @@ impl ConnectionTrait for DatabaseConnection {
334334
}
335335
// D1 connections must use as_d1_connection() directly
336336
#[cfg(feature = "d1")]
337-
DatabaseConnectionType::D1Connection(_) => {
338-
Err(conn_err("D1 connections require direct access via as_d1_connection(). See https://docs.sea-ql.org/sea-orm/master/feature-flags.html#d1 for details."))
339-
}
337+
DatabaseConnectionType::D1Connection(_) => Err(conn_err(
338+
"D1 connections require direct access via as_d1_connection(). See https://docs.sea-ql.org/sea-orm/master/feature-flags.html#d1 for details.",
339+
)),
340340
DatabaseConnectionType::Disconnected => Err(conn_err("Disconnected")),
341341
}
342342
}
@@ -389,9 +389,9 @@ impl StreamTrait for DatabaseConnection {
389389
}
390390
// D1 connections must use as_d1_connection() directly
391391
#[cfg(feature = "d1")]
392-
DatabaseConnectionType::D1Connection(_) => {
393-
Err(conn_err("D1 streaming is not supported. Use query_all() instead. See https://docs.sea-ql.org/sea-orm/master/feature-flags.html#d1 for details."))
394-
}
392+
DatabaseConnectionType::D1Connection(_) => Err(conn_err(
393+
"D1 streaming is not supported. Use query_all() instead. See https://docs.sea-ql.org/sea-orm/master/feature-flags.html#d1 for details.",
394+
)),
395395
DatabaseConnectionType::Disconnected => Err(conn_err("Disconnected")),
396396
}
397397
})
@@ -424,9 +424,9 @@ impl TransactionTrait for DatabaseConnection {
424424
}
425425
// D1 connections must use as_d1_connection() directly
426426
#[cfg(feature = "d1")]
427-
DatabaseConnectionType::D1Connection(_) => {
428-
Err(conn_err("D1 transactions require direct access via as_d1_connection(). See https://docs.sea-ql.org/sea-orm/master/feature-flags.html#d1 for details."))
429-
}
427+
DatabaseConnectionType::D1Connection(_) => Err(conn_err(
428+
"D1 transactions require direct access via as_d1_connection(). See https://docs.sea-ql.org/sea-orm/master/feature-flags.html#d1 for details.",
429+
)),
430430
DatabaseConnectionType::Disconnected => Err(conn_err("Disconnected")),
431431
}
432432
}
@@ -463,9 +463,9 @@ impl TransactionTrait for DatabaseConnection {
463463
}
464464
// D1 connections must use as_d1_connection() directly
465465
#[cfg(feature = "d1")]
466-
DatabaseConnectionType::D1Connection(_) => {
467-
Err(conn_err("D1 transactions require direct access via as_d1_connection(). See https://docs.sea-ql.org/sea-orm/master/feature-flags.html#d1 for details."))
468-
}
466+
DatabaseConnectionType::D1Connection(_) => Err(conn_err(
467+
"D1 transactions require direct access via as_d1_connection(). See https://docs.sea-ql.org/sea-orm/master/feature-flags.html#d1 for details.",
468+
)),
469469
DatabaseConnectionType::Disconnected => Err(conn_err("Disconnected")),
470470
}
471471
}
@@ -766,9 +766,7 @@ impl DatabaseConnection {
766766
conn.set_metric_callback(_callback)
767767
}
768768
#[cfg(feature = "d1")]
769-
DatabaseConnectionType::D1Connection(conn) => {
770-
conn.set_metric_callback(_callback)
771-
}
769+
DatabaseConnectionType::D1Connection(conn) => conn.set_metric_callback(_callback),
772770
_ => {}
773771
}
774772
}

src/driver/d1.rs

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ use worker::wasm_bindgen::JsValue;
9595
use crate::{
9696
AccessMode, DatabaseConnection, DatabaseConnectionType, DatabaseTransaction, DbErr, ExecResult,
9797
FromQueryResult, IsolationLevel, QueryResult, Statement, TransactionError, Value, debug_print,
98-
error::*,
99-
executor::*,
98+
error::*, executor::*,
10099
};
101100

102101
/// D1 Connector for Sea-ORM
@@ -173,7 +172,11 @@ impl D1Connection {
173172
debug_print!("{}", stmt);
174173

175174
let sql = stmt.sql.clone();
176-
let values = stmt.values.as_ref().cloned().unwrap_or_else(|| Values(Vec::new()));
175+
let values = stmt
176+
.values
177+
.as_ref()
178+
.cloned()
179+
.unwrap_or_else(|| Values(Vec::new()));
177180

178181
crate::metric::metric!(self.metric_callback, &stmt, {
179182
match self.execute_inner(&sql, &values, false).await {
@@ -202,7 +205,11 @@ impl D1Connection {
202205
debug_print!("{}", stmt);
203206

204207
let sql = stmt.sql.clone();
205-
let values = stmt.values.as_ref().cloned().unwrap_or_else(|| Values(Vec::new()));
208+
let values = stmt
209+
.values
210+
.as_ref()
211+
.cloned()
212+
.unwrap_or_else(|| Values(Vec::new()));
206213

207214
crate::metric::metric!(self.metric_callback, &stmt, {
208215
match self.query_inner(&sql, &values).await {
@@ -218,7 +225,11 @@ impl D1Connection {
218225
debug_print!("{}", stmt);
219226

220227
let sql = stmt.sql.clone();
221-
let values = stmt.values.as_ref().cloned().unwrap_or_else(|| Values(Vec::new()));
228+
let values = stmt
229+
.values
230+
.as_ref()
231+
.cloned()
232+
.unwrap_or_else(|| Values(Vec::new()));
222233

223234
crate::metric::metric!(self.metric_callback, &stmt, {
224235
match self.query_inner(&sql, &values).await {
@@ -245,8 +256,7 @@ impl D1Connection {
245256
// D1 doesn't support explicit transactions in the traditional sense.
246257
// We'll use a no-op transaction that just commits/rollbacks immediately.
247258
// This is a limitation of D1's current API.
248-
DatabaseTransaction::new_d1(self.d1.clone(), self.metric_callback.clone())
249-
.await
259+
DatabaseTransaction::new_d1(self.d1.clone(), self.metric_callback.clone()).await
250260
}
251261

252262
/// Execute a function inside a transaction
@@ -265,9 +275,10 @@ impl D1Connection {
265275
T: Send,
266276
E: std::fmt::Display + std::fmt::Debug + Send,
267277
{
268-
let transaction = DatabaseTransaction::new_d1(self.d1.clone(), self.metric_callback.clone())
269-
.await
270-
.map_err(|e| TransactionError::Connection(e))?;
278+
let transaction =
279+
DatabaseTransaction::new_d1(self.d1.clone(), self.metric_callback.clone())
280+
.await
281+
.map_err(|e| TransactionError::Connection(e))?;
271282
transaction.run(callback).await
272283
}
273284

@@ -302,7 +313,10 @@ impl D1Connection {
302313
.bind(&js_values)
303314
.map_err(|e| D1Error::Prepare(e.into()))?;
304315

305-
let result = prepared.run().await.map_err(|e| D1Error::Execute(e.into()))?;
316+
let result = prepared
317+
.run()
318+
.await
319+
.map_err(|e| D1Error::Execute(e.into()))?;
306320
let meta = result.meta().map_err(|e| D1Error::Meta(e.into()))?;
307321

308322
let (last_insert_id, rows_affected) = match meta {
@@ -320,11 +334,7 @@ impl D1Connection {
320334
}
321335

322336
/// Internal method to query and get rows
323-
async fn query_inner(
324-
&self,
325-
sql: &str,
326-
values: &Values,
327-
) -> Result<Vec<D1Row>, D1Error> {
337+
async fn query_inner(&self, sql: &str, values: &Values) -> Result<Vec<D1Row>, D1Error> {
328338
let js_values = values_to_js_values(values)?;
329339

330340
let prepared = self
@@ -339,12 +349,10 @@ impl D1Connection {
339349
return Err(D1Error::Response(error.to_string()));
340350
}
341351

342-
let results: Vec<serde_json::Value> = result.results().map_err(|e| D1Error::Results(e.into()))?;
352+
let results: Vec<serde_json::Value> =
353+
result.results().map_err(|e| D1Error::Results(e.into()))?;
343354

344-
let rows: Vec<D1Row> = results
345-
.into_iter()
346-
.map(|row| D1Row { row })
347-
.collect();
355+
let rows: Vec<D1Row> = results.into_iter().map(|row| D1Row { row }).collect();
348356

349357
Ok(rows)
350358
}
@@ -416,10 +424,7 @@ fn value_to_js_value(val: &Value) -> Result<JsValue, D1Error> {
416424
Value::Char(Some(v)) => Ok(JsValue::from(v.to_string())),
417425
Value::Bytes(Some(v)) => {
418426
// Convert bytes to hex string for D1
419-
let hex: String = v
420-
.iter()
421-
.map(|byte| format!("{:02x}", byte))
422-
.collect();
427+
let hex: String = v.iter().map(|byte| format!("{:02x}", byte)).collect();
423428
Ok(JsValue::from(format!("X'{}'", hex)))
424429
}
425430
Value::Json(Some(v)) => Ok(JsValue::from(v.to_string())),
@@ -467,7 +472,10 @@ fn d1_error_to_query_err(err: D1Error) -> DbErr {
467472

468473
/// Convert D1 error to DbErr for connection
469474
fn d1_error_to_conn_err(err: D1Error) -> DbErr {
470-
DbErr::Conn(RuntimeErr::Internal(format!("D1 connection error: {}", err)))
475+
DbErr::Conn(RuntimeErr::Internal(format!(
476+
"D1 connection error: {}",
477+
err
478+
)))
471479
}
472480

473481
/// Convert D1 JSON row to Sea-ORM values
@@ -765,7 +773,10 @@ mod tests {
765773
assert_eq!(id_value, Value::BigInt(Some(1)));
766774

767775
let name_value = values.iter().find(|(k, _)| k == "name").unwrap().1.clone();
768-
assert_eq!(name_value, Value::String(Some("Chocolate Cake".to_string())));
776+
assert_eq!(
777+
name_value,
778+
Value::String(Some("Chocolate Cake".to_string()))
779+
);
769780
}
770781

771782
/// Test D1Row try_get_by with valid column

src/driver/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(feature = "d1")]
2+
pub(crate) mod d1;
13
#[cfg(feature = "mock")]
24
mod mock;
35
#[cfg(feature = "proxy")]
@@ -14,9 +16,9 @@ pub(crate) mod sqlx_mysql;
1416
pub(crate) mod sqlx_postgres;
1517
#[cfg(feature = "sqlx-sqlite")]
1618
pub(crate) mod sqlx_sqlite;
17-
#[cfg(feature = "d1")]
18-
pub(crate) mod d1;
1919

20+
#[cfg(feature = "d1")]
21+
pub use d1::*;
2022
#[cfg(feature = "mock")]
2123
pub use mock::*;
2224
#[cfg(feature = "proxy")]
@@ -29,5 +31,3 @@ pub use sqlx_mysql::*;
2931
pub use sqlx_postgres::*;
3032
#[cfg(feature = "sqlx-sqlite")]
3133
pub use sqlx_sqlite::*;
32-
#[cfg(feature = "d1")]
33-
pub use d1::*;

0 commit comments

Comments
 (0)