spring-sea-orm 0.1.0

rust microservice framework
Documentation
[![crates.io](https://img.shields.io/crates/v/spring-sea-orm.svg)](https://crates.io/crates/spring-sea-orm)
[![Documentation](https://docs.rs/spring-sea-orm/badge.svg)](https://docs.rs/spring-sea-orm)

## Dependencies

```toml
spring-sea-orm = { version = "0.1.0", features = ["postgres"] }
sea-orm = { version = "1.0" }          # Mainly to adapt to the entity code generated by sea-orm-cli
```

You can replace `postgres`, `mysql`, `sqlite`feature to select the appropriate database driver.

## Configuration items

```toml
[sea-orm]
uri = "postgres://root:123456@localhost:5432/pg_db" # Database address
min_connections = 1        # Minimum number of connections in the connection pool, the default value is 1
max_connections = 10       # Maximum number of connections in the connection pool, the default value is 10
acquire_timeout = 30000    # Connection timeout, in milliseconds, default 30s
idle_timeout = 600000      # Connection idle time, in milliseconds, default 10min
connect_timeout = 1800000  # Maximum connection survival time, in milliseconds, default 30min
enable_logging = true      # Print sql log
```

## Components

After configuring the above configuration items, the plugin will automatically register a [`DbConn`](https://docs.rs/spring-sea-orm/latest/spring_sea_orm/type.DbConn.html) connection pool object. This object is an alias of [`sea_orm::DbConn`](https://docs.rs/sea-orm/1.0.0/sea_orm/type.DbConn.html).

```rust
pub type DbConn = sea_orm::DbConn;
```

## Extract the Component registered by the plugin

The `SeaOrmPlugin` plugin automatically registers a connection pool component for us. We can use `Component` to extract this connection pool from AppState. [`Component`](https://docs.rs/spring-web/latest/spring_web/extractor/struct.Component.html) is an axum [extractor](https://docs.rs/axum/latest/axum/extract/index.html).

```rust
use spring_sqlx::{sqlx::{self, Row}, ConnectPool};
use spring_web::get;
use spring_web::extractor::Component;
use spring_web::error::Result;
use anyhow::Context;

#[get("/:id")]
async fn get_todo_list(
    Component(db): Component<DbConn>,
    Path(id): Path<i32>
) -> Result<String> {
    let rows = TodoItem::find()
        .filter(todo_item::Column::ListId.eq(id))
        .all(&db)
        .await
        .context("query todo list failed")?;
    Ok(Json(rows))
}
```

For the complete code, please refer to [`sea-orm-example`](https://github.com/spring-rs/spring-rs/tree/master/examples/sea-orm-example)