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
135 downloads per month
17KB
144 lines
poem-sea-orm-middleware
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