#sea-orm #poem-web #poem #middleware #web #web-framework

poem-sea-orm-middleware

Sea ORM middleware for Poem web framework

6 releases

0.3.0 Jan 7, 2024
0.2.3 Mar 27, 2023
0.2.1 Feb 14, 2023
0.1.0 Feb 8, 2023

#854 in Database interfaces

Download history 10/week @ 2023-12-18 6/week @ 2023-12-25 12/week @ 2024-01-01 1/week @ 2024-01-08 27/week @ 2024-01-22 9/week @ 2024-01-29 17/week @ 2024-02-12 144/week @ 2024-02-26 38/week @ 2024-03-04 28/week @ 2024-03-11 34/week @ 2024-03-18 28/week @ 2024-03-25 40/week @ 2024-04-01

135 downloads per month

MIT/Apache

17KB
144 lines

poem-sea-orm-middleware

Crates.io version

This library is the Sea ORM middleware for Poem. This library is designed to make it easier for users to no longer need to manually begin transactions.

Example

/// explicit transaction
#[handler]
async fn hello(
    Path(name): Path<String>,
    // get transaction from parameter rather than task local
    Data(txn): Data<&ArcTxn>,
) -> String {
    let txn = &**txn;

    let user = match Entity::find()
        .filter(Column::Name.eq(name.clone()))
        .one(txn)
        .await
        .unwrap()
    {
        Some(user) => user,
        None => return format!("not found: {name}"),
    };

    format!("hello: {}", user.name)
}


/// implicit transaction
#[handler]
async fn hello(Path(name): Path<String>) -> String {
    // get transaction from task local rather than passing it as a parameter
    let txn = &*TXN.cloned();

    let user = match Entity::find()
        .filter(Column::Name.eq(name.clone()))
        .one(txn)
        .await
        .unwrap()
    {
        Some(user) => user,
        None => return format!("not found: {name}"),
    };

    format!("hello: {}", user.name)
}

Check examples, to see the full examples.

Dependencies

~17–30MB
~482K SLoC