Rename to DbErr
This commit is contained in:
parent
2a1173c174
commit
0298cfb6af
@ -1,7 +1,7 @@
|
||||
use super::*;
|
||||
use sea_orm::{entity::*, error::*, query::*, DbConn};
|
||||
|
||||
pub async fn all_about_operation(db: &DbConn) -> Result<(), SeaErr> {
|
||||
pub async fn all_about_operation(db: &DbConn) -> Result<(), DbErr> {
|
||||
insert_and_update(db).await?;
|
||||
|
||||
println!("===== =====\n");
|
||||
@ -15,7 +15,7 @@ pub async fn all_about_operation(db: &DbConn) -> Result<(), SeaErr> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn insert_and_update(db: &DbConn) -> Result<(), SeaErr> {
|
||||
pub async fn insert_and_update(db: &DbConn) -> Result<(), DbErr> {
|
||||
let pear = fruit::ActiveModel {
|
||||
name: Set("pear".to_owned()),
|
||||
..Default::default()
|
||||
@ -41,7 +41,7 @@ pub async fn insert_and_update(db: &DbConn) -> Result<(), SeaErr> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn save_active_model(db: &DbConn) -> Result<(), SeaErr> {
|
||||
pub async fn save_active_model(db: &DbConn) -> Result<(), DbErr> {
|
||||
let banana = fruit::ActiveModel {
|
||||
name: Set("Banana".to_owned()),
|
||||
..Default::default()
|
||||
@ -79,7 +79,7 @@ mod form {
|
||||
}
|
||||
}
|
||||
|
||||
async fn save_custom_active_model(db: &DbConn) -> Result<(), SeaErr> {
|
||||
async fn save_custom_active_model(db: &DbConn) -> Result<(), DbErr> {
|
||||
let pineapple = form::ActiveModel {
|
||||
id: Unset(None),
|
||||
name: Set("Pineapple".to_owned()),
|
||||
|
@ -1,7 +1,7 @@
|
||||
use super::*;
|
||||
use sea_orm::{entity::*, error::*, query::*, DbConn, FromQueryResult};
|
||||
|
||||
pub async fn all_about_select(db: &DbConn) -> Result<(), SeaErr> {
|
||||
pub async fn all_about_select(db: &DbConn) -> Result<(), DbErr> {
|
||||
find_all(db).await?;
|
||||
|
||||
println!("===== =====\n");
|
||||
@ -41,7 +41,7 @@ pub async fn all_about_select(db: &DbConn) -> Result<(), SeaErr> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn find_all(db: &DbConn) -> Result<(), SeaErr> {
|
||||
async fn find_all(db: &DbConn) -> Result<(), DbErr> {
|
||||
print!("find all cakes: ");
|
||||
|
||||
let cakes: Vec<cake::Model> = Cake::find().all(db).await?;
|
||||
@ -63,7 +63,7 @@ async fn find_all(db: &DbConn) -> Result<(), SeaErr> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn find_together(db: &DbConn) -> Result<(), SeaErr> {
|
||||
async fn find_together(db: &DbConn) -> Result<(), DbErr> {
|
||||
print!("find cakes and fruits: ");
|
||||
|
||||
let both = Cake::find().find_also_related(Fruit).all(db).await?;
|
||||
@ -82,7 +82,7 @@ impl Cake {
|
||||
}
|
||||
}
|
||||
|
||||
async fn find_one(db: &DbConn) -> Result<(), SeaErr> {
|
||||
async fn find_one(db: &DbConn) -> Result<(), DbErr> {
|
||||
print!("find one by primary key: ");
|
||||
|
||||
let cheese: Option<cake::Model> = Cake::find_by_id(1).one(db).await?;
|
||||
@ -112,7 +112,7 @@ async fn find_one(db: &DbConn) -> Result<(), SeaErr> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn count_fruits_by_cake(db: &DbConn) -> Result<(), SeaErr> {
|
||||
async fn count_fruits_by_cake(db: &DbConn) -> Result<(), DbErr> {
|
||||
#[derive(Debug, FromQueryResult)]
|
||||
struct SelectResult {
|
||||
name: String,
|
||||
@ -138,7 +138,7 @@ async fn count_fruits_by_cake(db: &DbConn) -> Result<(), SeaErr> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn find_many_to_many(db: &DbConn) -> Result<(), SeaErr> {
|
||||
async fn find_many_to_many(db: &DbConn) -> Result<(), DbErr> {
|
||||
print!("find cakes and fillings: ");
|
||||
|
||||
let both: Vec<(cake::Model, Vec<filling::Model>)> =
|
||||
@ -178,7 +178,7 @@ async fn find_many_to_many(db: &DbConn) -> Result<(), SeaErr> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn all_about_select_json(db: &DbConn) -> Result<(), SeaErr> {
|
||||
async fn all_about_select_json(db: &DbConn) -> Result<(), DbErr> {
|
||||
find_all_json(&db).await?;
|
||||
|
||||
println!("===== =====\n");
|
||||
@ -192,7 +192,7 @@ async fn all_about_select_json(db: &DbConn) -> Result<(), SeaErr> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn find_all_json(db: &DbConn) -> Result<(), SeaErr> {
|
||||
async fn find_all_json(db: &DbConn) -> Result<(), DbErr> {
|
||||
print!("find all cakes: ");
|
||||
|
||||
let cakes = Cake::find().into_json().all(db).await?;
|
||||
@ -208,7 +208,7 @@ async fn find_all_json(db: &DbConn) -> Result<(), SeaErr> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn find_together_json(db: &DbConn) -> Result<(), SeaErr> {
|
||||
async fn find_together_json(db: &DbConn) -> Result<(), DbErr> {
|
||||
print!("find cakes and fruits: ");
|
||||
|
||||
let cakes_fruits = Cake::find()
|
||||
@ -225,7 +225,7 @@ async fn find_together_json(db: &DbConn) -> Result<(), SeaErr> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn count_fruits_by_cake_json(db: &DbConn) -> Result<(), SeaErr> {
|
||||
async fn count_fruits_by_cake_json(db: &DbConn) -> Result<(), DbErr> {
|
||||
print!("count fruits by cake: ");
|
||||
|
||||
let count = Cake::find()
|
||||
@ -243,7 +243,7 @@ async fn count_fruits_by_cake_json(db: &DbConn) -> Result<(), SeaErr> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn find_all_stream(db: &DbConn) -> Result<(), SeaErr> {
|
||||
async fn find_all_stream(db: &DbConn) -> Result<(), DbErr> {
|
||||
use async_std::task::sleep;
|
||||
use futures::TryStreamExt;
|
||||
use std::time::Duration;
|
||||
@ -291,7 +291,7 @@ async fn find_all_stream(db: &DbConn) -> Result<(), SeaErr> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn find_first_page(db: &DbConn) -> Result<(), SeaErr> {
|
||||
async fn find_first_page(db: &DbConn) -> Result<(), DbErr> {
|
||||
println!("fruits first page: ");
|
||||
let page = fruit::Entity::find().paginate(db, 2).fetch_page(0).await?;
|
||||
for fruit in page {
|
||||
@ -301,7 +301,7 @@ async fn find_first_page(db: &DbConn) -> Result<(), SeaErr> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn find_num_pages(db: &DbConn) -> Result<(), SeaErr> {
|
||||
async fn find_num_pages(db: &DbConn) -> Result<(), DbErr> {
|
||||
println!("fruits number of page: ");
|
||||
let num_pages = fruit::Entity::find().paginate(db, 2).num_pages().await?;
|
||||
println!("{:?}", num_pages);
|
||||
|
@ -37,11 +37,11 @@ pub fn expand_derive_active_model(ident: Ident, data: Data) -> syn::Result<Token
|
||||
}
|
||||
|
||||
impl ActiveModel {
|
||||
pub async fn save(self, db: &sea_orm::DatabaseConnection) -> Result<Self, sea_orm::SeaErr> {
|
||||
pub async fn save(self, db: &sea_orm::DatabaseConnection) -> Result<Self, sea_orm::DbErr> {
|
||||
sea_orm::save_active_model::<Self, Entity>(self, db).await
|
||||
}
|
||||
|
||||
pub async fn delete(self, db: &sea_orm::DatabaseConnection) -> Result<sea_orm::DeleteResult, sea_orm::SeaErr> {
|
||||
pub async fn delete(self, db: &sea_orm::DatabaseConnection) -> Result<sea_orm::DeleteResult, sea_orm::DbErr> {
|
||||
sea_orm::delete_active_model::<Self, Entity>(self, db).await
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ pub fn expand_derive_from_query_result(ident: Ident, data: Data) -> syn::Result<
|
||||
|
||||
Ok(quote!(
|
||||
impl sea_orm::FromQueryResult for #ident {
|
||||
fn from_query_result(row: &sea_orm::QueryResult, pre: &str) -> Result<Self, sea_orm::SeaErr> {
|
||||
fn from_query_result(row: &sea_orm::QueryResult, pre: &str) -> Result<Self, sea_orm::DbErr> {
|
||||
Ok(Self {
|
||||
#(#field: row.try_get(pre, #name)?),*
|
||||
})
|
||||
|
@ -47,7 +47,7 @@ pub fn expand_derive_model(ident: Ident, data: Data) -> syn::Result<TokenStream>
|
||||
}
|
||||
|
||||
impl sea_orm::FromQueryResult for #ident {
|
||||
fn from_query_result(row: &sea_orm::QueryResult, pre: &str) -> Result<Self, sea_orm::SeaErr> {
|
||||
fn from_query_result(row: &sea_orm::QueryResult, pre: &str) -> Result<Self, sea_orm::DbErr> {
|
||||
Ok(Self {
|
||||
#(#field: row.try_get(pre, <<Self as ModelTrait>::Entity as EntityTrait>::Column::#name.as_str().into())?),*
|
||||
})
|
||||
|
@ -77,7 +77,7 @@ impl DatabaseConnection {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn execute(&self, stmt: Statement) -> Result<ExecResult, SeaErr> {
|
||||
pub async fn execute(&self, stmt: Statement) -> Result<ExecResult, DbErr> {
|
||||
match self {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
DatabaseConnection::SqlxMySqlPoolConnection(conn) => conn.execute(stmt).await,
|
||||
@ -89,7 +89,7 @@ impl DatabaseConnection {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, SeaErr> {
|
||||
pub async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr> {
|
||||
match self {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
DatabaseConnection::SqlxMySqlPoolConnection(conn) => conn.query_one(stmt).await,
|
||||
@ -101,7 +101,7 @@ impl DatabaseConnection {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn query_all(&self, stmt: Statement) -> Result<Vec<QueryResult>, SeaErr> {
|
||||
pub async fn query_all(&self, stmt: Statement) -> Result<Vec<QueryResult>, DbErr> {
|
||||
match self {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
DatabaseConnection::SqlxMySqlPoolConnection(conn) => conn.query_all(stmt).await,
|
||||
|
@ -68,14 +68,14 @@ impl MockDatabase {
|
||||
}
|
||||
|
||||
impl MockDatabaseTrait for MockDatabase {
|
||||
fn execute(&mut self, counter: usize, statement: Statement) -> Result<ExecResult, SeaErr> {
|
||||
fn execute(&mut self, counter: usize, statement: Statement) -> Result<ExecResult, DbErr> {
|
||||
self.transaction_log.push(Transaction::one(statement));
|
||||
if counter < self.exec_results.len() {
|
||||
Ok(ExecResult {
|
||||
result: ExecResultHolder::Mock(std::mem::take(&mut self.exec_results[counter])),
|
||||
})
|
||||
} else {
|
||||
Err(SeaErr::Execution)
|
||||
Err(DbErr::Execution)
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ impl MockDatabaseTrait for MockDatabase {
|
||||
&mut self,
|
||||
counter: usize,
|
||||
statement: Statement,
|
||||
) -> Result<Vec<QueryResult>, SeaErr> {
|
||||
) -> Result<Vec<QueryResult>, DbErr> {
|
||||
self.transaction_log.push(Transaction::one(statement));
|
||||
if counter < self.query_results.len() {
|
||||
Ok(std::mem::take(&mut self.query_results[counter])
|
||||
@ -93,7 +93,7 @@ impl MockDatabaseTrait for MockDatabase {
|
||||
})
|
||||
.collect())
|
||||
} else {
|
||||
Err(SeaErr::Query)
|
||||
Err(DbErr::Query)
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ impl MockDatabaseTrait for MockDatabase {
|
||||
}
|
||||
|
||||
impl MockRow {
|
||||
pub fn try_get<T>(&self, col: &str) -> Result<T, SeaErr>
|
||||
pub fn try_get<T>(&self, col: &str) -> Result<T, DbErr>
|
||||
where
|
||||
T: ValueType,
|
||||
{
|
||||
|
@ -10,13 +10,13 @@ pub use mock::*;
|
||||
pub use statement::*;
|
||||
pub use transaction::*;
|
||||
|
||||
use crate::SeaErr;
|
||||
use crate::DbErr;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Database;
|
||||
|
||||
impl Database {
|
||||
pub async fn connect(string: &str) -> Result<DatabaseConnection, SeaErr> {
|
||||
pub async fn connect(string: &str) -> Result<DatabaseConnection, DbErr> {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
if crate::SqlxMySqlConnector::accepts(string) {
|
||||
return Ok(crate::SqlxMySqlConnector::connect(string).await?);
|
||||
@ -29,6 +29,6 @@ impl Database {
|
||||
if crate::MockDatabaseConnector::accepts(string) {
|
||||
return Ok(crate::MockDatabaseConnector::connect(string).await?);
|
||||
}
|
||||
Err(SeaErr::Connection)
|
||||
Err(DbErr::Connection)
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,9 @@ pub struct MockDatabaseConnection {
|
||||
}
|
||||
|
||||
pub trait MockDatabaseTrait: Send {
|
||||
fn execute(&mut self, counter: usize, stmt: Statement) -> Result<ExecResult, SeaErr>;
|
||||
fn execute(&mut self, counter: usize, stmt: Statement) -> Result<ExecResult, DbErr>;
|
||||
|
||||
fn query(&mut self, counter: usize, stmt: Statement) -> Result<Vec<QueryResult>, SeaErr>;
|
||||
fn query(&mut self, counter: usize, stmt: Statement) -> Result<Vec<QueryResult>, DbErr>;
|
||||
|
||||
fn drain_transaction_log(&mut self) -> Vec<Transaction>;
|
||||
}
|
||||
@ -27,7 +27,7 @@ impl MockDatabaseConnector {
|
||||
string.starts_with("mock://")
|
||||
}
|
||||
|
||||
pub async fn connect(_string: &str) -> Result<DatabaseConnection, SeaErr> {
|
||||
pub async fn connect(_string: &str) -> Result<DatabaseConnection, DbErr> {
|
||||
Ok(DatabaseConnection::MockDatabaseConnection(
|
||||
MockDatabaseConnection::new(MockDatabase::new()),
|
||||
))
|
||||
@ -49,20 +49,20 @@ impl MockDatabaseConnection {
|
||||
&self.mocker
|
||||
}
|
||||
|
||||
pub async fn execute(&self, statement: Statement) -> Result<ExecResult, SeaErr> {
|
||||
pub async fn execute(&self, statement: Statement) -> Result<ExecResult, DbErr> {
|
||||
debug_print!("{}", statement);
|
||||
let counter = self.counter.fetch_add(1, Ordering::SeqCst);
|
||||
self.mocker.lock().unwrap().execute(counter, statement)
|
||||
}
|
||||
|
||||
pub async fn query_one(&self, statement: Statement) -> Result<Option<QueryResult>, SeaErr> {
|
||||
pub async fn query_one(&self, statement: Statement) -> Result<Option<QueryResult>, DbErr> {
|
||||
debug_print!("{}", statement);
|
||||
let counter = self.counter.fetch_add(1, Ordering::SeqCst);
|
||||
let result = self.mocker.lock().unwrap().query(counter, statement)?;
|
||||
Ok(result.into_iter().next())
|
||||
}
|
||||
|
||||
pub async fn query_all(&self, statement: Statement) -> Result<Vec<QueryResult>, SeaErr> {
|
||||
pub async fn query_all(&self, statement: Statement) -> Result<Vec<QueryResult>, DbErr> {
|
||||
debug_print!("{}", statement);
|
||||
let counter = self.counter.fetch_add(1, Ordering::SeqCst);
|
||||
self.mocker.lock().unwrap().query(counter, statement)
|
||||
|
@ -19,13 +19,13 @@ impl SqlxMySqlConnector {
|
||||
string.starts_with("mysql://")
|
||||
}
|
||||
|
||||
pub async fn connect(string: &str) -> Result<DatabaseConnection, SeaErr> {
|
||||
pub async fn connect(string: &str) -> Result<DatabaseConnection, DbErr> {
|
||||
if let Ok(pool) = MySqlPool::connect(string).await {
|
||||
Ok(DatabaseConnection::SqlxMySqlPoolConnection(
|
||||
SqlxMySqlPoolConnection { pool },
|
||||
))
|
||||
} else {
|
||||
Err(SeaErr::Connection)
|
||||
Err(DbErr::Connection)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -37,7 +37,7 @@ impl SqlxMySqlConnector {
|
||||
}
|
||||
|
||||
impl SqlxMySqlPoolConnection {
|
||||
pub async fn execute(&self, stmt: Statement) -> Result<ExecResult, SeaErr> {
|
||||
pub async fn execute(&self, stmt: Statement) -> Result<ExecResult, DbErr> {
|
||||
debug_print!("{}", stmt);
|
||||
|
||||
let query = sqlx_query(&stmt);
|
||||
@ -46,10 +46,10 @@ impl SqlxMySqlPoolConnection {
|
||||
return Ok(res.into());
|
||||
}
|
||||
}
|
||||
Err(SeaErr::Execution)
|
||||
Err(DbErr::Execution)
|
||||
}
|
||||
|
||||
pub async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, SeaErr> {
|
||||
pub async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr> {
|
||||
debug_print!("{}", stmt);
|
||||
|
||||
let query = sqlx_query(&stmt);
|
||||
@ -60,11 +60,11 @@ impl SqlxMySqlPoolConnection {
|
||||
Ok(None)
|
||||
}
|
||||
} else {
|
||||
Err(SeaErr::Query)
|
||||
Err(DbErr::Query)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn query_all(&self, stmt: Statement) -> Result<Vec<QueryResult>, SeaErr> {
|
||||
pub async fn query_all(&self, stmt: Statement) -> Result<Vec<QueryResult>, DbErr> {
|
||||
debug_print!("{}", stmt);
|
||||
|
||||
let query = sqlx_query(&stmt);
|
||||
@ -73,7 +73,7 @@ impl SqlxMySqlPoolConnection {
|
||||
return Ok(rows.into_iter().map(|r| r.into()).collect());
|
||||
}
|
||||
}
|
||||
Err(SeaErr::Query)
|
||||
Err(DbErr::Query)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,13 +19,13 @@ impl SqlxSqliteConnector {
|
||||
string.starts_with("sqlite:")
|
||||
}
|
||||
|
||||
pub async fn connect(string: &str) -> Result<DatabaseConnection, SeaErr> {
|
||||
pub async fn connect(string: &str) -> Result<DatabaseConnection, DbErr> {
|
||||
if let Ok(pool) = SqlitePool::connect(string).await {
|
||||
Ok(DatabaseConnection::SqlxSqlitePoolConnection(
|
||||
SqlxSqlitePoolConnection { pool },
|
||||
))
|
||||
} else {
|
||||
Err(SeaErr::Connection)
|
||||
Err(DbErr::Connection)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -37,7 +37,7 @@ impl SqlxSqliteConnector {
|
||||
}
|
||||
|
||||
impl SqlxSqlitePoolConnection {
|
||||
pub async fn execute(&self, stmt: Statement) -> Result<ExecResult, SeaErr> {
|
||||
pub async fn execute(&self, stmt: Statement) -> Result<ExecResult, DbErr> {
|
||||
debug_print!("{}", stmt);
|
||||
|
||||
let query = sqlx_query(&stmt);
|
||||
@ -46,10 +46,10 @@ impl SqlxSqlitePoolConnection {
|
||||
return Ok(res.into());
|
||||
}
|
||||
}
|
||||
Err(SeaErr::Execution)
|
||||
Err(DbErr::Execution)
|
||||
}
|
||||
|
||||
pub async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, SeaErr> {
|
||||
pub async fn query_one(&self, stmt: Statement) -> Result<Option<QueryResult>, DbErr> {
|
||||
debug_print!("{}", stmt);
|
||||
|
||||
let query = sqlx_query(&stmt);
|
||||
@ -60,11 +60,11 @@ impl SqlxSqlitePoolConnection {
|
||||
Ok(None)
|
||||
}
|
||||
} else {
|
||||
Err(SeaErr::Query)
|
||||
Err(DbErr::Query)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn query_all(&self, stmt: Statement) -> Result<Vec<QueryResult>, SeaErr> {
|
||||
pub async fn query_all(&self, stmt: Statement) -> Result<Vec<QueryResult>, DbErr> {
|
||||
debug_print!("{}", stmt);
|
||||
|
||||
let query = sqlx_query(&stmt);
|
||||
@ -73,7 +73,7 @@ impl SqlxSqlitePoolConnection {
|
||||
return Ok(rows.into_iter().map(|r| r.into()).collect());
|
||||
}
|
||||
}
|
||||
Err(SeaErr::Query)
|
||||
Err(DbErr::Query)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,8 +66,8 @@ pub trait ActiveModelTrait: Clone + Debug {
|
||||
fn default() -> Self;
|
||||
|
||||
// below is not yet possible. right now we define these methods in DeriveActiveModel
|
||||
// fn save(self, db: &DatabaseConnection) -> impl Future<Output = Result<Self, SeaErr>>;
|
||||
// fn delete(self, db: &DatabaseConnection) -> impl Future<Output = Result<DeleteResult, SeaErr>>;
|
||||
// fn save(self, db: &DatabaseConnection) -> impl Future<Output = Result<Self, DbErr>>;
|
||||
// fn delete(self, db: &DatabaseConnection) -> impl Future<Output = Result<DeleteResult, DbErr>>;
|
||||
}
|
||||
|
||||
/// Behaviors for users to override
|
||||
@ -188,7 +188,7 @@ where
|
||||
|
||||
/// Insert the model if primary key is unset, update otherwise.
|
||||
/// Only works if the entity has auto increment primary key.
|
||||
pub async fn save_active_model<A, E>(mut am: A, db: &DatabaseConnection) -> Result<A, SeaErr>
|
||||
pub async fn save_active_model<A, E>(mut am: A, db: &DatabaseConnection) -> Result<A, DbErr>
|
||||
where
|
||||
A: ActiveModelBehavior + ActiveModelTrait<Entity = E>,
|
||||
E::Model: IntoActiveModel<A>,
|
||||
@ -212,7 +212,7 @@ where
|
||||
Ok(am)
|
||||
}
|
||||
|
||||
async fn insert_and_select_active_model<A, E>(am: A, db: &DatabaseConnection) -> Result<A, SeaErr>
|
||||
async fn insert_and_select_active_model<A, E>(am: A, db: &DatabaseConnection) -> Result<A, DbErr>
|
||||
where
|
||||
A: ActiveModelTrait<Entity = E>,
|
||||
E::Model: IntoActiveModel<A>,
|
||||
@ -227,14 +227,14 @@ where
|
||||
let model: Option<E::Model> = res?;
|
||||
match model {
|
||||
Some(model) => Ok(model.into_active_model()),
|
||||
None => Err(SeaErr::Execution),
|
||||
None => Err(DbErr::Execution),
|
||||
}
|
||||
} else {
|
||||
Ok(A::default())
|
||||
}
|
||||
}
|
||||
|
||||
async fn update_active_model<A, E>(am: A, db: &DatabaseConnection) -> Result<A, SeaErr>
|
||||
async fn update_active_model<A, E>(am: A, db: &DatabaseConnection) -> Result<A, DbErr>
|
||||
where
|
||||
A: ActiveModelTrait<Entity = E>,
|
||||
E: EntityTrait,
|
||||
@ -246,7 +246,7 @@ where
|
||||
pub async fn delete_active_model<A, E>(
|
||||
mut am: A,
|
||||
db: &DatabaseConnection,
|
||||
) -> Result<DeleteResult, SeaErr>
|
||||
) -> Result<DeleteResult, DbErr>
|
||||
where
|
||||
A: ActiveModelBehavior + ActiveModelTrait<Entity = E>,
|
||||
E: EntityTrait,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{EntityTrait, SeaErr, QueryFilter, QueryResult, Related, Select};
|
||||
use crate::{EntityTrait, DbErr, QueryFilter, QueryResult, Related, Select};
|
||||
pub use sea_query::Value;
|
||||
use std::fmt::Debug;
|
||||
|
||||
@ -19,11 +19,11 @@ pub trait ModelTrait: Clone + Debug {
|
||||
}
|
||||
|
||||
pub trait FromQueryResult {
|
||||
fn from_query_result(res: &QueryResult, pre: &str) -> Result<Self, SeaErr>
|
||||
fn from_query_result(res: &QueryResult, pre: &str) -> Result<Self, DbErr>
|
||||
where
|
||||
Self: Sized;
|
||||
|
||||
fn from_query_result_optional(res: &QueryResult, pre: &str) -> Result<Option<Self>, SeaErr>
|
||||
fn from_query_result_optional(res: &QueryResult, pre: &str) -> Result<Option<Self>, DbErr>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::{error, fmt};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SeaErr {
|
||||
pub enum DbErr {
|
||||
Connection,
|
||||
Execution,
|
||||
Query,
|
||||
@ -9,7 +9,7 @@ pub enum SeaErr {
|
||||
Sqlx(sqlx::Error),
|
||||
}
|
||||
|
||||
impl fmt::Display for SeaErr {
|
||||
impl fmt::Display for DbErr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Self::Connection => write!(f, "{:?}", "Connection Error"),
|
||||
@ -21,7 +21,7 @@ impl fmt::Display for SeaErr {
|
||||
}
|
||||
}
|
||||
|
||||
impl error::Error for SeaErr {
|
||||
impl error::Error for DbErr {
|
||||
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
||||
match self {
|
||||
Self::Connection => None,
|
||||
@ -34,7 +34,7 @@ impl error::Error for SeaErr {
|
||||
}
|
||||
|
||||
#[cfg(feature = "sqlx-dep")]
|
||||
impl From<sqlx::Error> for SeaErr {
|
||||
impl From<sqlx::Error> for DbErr {
|
||||
fn from(sqlx_err: sqlx::Error) -> Self {
|
||||
Self::Sqlx(sqlx_err)
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ where
|
||||
pub fn exec(
|
||||
self,
|
||||
db: &'a DatabaseConnection,
|
||||
) -> impl Future<Output = Result<DeleteResult, SeaErr>> + 'a {
|
||||
) -> impl Future<Output = Result<DeleteResult, DbErr>> + 'a {
|
||||
// so that self is dropped before entering await
|
||||
exec_delete_only(self.query, db)
|
||||
}
|
||||
@ -34,7 +34,7 @@ where
|
||||
pub fn exec(
|
||||
self,
|
||||
db: &'a DatabaseConnection,
|
||||
) -> impl Future<Output = Result<DeleteResult, SeaErr>> + 'a {
|
||||
) -> impl Future<Output = Result<DeleteResult, DbErr>> + 'a {
|
||||
// so that self is dropped before entering await
|
||||
exec_delete_only(self.query, db)
|
||||
}
|
||||
@ -48,7 +48,7 @@ impl Deleter {
|
||||
pub fn exec(
|
||||
self,
|
||||
db: &DatabaseConnection,
|
||||
) -> impl Future<Output = Result<DeleteResult, SeaErr>> + '_ {
|
||||
) -> impl Future<Output = Result<DeleteResult, DbErr>> + '_ {
|
||||
let builder = db.get_query_builder_backend();
|
||||
exec_delete(builder.build(&self.query), db)
|
||||
}
|
||||
@ -57,7 +57,7 @@ impl Deleter {
|
||||
async fn exec_delete_only(
|
||||
query: DeleteStatement,
|
||||
db: &DatabaseConnection,
|
||||
) -> Result<DeleteResult, SeaErr> {
|
||||
) -> Result<DeleteResult, DbErr> {
|
||||
Deleter::new(query).exec(db).await
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ async fn exec_delete_only(
|
||||
async fn exec_delete(
|
||||
statement: Statement,
|
||||
db: &DatabaseConnection,
|
||||
) -> Result<DeleteResult, SeaErr> {
|
||||
) -> Result<DeleteResult, DbErr> {
|
||||
let result = db.execute(statement).await?;
|
||||
Ok(DeleteResult {
|
||||
rows_affected: result.rows_affected(),
|
||||
|
@ -19,7 +19,7 @@ where
|
||||
pub fn exec(
|
||||
self,
|
||||
db: &DatabaseConnection,
|
||||
) -> impl Future<Output = Result<InsertResult, SeaErr>> + '_ {
|
||||
) -> impl Future<Output = Result<InsertResult, DbErr>> + '_ {
|
||||
// so that self is dropped before entering await
|
||||
Inserter::new(self.into_query()).exec(db)
|
||||
}
|
||||
@ -33,7 +33,7 @@ impl Inserter {
|
||||
pub fn exec(
|
||||
self,
|
||||
db: &DatabaseConnection,
|
||||
) -> impl Future<Output = Result<InsertResult, SeaErr>> + '_ {
|
||||
) -> impl Future<Output = Result<InsertResult, DbErr>> + '_ {
|
||||
let builder = db.get_query_builder_backend();
|
||||
exec_insert(builder.build(&self.query), db)
|
||||
}
|
||||
@ -43,7 +43,7 @@ impl Inserter {
|
||||
async fn exec_insert(
|
||||
statement: Statement,
|
||||
db: &DatabaseConnection,
|
||||
) -> Result<InsertResult, SeaErr> {
|
||||
) -> Result<InsertResult, DbErr> {
|
||||
let result = db.execute(statement).await?;
|
||||
// TODO: Postgres instead use query_one + returning clause
|
||||
Ok(InsertResult {
|
||||
|
@ -23,7 +23,7 @@ where
|
||||
S: SelectorTrait + 'db,
|
||||
{
|
||||
/// Fetch a specific page
|
||||
pub async fn fetch_page(&self, page: usize) -> Result<Vec<S::Item>, SeaErr> {
|
||||
pub async fn fetch_page(&self, page: usize) -> Result<Vec<S::Item>, DbErr> {
|
||||
let query = self
|
||||
.query
|
||||
.clone()
|
||||
@ -42,12 +42,12 @@ where
|
||||
}
|
||||
|
||||
/// Fetch the current page
|
||||
pub async fn fetch(&self) -> Result<Vec<S::Item>, SeaErr> {
|
||||
pub async fn fetch(&self) -> Result<Vec<S::Item>, DbErr> {
|
||||
self.fetch_page(self.page).await
|
||||
}
|
||||
|
||||
/// Get the total number of pages
|
||||
pub async fn num_pages(&self) -> Result<usize, SeaErr> {
|
||||
pub async fn num_pages(&self) -> Result<usize, DbErr> {
|
||||
let builder = self.db.get_query_builder_backend();
|
||||
let stmt = builder.build(
|
||||
SelectStatement::new()
|
||||
@ -77,7 +77,7 @@ where
|
||||
}
|
||||
|
||||
/// Fetch one page and increment the page counter
|
||||
pub async fn fetch_and_next(&mut self) -> Result<Option<Vec<S::Item>>, SeaErr> {
|
||||
pub async fn fetch_and_next(&mut self) -> Result<Option<Vec<S::Item>>, DbErr> {
|
||||
let vec = self.fetch().await?;
|
||||
self.next();
|
||||
let opt = if !vec.is_empty() { Some(vec) } else { None };
|
||||
@ -85,7 +85,7 @@ where
|
||||
}
|
||||
|
||||
/// Convert self into an async stream
|
||||
pub fn into_stream(mut self) -> PinBoxStream<'db, Result<Vec<S::Item>, SeaErr>> {
|
||||
pub fn into_stream(mut self) -> PinBoxStream<'db, Result<Vec<S::Item>, DbErr>> {
|
||||
Box::pin(stream! {
|
||||
loop {
|
||||
if let Some(vec) = self.fetch_and_next().await? {
|
||||
@ -148,7 +148,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn fetch_page() -> Result<(), SeaErr> {
|
||||
async fn fetch_page() -> Result<(), DbErr> {
|
||||
let (db, pages) = setup();
|
||||
|
||||
let paginator = fruit::Entity::find().paginate(&db, 2);
|
||||
@ -178,7 +178,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn fetch() -> Result<(), SeaErr> {
|
||||
async fn fetch() -> Result<(), DbErr> {
|
||||
let (db, pages) = setup();
|
||||
|
||||
let mut paginator = fruit::Entity::find().paginate(&db, 2);
|
||||
@ -212,7 +212,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn num_pages() -> Result<(), SeaErr> {
|
||||
async fn num_pages() -> Result<(), DbErr> {
|
||||
let (db, num_rows) = setup_num_rows();
|
||||
|
||||
let num_rows = num_rows as usize;
|
||||
@ -244,7 +244,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn next_and_cur_page() -> Result<(), SeaErr> {
|
||||
async fn next_and_cur_page() -> Result<(), DbErr> {
|
||||
let (db, _) = setup();
|
||||
|
||||
let mut paginator = fruit::Entity::find().paginate(&db, 2);
|
||||
@ -260,7 +260,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn fetch_and_next() -> Result<(), SeaErr> {
|
||||
async fn fetch_and_next() -> Result<(), DbErr> {
|
||||
let (db, pages) = setup();
|
||||
|
||||
let mut paginator = fruit::Entity::find().paginate(&db, 2);
|
||||
@ -295,7 +295,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn into_stream() -> Result<(), SeaErr> {
|
||||
async fn into_stream() -> Result<(), DbErr> {
|
||||
let (db, pages) = setup();
|
||||
|
||||
let mut fruit_stream = fruit::Entity::find().paginate(&db, 2).into_stream();
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::SeaErr;
|
||||
use crate::DbErr;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -16,7 +16,7 @@ pub(crate) enum QueryResultRow {
|
||||
}
|
||||
|
||||
pub trait TryGetable {
|
||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, SeaErr>
|
||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, DbErr>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
@ -24,7 +24,7 @@ pub trait TryGetable {
|
||||
// QueryResult //
|
||||
|
||||
impl QueryResult {
|
||||
pub fn try_get<T>(&self, pre: &str, col: &str) -> Result<T, SeaErr>
|
||||
pub fn try_get<T>(&self, pre: &str, col: &str) -> Result<T, DbErr>
|
||||
where
|
||||
T: TryGetable,
|
||||
{
|
||||
@ -50,7 +50,7 @@ impl fmt::Debug for QueryResultRow {
|
||||
macro_rules! try_getable_all {
|
||||
( $type: ty ) => {
|
||||
impl TryGetable for $type {
|
||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, SeaErr> {
|
||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, DbErr> {
|
||||
let column = format!("{}{}", pre, col);
|
||||
match &res.row {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
@ -70,7 +70,7 @@ macro_rules! try_getable_all {
|
||||
}
|
||||
|
||||
impl TryGetable for Option<$type> {
|
||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, SeaErr> {
|
||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, DbErr> {
|
||||
let column = format!("{}{}", pre, col);
|
||||
match &res.row {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
@ -103,7 +103,7 @@ macro_rules! try_getable_all {
|
||||
macro_rules! try_getable_mysql {
|
||||
( $type: ty ) => {
|
||||
impl TryGetable for $type {
|
||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, SeaErr> {
|
||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, DbErr> {
|
||||
let column = format!("{}{}", pre, col);
|
||||
match &res.row {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
@ -122,7 +122,7 @@ macro_rules! try_getable_mysql {
|
||||
}
|
||||
|
||||
impl TryGetable for Option<$type> {
|
||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, SeaErr> {
|
||||
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, DbErr> {
|
||||
let column = format!("{}{}", pre, col);
|
||||
match &res.row {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
|
@ -18,7 +18,7 @@ where
|
||||
pub trait SelectorTrait {
|
||||
type Item: Sized;
|
||||
|
||||
fn from_raw_query_result(res: QueryResult) -> Result<Self::Item, SeaErr>;
|
||||
fn from_raw_query_result(res: QueryResult) -> Result<Self::Item, DbErr>;
|
||||
}
|
||||
|
||||
pub struct SelectModel<M>
|
||||
@ -43,7 +43,7 @@ where
|
||||
{
|
||||
type Item = M;
|
||||
|
||||
fn from_raw_query_result(res: QueryResult) -> Result<Self::Item, SeaErr> {
|
||||
fn from_raw_query_result(res: QueryResult) -> Result<Self::Item, DbErr> {
|
||||
M::from_query_result(&res, "")
|
||||
}
|
||||
}
|
||||
@ -55,7 +55,7 @@ where
|
||||
{
|
||||
type Item = (M, Option<N>);
|
||||
|
||||
fn from_raw_query_result(res: QueryResult) -> Result<Self::Item, SeaErr> {
|
||||
fn from_raw_query_result(res: QueryResult) -> Result<Self::Item, DbErr> {
|
||||
Ok((
|
||||
M::from_query_result(&res, combine::SELECT_A)?,
|
||||
N::from_query_result_optional(&res, combine::SELECT_B)?,
|
||||
@ -85,11 +85,11 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn one(self, db: &DatabaseConnection) -> Result<Option<E::Model>, SeaErr> {
|
||||
pub async fn one(self, db: &DatabaseConnection) -> Result<Option<E::Model>, DbErr> {
|
||||
self.into_model::<E::Model>().one(db).await
|
||||
}
|
||||
|
||||
pub async fn all(self, db: &DatabaseConnection) -> Result<Vec<E::Model>, SeaErr> {
|
||||
pub async fn all(self, db: &DatabaseConnection) -> Result<Vec<E::Model>, DbErr> {
|
||||
self.into_model::<E::Model>().all(db).await
|
||||
}
|
||||
|
||||
@ -129,14 +129,14 @@ where
|
||||
pub async fn one(
|
||||
self,
|
||||
db: &DatabaseConnection,
|
||||
) -> Result<Option<(E::Model, Option<F::Model>)>, SeaErr> {
|
||||
) -> Result<Option<(E::Model, Option<F::Model>)>, DbErr> {
|
||||
self.into_model::<E::Model, F::Model>().one(db).await
|
||||
}
|
||||
|
||||
pub async fn all(
|
||||
self,
|
||||
db: &DatabaseConnection,
|
||||
) -> Result<Vec<(E::Model, Option<F::Model>)>, SeaErr> {
|
||||
) -> Result<Vec<(E::Model, Option<F::Model>)>, DbErr> {
|
||||
self.into_model::<E::Model, F::Model>().all(db).await
|
||||
}
|
||||
}
|
||||
@ -168,14 +168,14 @@ where
|
||||
pub async fn one(
|
||||
self,
|
||||
db: &DatabaseConnection,
|
||||
) -> Result<Option<(E::Model, Option<F::Model>)>, SeaErr> {
|
||||
) -> Result<Option<(E::Model, Option<F::Model>)>, DbErr> {
|
||||
self.into_model::<E::Model, F::Model>().one(db).await
|
||||
}
|
||||
|
||||
pub async fn all(
|
||||
self,
|
||||
db: &DatabaseConnection,
|
||||
) -> Result<Vec<(E::Model, Vec<F::Model>)>, SeaErr> {
|
||||
) -> Result<Vec<(E::Model, Vec<F::Model>)>, DbErr> {
|
||||
let rows = self.into_model::<E::Model, F::Model>().all(db).await?;
|
||||
Ok(consolidate_query_result::<E, F>(rows))
|
||||
}
|
||||
@ -185,7 +185,7 @@ impl<S> Selector<S>
|
||||
where
|
||||
S: SelectorTrait,
|
||||
{
|
||||
pub async fn one(mut self, db: &DatabaseConnection) -> Result<Option<S::Item>, SeaErr> {
|
||||
pub async fn one(mut self, db: &DatabaseConnection) -> Result<Option<S::Item>, DbErr> {
|
||||
let builder = db.get_query_builder_backend();
|
||||
self.query.limit(1);
|
||||
let row = db.query_one(builder.build(&self.query)).await?;
|
||||
@ -195,7 +195,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn all(self, db: &DatabaseConnection) -> Result<Vec<S::Item>, SeaErr> {
|
||||
pub async fn all(self, db: &DatabaseConnection) -> Result<Vec<S::Item>, DbErr> {
|
||||
let builder = db.get_query_builder_backend();
|
||||
let rows = db.query_all(builder.build(&self.query)).await?;
|
||||
let mut models = Vec::new();
|
||||
|
@ -21,7 +21,7 @@ where
|
||||
pub fn exec(
|
||||
self,
|
||||
db: &'a DatabaseConnection,
|
||||
) -> impl Future<Output = Result<A, SeaErr>> + 'a {
|
||||
) -> impl Future<Output = Result<A, DbErr>> + 'a {
|
||||
// so that self is dropped before entering await
|
||||
exec_update_and_return_original(self.query, self.model, db)
|
||||
}
|
||||
@ -34,7 +34,7 @@ where
|
||||
pub fn exec(
|
||||
self,
|
||||
db: &'a DatabaseConnection,
|
||||
) -> impl Future<Output = Result<UpdateResult, SeaErr>> + 'a {
|
||||
) -> impl Future<Output = Result<UpdateResult, DbErr>> + 'a {
|
||||
// so that self is dropped before entering await
|
||||
exec_update_only(self.query, db)
|
||||
}
|
||||
@ -48,7 +48,7 @@ impl Updater {
|
||||
pub fn exec(
|
||||
self,
|
||||
db: &DatabaseConnection,
|
||||
) -> impl Future<Output = Result<UpdateResult, SeaErr>> + '_ {
|
||||
) -> impl Future<Output = Result<UpdateResult, DbErr>> + '_ {
|
||||
let builder = db.get_query_builder_backend();
|
||||
exec_update(builder.build(&self.query), db)
|
||||
}
|
||||
@ -57,7 +57,7 @@ impl Updater {
|
||||
async fn exec_update_only(
|
||||
query: UpdateStatement,
|
||||
db: &DatabaseConnection,
|
||||
) -> Result<UpdateResult, SeaErr> {
|
||||
) -> Result<UpdateResult, DbErr> {
|
||||
Updater::new(query).exec(db).await
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ async fn exec_update_and_return_original<A>(
|
||||
query: UpdateStatement,
|
||||
model: A,
|
||||
db: &DatabaseConnection,
|
||||
) -> Result<A, SeaErr>
|
||||
) -> Result<A, DbErr>
|
||||
where
|
||||
A: ActiveModelTrait,
|
||||
{
|
||||
@ -77,7 +77,7 @@ where
|
||||
async fn exec_update(
|
||||
statement: Statement,
|
||||
db: &DatabaseConnection,
|
||||
) -> Result<UpdateResult, SeaErr> {
|
||||
) -> Result<UpdateResult, DbErr> {
|
||||
let result = db.execute(statement).await?;
|
||||
Ok(UpdateResult {
|
||||
rows_affected: result.rows_affected(),
|
||||
|
16
src/lib.rs
16
src/lib.rs
@ -44,7 +44,7 @@
|
||||
//! ## Select
|
||||
//! ```
|
||||
//! # use sea_orm::{DbConn, error::*, entity::*, query::*, tests_cfg::*};
|
||||
//! # async fn function(db: &DbConn) -> Result<(), SeaErr> {
|
||||
//! # async fn function(db: &DbConn) -> Result<(), DbErr> {
|
||||
//! #
|
||||
//! // find all models
|
||||
//! let cakes: Vec<cake::Model> = Cake::find().all(db).await?;
|
||||
@ -74,7 +74,7 @@
|
||||
//! ## Insert
|
||||
//! ```
|
||||
//! # use sea_orm::{DbConn, error::*, entity::*, query::*, tests_cfg::*};
|
||||
//! # async fn function(db: &DbConn) -> Result<(), SeaErr> {
|
||||
//! # async fn function(db: &DbConn) -> Result<(), DbErr> {
|
||||
//! #
|
||||
//! let apple = fruit::ActiveModel {
|
||||
//! name: Set("Apple".to_owned()),
|
||||
@ -94,7 +94,7 @@
|
||||
//! # Ok(())
|
||||
//! # }
|
||||
//! #
|
||||
//! # async fn function2(db: &DbConn) -> Result<(), SeaErr> {
|
||||
//! # async fn function2(db: &DbConn) -> Result<(), DbErr> {
|
||||
//! # let apple = fruit::ActiveModel {
|
||||
//! # name: Set("Apple".to_owned()),
|
||||
//! # ..Default::default() // no need to set primary key
|
||||
@ -117,12 +117,12 @@
|
||||
//! #
|
||||
//! use sea_orm::sea_query::{Expr, Value};
|
||||
//!
|
||||
//! # async fn function(db: &DbConn) -> Result<(), SeaErr> {
|
||||
//! # async fn function(db: &DbConn) -> Result<(), DbErr> {
|
||||
//! let pear: Option<fruit::Model> = Fruit::find_by_id(1).one(db).await?;
|
||||
//! # Ok(())
|
||||
//! # }
|
||||
//! #
|
||||
//! # async fn function2(db: &DbConn) -> Result<(), SeaErr> {
|
||||
//! # async fn function2(db: &DbConn) -> Result<(), DbErr> {
|
||||
//! # let pear: Option<fruit::Model> = Fruit::find_by_id(1).one(db).await.unwrap();
|
||||
//!
|
||||
//! let mut pear: fruit::ActiveModel = pear.unwrap().into();
|
||||
@ -145,7 +145,7 @@
|
||||
//! ```
|
||||
//! # use sea_orm::{DbConn, error::*, entity::*, query::*, tests_cfg::*};
|
||||
//! #
|
||||
//! # async fn function(db: &DbConn) -> Result<(), SeaErr> {
|
||||
//! # async fn function(db: &DbConn) -> Result<(), DbErr> {
|
||||
//! let banana = fruit::ActiveModel {
|
||||
//! id: Unset(None),
|
||||
//! name: Set("Banana".to_owned()),
|
||||
@ -167,12 +167,12 @@
|
||||
//! ```
|
||||
//! # use sea_orm::{DbConn, error::*, entity::*, query::*, tests_cfg::*};
|
||||
//! #
|
||||
//! # async fn function(db: &DbConn) -> Result<(), SeaErr> {
|
||||
//! # async fn function(db: &DbConn) -> Result<(), DbErr> {
|
||||
//! let orange: Option<fruit::Model> = Fruit::find_by_id(1).one(db).await?;
|
||||
//! # Ok(())
|
||||
//! # }
|
||||
//! #
|
||||
//! # async fn function2(db: &DbConn) -> Result<(), SeaErr> {
|
||||
//! # async fn function2(db: &DbConn) -> Result<(), DbErr> {
|
||||
//! # let orange: Option<fruit::Model> = Fruit::find_by_id(1).one(db).await.unwrap();
|
||||
//! let orange: fruit::ActiveModel = orange.unwrap().into();
|
||||
//!
|
||||
|
@ -1,9 +1,9 @@
|
||||
use crate::{FromQueryResult, SeaErr, QueryResult, QueryResultRow};
|
||||
use crate::{FromQueryResult, DbErr, QueryResult, QueryResultRow};
|
||||
use serde_json::Map;
|
||||
pub use serde_json::Value as JsonValue;
|
||||
|
||||
impl FromQueryResult for JsonValue {
|
||||
fn from_query_result(res: &QueryResult, pre: &str) -> Result<Self, SeaErr> {
|
||||
fn from_query_result(res: &QueryResult, pre: &str) -> Result<Self, DbErr> {
|
||||
match &res.row {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
QueryResultRow::SqlxMySql(row) => {
|
||||
|
@ -31,7 +31,7 @@ async fn setup_schema(db: &DbConn) {
|
||||
println!("Create table cake: {:?}", result);
|
||||
}
|
||||
|
||||
async fn crud_cake(db: &DbConn) -> Result<(), SeaErr> {
|
||||
async fn crud_cake(db: &DbConn) -> Result<(), DbErr> {
|
||||
let apple = cake::ActiveModel {
|
||||
name: Set("Apple Pie".to_owned()),
|
||||
..Default::default()
|
||||
|
Loading…
x
Reference in New Issue
Block a user