Skip to content

Commit 81924f8

Browse files
committed
[Blog] Edit
1 parent 90539aa commit 81924f8

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

Blog/blog/2025-12-12-sea-orm-2.0.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,17 @@ Simply remove `#[async_trait]` usage and it's Cargo dependency.
4747

4848
Most `Send` and `Sync` in trait bounds can be removed.
4949

50-
### 5. `BoxFuture`
50+
### 5. `Future`
51+
52+
`impl Future<Output = T>` can be converted to just `T`.
53+
54+
```rust
55+
// async
56+
fn exec<'a, C>(self, db: &'a C) -> impl Future<Output = Result<InsertResult<A>, DbErr>> + 'a;
57+
58+
// sync
59+
fn exec<'a, C>(self, db: &'a C) -> Result<InsertResult<A>, DbErr>;
60+
```
5161

5262
If you've used `BoxFuture` you can use the following shim:
5363

@@ -121,9 +131,8 @@ The semantic difference in `lock()` between a synchronous mutex (`std::sync::Mut
121131
fn lock(&self) -> LockResult<MutexGuard<T>>
122132
```
123133

124-
+ Fallible: Returns a Result because the lock can be poisoned.
125-
126-
+ Poisoning happens if a thread panics while holding the lock.
134+
+ Fallible: Returns a Result because the lock can be poisoned
135+
+ Poisoning happens if a thread panics while holding the lock
127136

128137
#### `tokio::sync::Mutex::lock().await`
129138

@@ -132,8 +141,7 @@ async fn lock(&self) -> MutexGuard<'_, T>
132141
```
133142

134143
+ Infallible: always succeeds and returns a guard
135-
136-
+ In async world mutexes don't get poisoned. A panic inside a task would abort the task, but would not affect other tasks. This is actually a problem in async Rust as a task can fail silently
144+
+ In async world mutexes don't get poisoned. A panic inside a task would abort the task, but would not affect other tasks
137145

138146
In practice, we did:
139147

@@ -240,21 +248,22 @@ where
240248

241249
### 9. File / Network I/O
242250

243-
This is very application specific. In SeaORM's case, the external I/O is handled by `rusqlite` and `sqlx` respectively. Their APIs differ significantly, that's why we have written `sea-query-sqlx` and `sea-query-rusqlite` to align them.
251+
This is very application specific. In SeaORM's case, the external I/O is handled by `sqlx` and `rusqlite` respectively. Their APIs differ significantly, that's why we have written `sea-query-sqlx` and `sea-query-rusqlite` to align their interfaces.
244252

245-
For HTTP requests, you can simply use the sync and async versions of `Client` in different contexts.
253+
For HTTP requests, you can simply use the sync and async versions of `reqwest::Client` in different contexts.
246254

247255
For file I/O, the API difference between sync and async Rust is very small.
248256

249257
## Conclusion: SQLite + SeaORM Sync = ⚡
250258

251259
You can now use `sea-orm-sync` in CLI programs, and only bringing in small number of additional dependencies compared to having to bring in the async ecosystem.
252260

253-
In fact, the compilation time speaks for itself. The async version of [quickstart](https://github.com/SeaQL/sea-orm/blob/master/examples/quickstart/src/main.rs) took 30 seconds to compile, while the [sync version](https://github.com/SeaQL/sea-orm/blob/master/sea-orm-sync/examples/quickstart/src/main.rs) only took 15 seconds!
261+
The compilation time speaks for itself. The async version of [quickstart](https://github.com/SeaQL/sea-orm/blob/master/examples/quickstart/src/main.rs) took 30 seconds to compile, while the [sync version](https://github.com/SeaQL/sea-orm/blob/master/sea-orm-sync/examples/quickstart/src/main.rs) only took 15 seconds!
254262

255-
Right now only `rusqlite` is supported, but SeaORM's entire API surface is available. It's a breeze to add SQLite query capabilities to CLI programs where async would be overkill.
263+
Right now only `rusqlite` is supported, but SeaORM's entire API surface is available: including nested transactions. It's a breeze to add SQLite query capabilities to CLI programs where async would be overkill.
256264

257265
```rust
266+
// Same API as before
258267
let db = &sea_orm::Database::connect("sqlite::memory:")?;
259268

260269
// Setup the database: create tables

0 commit comments

Comments
 (0)