Skip to content

Commit d4cf557

Browse files
committed
[SeaORM] Docs
1 parent 93f9fc1 commit d4cf557

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

SeaORM/docs/04-generate-entity/05-newtype.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,13 @@ impl sea_orm::TryGetable for Tag {
287287
fn try_get_by<I: sea_orm::ColIdx>(res: &sea_orm::QueryResult, idx: I)
288288
-> std::result::Result<Self, sea_orm::TryGetError> {
289289
let string = String::try_get_by(res, idx)?;
290-
std::str::FromStr::from_str(&string).map_err(|err| sea_orm::TryGetError::DbErr(sea_orm::DbErr::Type(format!("{err:?}"))))
290+
std::str::FromStr::from_str(&string).map_err(|err| {
291+
sea_orm::TryGetError::DbErr(sea_orm::DbErr::TryIntoErr {
292+
from: "String",
293+
into: stringify!(#name),
294+
source: std::sync::Arc::new(err),
295+
})
296+
})
291297
}
292298
}
293299

@@ -335,4 +341,31 @@ impl Tag {
335341

336342
fn to_str(&self) -> &'static str { .. }
337343
}
338-
```
344+
```
345+
346+
## String-like structs
347+
348+
Since `2.0.0`, `DeriveValueType` also supports struct types that can convert to and from strings. It's exactly the same as Enum String.
349+
350+
```rust
351+
#[derive(Copy, Clone, Debug, PartialEq, Eq, DeriveValueType)]
352+
#[sea_orm(value_type = "String", column_type = "Text")] // override column type
353+
pub struct Tag3 {
354+
pub i: i64,
355+
}
356+
357+
impl std::fmt::Display for Tag3 {
358+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
359+
write!(f, "{}", self.i)
360+
}
361+
}
362+
363+
impl std::str::FromStr for Tag3 {
364+
type Err = std::num::ParseIntError;
365+
366+
fn from_str(s: &str) -> Result<Self, Self::Err> {
367+
let i: i64 = s.parse()?;
368+
Ok(Self { i })
369+
}
370+
}
371+
```

SeaORM/docs/06-relation/04-complex-relations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ assert_eq!(staff[3].name, "Elle");
148148
assert_eq!(reports_to[3], None);
149149
```
150150

151-
It can works in reverse too.
151+
It can work in reverse too.
152152

153153
```rust
154154
let manages = staff

Seaography/docs/02-getting-started/01-bootstrap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ mysql://username:password@host/database
3030
Specify a schema
3131

3232
```
33-
postgres://username:password@host/database?currentSchema=my_schema
33+
postgres://username:password@host/database?options=--search_path=my_schema
3434
```
3535

3636
#### SQLite

0 commit comments

Comments
 (0)