DbBackend alias
This commit is contained in:
parent
041f1a135b
commit
9334d4ff5d
@ -2,7 +2,7 @@ mod entity;
|
||||
|
||||
use entity::*;
|
||||
|
||||
use sea_orm::{entity::*, error::*, DatabaseBackend, MockDatabase, MockExecResult, Transaction};
|
||||
use sea_orm::{entity::*, error::*, DbBackend, MockDatabase, MockExecResult, Transaction};
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_insert() -> Result<(), DbErr> {
|
||||
@ -11,7 +11,7 @@ async fn test_insert() -> Result<(), DbErr> {
|
||||
rows_affected: 1,
|
||||
};
|
||||
|
||||
let db = MockDatabase::new(DatabaseBackend::Postgres)
|
||||
let db = MockDatabase::new(DbBackend::Postgres)
|
||||
.append_exec_results(vec![exec_result.clone()])
|
||||
.into_connection();
|
||||
|
||||
@ -27,7 +27,7 @@ async fn test_insert() -> Result<(), DbErr> {
|
||||
assert_eq!(
|
||||
db.into_transaction_log(),
|
||||
vec![Transaction::from_sql_and_values(
|
||||
DatabaseBackend::Postgres,
|
||||
DbBackend::Postgres,
|
||||
r#"INSERT INTO "cake" ("name") VALUES ($1)"#,
|
||||
vec!["Apple Pie".into()]
|
||||
)]
|
||||
@ -43,7 +43,7 @@ async fn test_select() -> Result<(), DbErr> {
|
||||
filling_id: 3,
|
||||
}];
|
||||
|
||||
let db = MockDatabase::new(DatabaseBackend::Postgres)
|
||||
let db = MockDatabase::new(DbBackend::Postgres)
|
||||
.append_query_results(vec![query_results.clone()])
|
||||
.into_connection();
|
||||
|
||||
@ -54,7 +54,7 @@ async fn test_select() -> Result<(), DbErr> {
|
||||
assert_eq!(
|
||||
db.into_transaction_log(),
|
||||
vec![Transaction::from_sql_and_values(
|
||||
DatabaseBackend::Postgres,
|
||||
DbBackend::Postgres,
|
||||
[
|
||||
r#"SELECT "cake_filling"."cake_id", "cake_filling"."filling_id" FROM "cake_filling""#,
|
||||
r#"WHERE "cake_filling"."cake_id" = $1 AND "cake_filling"."filling_id" = $2"#,
|
||||
@ -73,7 +73,7 @@ async fn test_update() -> Result<(), DbErr> {
|
||||
rows_affected: 1,
|
||||
};
|
||||
|
||||
let db = MockDatabase::new(DatabaseBackend::Postgres)
|
||||
let db = MockDatabase::new(DbBackend::Postgres)
|
||||
.append_exec_results(vec![exec_result.clone()])
|
||||
.into_connection();
|
||||
|
||||
@ -90,7 +90,7 @@ async fn test_update() -> Result<(), DbErr> {
|
||||
assert_eq!(
|
||||
db.into_transaction_log(),
|
||||
vec![Transaction::from_sql_and_values(
|
||||
DatabaseBackend::Postgres,
|
||||
DbBackend::Postgres,
|
||||
r#"UPDATE "fruit" SET "name" = $1 WHERE "fruit"."id" = $2"#,
|
||||
vec!["Orange".into(), 1i32.into()]
|
||||
)]
|
||||
@ -106,7 +106,7 @@ async fn test_delete() -> Result<(), DbErr> {
|
||||
rows_affected: 1,
|
||||
};
|
||||
|
||||
let db = MockDatabase::new(DatabaseBackend::Postgres)
|
||||
let db = MockDatabase::new(DbBackend::Postgres)
|
||||
.append_exec_results(vec![exec_result.clone()])
|
||||
.into_connection();
|
||||
|
||||
@ -122,7 +122,7 @@ async fn test_delete() -> Result<(), DbErr> {
|
||||
assert_eq!(
|
||||
db.into_transaction_log(),
|
||||
vec![Transaction::from_sql_and_values(
|
||||
DatabaseBackend::Postgres,
|
||||
DbBackend::Postgres,
|
||||
r#"DELETE FROM "fruit" WHERE "fruit"."id" = $1"#,
|
||||
vec![3i32.into()]
|
||||
)]
|
||||
|
@ -20,6 +20,8 @@ pub enum DatabaseBackend {
|
||||
Sqlite,
|
||||
}
|
||||
|
||||
pub type DbBackend = DatabaseBackend;
|
||||
|
||||
impl Default for DatabaseConnection {
|
||||
fn default() -> Self {
|
||||
Self::Disconnected
|
||||
@ -45,12 +47,12 @@ impl std::fmt::Debug for DatabaseConnection {
|
||||
}
|
||||
|
||||
impl DatabaseConnection {
|
||||
pub fn get_database_backend(&self) -> DatabaseBackend {
|
||||
pub fn get_database_backend(&self) -> DbBackend {
|
||||
match self {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
DatabaseConnection::SqlxMySqlPoolConnection(_) => DatabaseBackend::MySql,
|
||||
DatabaseConnection::SqlxMySqlPoolConnection(_) => DbBackend::MySql,
|
||||
#[cfg(feature = "sqlx-sqlite")]
|
||||
DatabaseConnection::SqlxSqlitePoolConnection(_) => DatabaseBackend::Sqlite,
|
||||
DatabaseConnection::SqlxSqlitePoolConnection(_) => DbBackend::Sqlite,
|
||||
#[cfg(feature = "mock")]
|
||||
DatabaseConnection::MockDatabaseConnection(conn) => conn.get_database_backend(),
|
||||
DatabaseConnection::Disconnected => panic!("Disconnected"),
|
||||
@ -113,7 +115,7 @@ impl DatabaseConnection {
|
||||
}
|
||||
}
|
||||
|
||||
impl DatabaseBackend {
|
||||
impl DbBackend {
|
||||
pub fn build<S>(&self, statement: &S) -> Statement
|
||||
where
|
||||
S: StatementBuilder,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
error::*, DatabaseBackend, DatabaseConnection, EntityTrait, ExecResult, ExecResultHolder, Iden,
|
||||
error::*, DbBackend, DatabaseConnection, EntityTrait, ExecResult, ExecResultHolder, Iden,
|
||||
Iterable, MockDatabaseConnection, MockDatabaseTrait, ModelTrait, QueryResult, QueryResultRow,
|
||||
Statement, Transaction,
|
||||
};
|
||||
@ -8,7 +8,7 @@ use std::collections::BTreeMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MockDatabase {
|
||||
db_backend: DatabaseBackend,
|
||||
db_backend: DbBackend,
|
||||
transaction_log: Vec<Transaction>,
|
||||
exec_results: Vec<MockExecResult>,
|
||||
query_results: Vec<Vec<MockRow>>,
|
||||
@ -43,7 +43,7 @@ where
|
||||
}
|
||||
|
||||
impl MockDatabase {
|
||||
pub fn new(db_backend: DatabaseBackend) -> Self {
|
||||
pub fn new(db_backend: DbBackend) -> Self {
|
||||
Self {
|
||||
db_backend,
|
||||
transaction_log: Vec::new(),
|
||||
@ -103,7 +103,7 @@ impl MockDatabaseTrait for MockDatabase {
|
||||
std::mem::take(&mut self.transaction_log)
|
||||
}
|
||||
|
||||
fn get_database_backend(&self) -> DatabaseBackend {
|
||||
fn get_database_backend(&self) -> DbBackend {
|
||||
self.db_backend
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::DatabaseBackend;
|
||||
use crate::DbBackend;
|
||||
use sea_query::{
|
||||
inject_parameters, MysqlQueryBuilder, PostgresQueryBuilder, SqliteQueryBuilder, Values,
|
||||
};
|
||||
@ -8,15 +8,15 @@ use std::fmt;
|
||||
pub struct Statement {
|
||||
pub sql: String,
|
||||
pub values: Option<Values>,
|
||||
pub db_backend: DatabaseBackend,
|
||||
pub db_backend: DbBackend,
|
||||
}
|
||||
|
||||
pub trait StatementBuilder {
|
||||
fn build(&self, db_backend: &DatabaseBackend) -> Statement;
|
||||
fn build(&self, db_backend: &DbBackend) -> Statement;
|
||||
}
|
||||
|
||||
impl Statement {
|
||||
pub fn from_string(db_backend: DatabaseBackend, stmt: String) -> Statement {
|
||||
pub fn from_string(db_backend: DbBackend, stmt: String) -> Statement {
|
||||
Statement {
|
||||
sql: stmt,
|
||||
values: None,
|
||||
@ -25,7 +25,7 @@ impl Statement {
|
||||
}
|
||||
|
||||
pub fn from_string_values_tuple(
|
||||
db_backend: DatabaseBackend,
|
||||
db_backend: DbBackend,
|
||||
stmt: (String, Values),
|
||||
) -> Statement {
|
||||
Statement {
|
||||
@ -57,9 +57,9 @@ impl fmt::Display for Statement {
|
||||
macro_rules! build_any_stmt {
|
||||
($stmt: expr, $db_backend: expr) => {
|
||||
match $db_backend {
|
||||
DatabaseBackend::MySql => $stmt.build(MysqlQueryBuilder),
|
||||
DatabaseBackend::Postgres => $stmt.build(PostgresQueryBuilder),
|
||||
DatabaseBackend::Sqlite => $stmt.build(SqliteQueryBuilder),
|
||||
DbBackend::MySql => $stmt.build(MysqlQueryBuilder),
|
||||
DbBackend::Postgres => $stmt.build(PostgresQueryBuilder),
|
||||
DbBackend::Sqlite => $stmt.build(SqliteQueryBuilder),
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -67,7 +67,7 @@ macro_rules! build_any_stmt {
|
||||
macro_rules! build_query_stmt {
|
||||
($stmt: ty) => {
|
||||
impl StatementBuilder for $stmt {
|
||||
fn build(&self, db_backend: &DatabaseBackend) -> Statement {
|
||||
fn build(&self, db_backend: &DbBackend) -> Statement {
|
||||
let stmt = build_any_stmt!(self, db_backend);
|
||||
Statement::from_string_values_tuple(*db_backend, stmt)
|
||||
}
|
||||
@ -83,7 +83,7 @@ build_query_stmt!(sea_query::DeleteStatement);
|
||||
macro_rules! build_schema_stmt {
|
||||
($stmt: ty) => {
|
||||
impl StatementBuilder for $stmt {
|
||||
fn build(&self, db_backend: &DatabaseBackend) -> Statement {
|
||||
fn build(&self, db_backend: &DbBackend) -> Statement {
|
||||
let stmt = build_any_stmt!(self, db_backend);
|
||||
Statement::from_string(*db_backend, stmt)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{DatabaseBackend, Statement};
|
||||
use crate::{DbBackend, Statement};
|
||||
use sea_query::{Value, Values};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@ -7,7 +7,7 @@ pub struct Transaction {
|
||||
}
|
||||
|
||||
impl Transaction {
|
||||
pub fn from_sql_and_values<I>(db_backend: DatabaseBackend, sql: &str, values: I) -> Self
|
||||
pub fn from_sql_and_values<I>(db_backend: DbBackend, sql: &str, values: I) -> Self
|
||||
where
|
||||
I: IntoIterator<Item = Value>,
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
debug_print, error::*, DatabaseBackend, DatabaseConnection, ExecResult, MockDatabase,
|
||||
debug_print, error::*, DbBackend, DatabaseConnection, ExecResult, MockDatabase,
|
||||
QueryResult, Statement, Transaction,
|
||||
};
|
||||
use std::sync::{
|
||||
@ -21,7 +21,7 @@ pub trait MockDatabaseTrait: Send {
|
||||
|
||||
fn drain_transaction_log(&mut self) -> Vec<Transaction>;
|
||||
|
||||
fn get_database_backend(&self) -> DatabaseBackend;
|
||||
fn get_database_backend(&self) -> DbBackend;
|
||||
}
|
||||
|
||||
impl MockDatabaseConnector {
|
||||
@ -48,13 +48,13 @@ impl MockDatabaseConnector {
|
||||
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
if crate::SqlxMySqlConnector::accepts(string) {
|
||||
return connect_mock_db!(DatabaseBackend::MySql);
|
||||
return connect_mock_db!(DbBackend::MySql);
|
||||
}
|
||||
#[cfg(feature = "sqlx-sqlite")]
|
||||
if crate::SqlxSqliteConnector::accepts(string) {
|
||||
return connect_mock_db!(DatabaseBackend::Sqlite);
|
||||
return connect_mock_db!(DbBackend::Sqlite);
|
||||
}
|
||||
connect_mock_db!(DatabaseBackend::Postgres)
|
||||
connect_mock_db!(DbBackend::Postgres)
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ impl MockDatabaseConnection {
|
||||
self.mocker.lock().unwrap().query(counter, statement)
|
||||
}
|
||||
|
||||
pub fn get_database_backend(&self) -> DatabaseBackend {
|
||||
pub fn get_database_backend(&self) -> DbBackend {
|
||||
self.mocker.lock().unwrap().get_database_backend()
|
||||
}
|
||||
}
|
||||
|
@ -71,9 +71,9 @@ pub trait EntityTrait: EntityName {
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "mock")]
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, Transaction, DatabaseBackend};
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, Transaction, DbBackend};
|
||||
/// #
|
||||
/// # let db = MockDatabase::new(DatabaseBackend::Postgres)
|
||||
/// # let db = MockDatabase::new(DbBackend::Postgres)
|
||||
/// # .append_query_results(vec![
|
||||
/// # vec![
|
||||
/// # cake::Model {
|
||||
@ -127,10 +127,10 @@ pub trait EntityTrait: EntityName {
|
||||
/// db.into_transaction_log(),
|
||||
/// vec![
|
||||
/// Transaction::from_sql_and_values(
|
||||
/// DatabaseBackend::Postgres, r#"SELECT "cake"."id", "cake"."name" FROM "cake" LIMIT $1"#, vec![1u64.into()]
|
||||
/// DbBackend::Postgres, r#"SELECT "cake"."id", "cake"."name" FROM "cake" LIMIT $1"#, vec![1u64.into()]
|
||||
/// ),
|
||||
/// Transaction::from_sql_and_values(
|
||||
/// DatabaseBackend::Postgres, r#"SELECT "cake"."id", "cake"."name" FROM "cake""#, vec![]
|
||||
/// DbBackend::Postgres, r#"SELECT "cake"."id", "cake"."name" FROM "cake""#, vec![]
|
||||
/// ),
|
||||
/// ]);
|
||||
/// ```
|
||||
@ -144,9 +144,9 @@ pub trait EntityTrait: EntityName {
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "mock")]
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, Transaction, DatabaseBackend};
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, Transaction, DbBackend};
|
||||
/// #
|
||||
/// # let db = MockDatabase::new(DatabaseBackend::Postgres)
|
||||
/// # let db = MockDatabase::new(DbBackend::Postgres)
|
||||
/// # .append_query_results(vec![
|
||||
/// # vec![
|
||||
/// # cake::Model {
|
||||
@ -175,15 +175,15 @@ pub trait EntityTrait: EntityName {
|
||||
/// assert_eq!(
|
||||
/// db.into_transaction_log(),
|
||||
/// vec![Transaction::from_sql_and_values(
|
||||
/// DatabaseBackend::Postgres, r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "cake"."id" = $1"#, vec![11i32.into()]
|
||||
/// DbBackend::Postgres, r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "cake"."id" = $1"#, vec![11i32.into()]
|
||||
/// )]);
|
||||
/// ```
|
||||
/// Find by composite key
|
||||
/// ```
|
||||
/// # #[cfg(feature = "mock")]
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, Transaction, DatabaseBackend};
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, Transaction, DbBackend};
|
||||
/// #
|
||||
/// # let db = MockDatabase::new(DatabaseBackend::Postgres)
|
||||
/// # let db = MockDatabase::new(DbBackend::Postgres)
|
||||
/// # .append_query_results(vec![
|
||||
/// # vec![
|
||||
/// # cake_filling::Model {
|
||||
@ -212,7 +212,7 @@ pub trait EntityTrait: EntityName {
|
||||
/// assert_eq!(
|
||||
/// db.into_transaction_log(),
|
||||
/// vec![Transaction::from_sql_and_values(
|
||||
/// DatabaseBackend::Postgres,
|
||||
/// DbBackend::Postgres,
|
||||
/// [
|
||||
/// r#"SELECT "cake_filling"."cake_id", "cake_filling"."filling_id" FROM "cake_filling""#,
|
||||
/// r#"WHERE "cake_filling"."cake_id" = $1 AND "cake_filling"."filling_id" = $2"#,
|
||||
@ -246,9 +246,9 @@ pub trait EntityTrait: EntityName {
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "mock")]
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, Transaction, DatabaseBackend};
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, Transaction, DbBackend};
|
||||
/// #
|
||||
/// # let db = MockDatabase::new(DatabaseBackend::Postgres)
|
||||
/// # let db = MockDatabase::new(DbBackend::Postgres)
|
||||
/// # .append_exec_results(vec![
|
||||
/// # MockExecResult {
|
||||
/// # last_insert_id: 15,
|
||||
@ -277,7 +277,7 @@ pub trait EntityTrait: EntityName {
|
||||
/// assert_eq!(
|
||||
/// db.into_transaction_log(),
|
||||
/// vec![Transaction::from_sql_and_values(
|
||||
/// DatabaseBackend::Postgres, r#"INSERT INTO "cake" ("name") VALUES ($1)"#, vec!["Apple Pie".into()]
|
||||
/// DbBackend::Postgres, r#"INSERT INTO "cake" ("name") VALUES ($1)"#, vec!["Apple Pie".into()]
|
||||
/// )]);
|
||||
/// ```
|
||||
fn insert<A>(model: A) -> Insert<A>
|
||||
@ -293,9 +293,9 @@ pub trait EntityTrait: EntityName {
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "mock")]
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, Transaction, DatabaseBackend};
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, Transaction, DbBackend};
|
||||
/// #
|
||||
/// # let db = MockDatabase::new(DatabaseBackend::Postgres)
|
||||
/// # let db = MockDatabase::new(DbBackend::Postgres)
|
||||
/// # .append_exec_results(vec![
|
||||
/// # MockExecResult {
|
||||
/// # last_insert_id: 28,
|
||||
@ -328,7 +328,7 @@ pub trait EntityTrait: EntityName {
|
||||
/// assert_eq!(
|
||||
/// db.into_transaction_log(),
|
||||
/// vec![Transaction::from_sql_and_values(
|
||||
/// DatabaseBackend::Postgres, r#"INSERT INTO "cake" ("name") VALUES ($1), ($2)"#,
|
||||
/// DbBackend::Postgres, r#"INSERT INTO "cake" ("name") VALUES ($1), ($2)"#,
|
||||
/// vec!["Apple Pie".into(), "Orange Scone".into()]
|
||||
/// )]);
|
||||
/// ```
|
||||
@ -348,9 +348,9 @@ pub trait EntityTrait: EntityName {
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "mock")]
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, Transaction, DatabaseBackend};
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, Transaction, DbBackend};
|
||||
/// #
|
||||
/// # let db = MockDatabase::new(DatabaseBackend::Postgres)
|
||||
/// # let db = MockDatabase::new(DbBackend::Postgres)
|
||||
/// # .append_exec_results(vec![
|
||||
/// # MockExecResult {
|
||||
/// # last_insert_id: 0,
|
||||
@ -380,7 +380,7 @@ pub trait EntityTrait: EntityName {
|
||||
/// assert_eq!(
|
||||
/// db.into_transaction_log(),
|
||||
/// vec![Transaction::from_sql_and_values(
|
||||
/// DatabaseBackend::Postgres, r#"UPDATE "fruit" SET "name" = $1 WHERE "fruit"."id" = $2"#, vec!["Orange".into(), 1i32.into()]
|
||||
/// DbBackend::Postgres, r#"UPDATE "fruit" SET "name" = $1 WHERE "fruit"."id" = $2"#, vec!["Orange".into(), 1i32.into()]
|
||||
/// )]);
|
||||
/// ```
|
||||
fn update<A>(model: A) -> UpdateOne<A>
|
||||
@ -398,9 +398,9 @@ pub trait EntityTrait: EntityName {
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "mock")]
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, Transaction, DatabaseBackend};
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, Transaction, DbBackend};
|
||||
/// #
|
||||
/// # let db = MockDatabase::new(DatabaseBackend::Postgres)
|
||||
/// # let db = MockDatabase::new(DbBackend::Postgres)
|
||||
/// # .append_exec_results(vec![
|
||||
/// # MockExecResult {
|
||||
/// # last_insert_id: 0,
|
||||
@ -427,7 +427,7 @@ pub trait EntityTrait: EntityName {
|
||||
/// assert_eq!(
|
||||
/// db.into_transaction_log(),
|
||||
/// vec![Transaction::from_sql_and_values(
|
||||
/// DatabaseBackend::Postgres, r#"UPDATE "fruit" SET "cake_id" = $1 WHERE "fruit"."name" LIKE $2"#, vec![Value::Null, "%Apple%".into()]
|
||||
/// DbBackend::Postgres, r#"UPDATE "fruit" SET "cake_id" = $1 WHERE "fruit"."name" LIKE $2"#, vec![Value::Null, "%Apple%".into()]
|
||||
/// )]);
|
||||
/// ```
|
||||
fn update_many() -> UpdateMany<Self> {
|
||||
@ -442,9 +442,9 @@ pub trait EntityTrait: EntityName {
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "mock")]
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, Transaction, DatabaseBackend};
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, Transaction, DbBackend};
|
||||
/// #
|
||||
/// # let db = MockDatabase::new(DatabaseBackend::Postgres)
|
||||
/// # let db = MockDatabase::new(DbBackend::Postgres)
|
||||
/// # .append_exec_results(vec![
|
||||
/// # MockExecResult {
|
||||
/// # last_insert_id: 0,
|
||||
@ -472,7 +472,7 @@ pub trait EntityTrait: EntityName {
|
||||
/// assert_eq!(
|
||||
/// db.into_transaction_log(),
|
||||
/// vec![Transaction::from_sql_and_values(
|
||||
/// DatabaseBackend::Postgres, r#"DELETE FROM "fruit" WHERE "fruit"."id" = $1"#, vec![3i32.into()]
|
||||
/// DbBackend::Postgres, r#"DELETE FROM "fruit" WHERE "fruit"."id" = $1"#, vec![3i32.into()]
|
||||
/// )]);
|
||||
/// ```
|
||||
fn delete<A>(model: A) -> DeleteOne<A>
|
||||
@ -490,9 +490,9 @@ pub trait EntityTrait: EntityName {
|
||||
///
|
||||
/// ```
|
||||
/// # #[cfg(feature = "mock")]
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, Transaction, DatabaseBackend};
|
||||
/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, Transaction, DbBackend};
|
||||
/// #
|
||||
/// # let db = MockDatabase::new(DatabaseBackend::Postgres)
|
||||
/// # let db = MockDatabase::new(DbBackend::Postgres)
|
||||
/// # .append_exec_results(vec![
|
||||
/// # MockExecResult {
|
||||
/// # last_insert_id: 0,
|
||||
@ -518,7 +518,7 @@ pub trait EntityTrait: EntityName {
|
||||
/// assert_eq!(
|
||||
/// db.into_transaction_log(),
|
||||
/// vec![Transaction::from_sql_and_values(
|
||||
/// DatabaseBackend::Postgres, r#"DELETE FROM "fruit" WHERE "fruit"."name" LIKE $1"#, vec!["%Apple%".into()]
|
||||
/// DbBackend::Postgres, r#"DELETE FROM "fruit" WHERE "fruit"."name" LIKE $1"#, vec!["%Apple%".into()]
|
||||
/// )]);
|
||||
/// ```
|
||||
fn delete_many() -> DeleteMany<Self> {
|
||||
|
@ -88,12 +88,12 @@ pub trait ColumnTrait: IdenStatic + Iterable {
|
||||
bind_oper!(lte);
|
||||
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find()
|
||||
/// .filter(cake::Column::Id.between(2,3))
|
||||
/// .build(DatabaseBackend::MySql)
|
||||
/// .build(DbBackend::MySql)
|
||||
/// .to_string(),
|
||||
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`id` BETWEEN 2 AND 3"
|
||||
/// );
|
||||
@ -106,12 +106,12 @@ pub trait ColumnTrait: IdenStatic + Iterable {
|
||||
}
|
||||
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find()
|
||||
/// .filter(cake::Column::Id.not_between(2,3))
|
||||
/// .build(DatabaseBackend::MySql)
|
||||
/// .build(DbBackend::MySql)
|
||||
/// .to_string(),
|
||||
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`id` NOT BETWEEN 2 AND 3"
|
||||
/// );
|
||||
@ -124,12 +124,12 @@ pub trait ColumnTrait: IdenStatic + Iterable {
|
||||
}
|
||||
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find()
|
||||
/// .filter(cake::Column::Name.like("cheese"))
|
||||
/// .build(DatabaseBackend::MySql)
|
||||
/// .build(DbBackend::MySql)
|
||||
/// .to_string(),
|
||||
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` LIKE 'cheese'"
|
||||
/// );
|
||||
@ -139,12 +139,12 @@ pub trait ColumnTrait: IdenStatic + Iterable {
|
||||
}
|
||||
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find()
|
||||
/// .filter(cake::Column::Name.not_like("cheese"))
|
||||
/// .build(DatabaseBackend::MySql)
|
||||
/// .build(DbBackend::MySql)
|
||||
/// .to_string(),
|
||||
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` NOT LIKE 'cheese'"
|
||||
/// );
|
||||
@ -154,12 +154,12 @@ pub trait ColumnTrait: IdenStatic + Iterable {
|
||||
}
|
||||
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find()
|
||||
/// .filter(cake::Column::Name.starts_with("cheese"))
|
||||
/// .build(DatabaseBackend::MySql)
|
||||
/// .build(DbBackend::MySql)
|
||||
/// .to_string(),
|
||||
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` LIKE 'cheese%'"
|
||||
/// );
|
||||
@ -170,12 +170,12 @@ pub trait ColumnTrait: IdenStatic + Iterable {
|
||||
}
|
||||
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find()
|
||||
/// .filter(cake::Column::Name.ends_with("cheese"))
|
||||
/// .build(DatabaseBackend::MySql)
|
||||
/// .build(DbBackend::MySql)
|
||||
/// .to_string(),
|
||||
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` LIKE '%cheese'"
|
||||
/// );
|
||||
@ -186,12 +186,12 @@ pub trait ColumnTrait: IdenStatic + Iterable {
|
||||
}
|
||||
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find()
|
||||
/// .filter(cake::Column::Name.contains("cheese"))
|
||||
/// .build(DatabaseBackend::MySql)
|
||||
/// .build(DbBackend::MySql)
|
||||
/// .to_string(),
|
||||
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` LIKE '%cheese%'"
|
||||
/// );
|
||||
|
@ -111,7 +111,7 @@ where
|
||||
mod tests {
|
||||
use crate::entity::prelude::*;
|
||||
use crate::tests_cfg::*;
|
||||
use crate::{DatabaseBackend, DatabaseConnection, MockDatabase, Transaction};
|
||||
use crate::{DbBackend, DatabaseConnection, MockDatabase, Transaction};
|
||||
use futures::TryStreamExt;
|
||||
use sea_query::{Alias, Expr, SelectStatement, Value};
|
||||
|
||||
@ -137,7 +137,7 @@ mod tests {
|
||||
|
||||
let page3 = Vec::<fruit::Model>::new();
|
||||
|
||||
let db = MockDatabase::new(DatabaseBackend::Postgres)
|
||||
let db = MockDatabase::new(DbBackend::Postgres)
|
||||
.append_query_results(vec![page1.clone(), page2.clone(), page3.clone()])
|
||||
.into_connection();
|
||||
|
||||
@ -146,7 +146,7 @@ mod tests {
|
||||
|
||||
fn setup_num_items() -> (DatabaseConnection, i32) {
|
||||
let num_items = 3;
|
||||
let db = MockDatabase::new(DatabaseBackend::Postgres)
|
||||
let db = MockDatabase::new(DbBackend::Postgres)
|
||||
.append_query_results(vec![vec![maplit::btreemap! {
|
||||
"num_items" => Into::<Value>::into(num_items),
|
||||
}]])
|
||||
|
@ -113,7 +113,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tests_cfg::{cake, fruit};
|
||||
use crate::{ColumnTrait, DatabaseBackend, EntityTrait, QueryFilter, QuerySelect, QueryTrait};
|
||||
use crate::{ColumnTrait, DbBackend, EntityTrait, QueryFilter, QuerySelect, QueryTrait};
|
||||
|
||||
#[test]
|
||||
fn alias_1() {
|
||||
@ -121,7 +121,7 @@ mod tests {
|
||||
cake::Entity::find()
|
||||
.column_as(cake::Column::Id, "B")
|
||||
.apply_alias("A_")
|
||||
.build(DatabaseBackend::MySql)
|
||||
.build(DbBackend::MySql)
|
||||
.to_string(),
|
||||
"SELECT `cake`.`id` AS `A_id`, `cake`.`name` AS `A_name`, `cake`.`id` AS `A_B` FROM `cake`",
|
||||
);
|
||||
@ -133,7 +133,7 @@ mod tests {
|
||||
cake::Entity::find()
|
||||
.left_join(fruit::Entity)
|
||||
.select_also(fruit::Entity)
|
||||
.build(DatabaseBackend::MySql)
|
||||
.build(DbBackend::MySql)
|
||||
.to_string(),
|
||||
[
|
||||
"SELECT `cake`.`id` AS `A_id`, `cake`.`name` AS `A_name`,",
|
||||
@ -149,7 +149,7 @@ mod tests {
|
||||
cake::Entity::find()
|
||||
.left_join(fruit::Entity)
|
||||
.select_with(fruit::Entity)
|
||||
.build(DatabaseBackend::MySql)
|
||||
.build(DbBackend::MySql)
|
||||
.to_string(),
|
||||
[
|
||||
"SELECT `cake`.`id` AS `A_id`, `cake`.`name` AS `A_name`,",
|
||||
@ -168,7 +168,7 @@ mod tests {
|
||||
.select_also(fruit::Entity)
|
||||
.filter(cake::Column::Id.eq(1))
|
||||
.filter(fruit::Column::Id.eq(2))
|
||||
.build(DatabaseBackend::MySql)
|
||||
.build(DbBackend::MySql)
|
||||
.to_string(),
|
||||
[
|
||||
"SELECT `cake`.`id` AS `A_id`, `cake`.`name` AS `A_name`,",
|
||||
@ -187,7 +187,7 @@ mod tests {
|
||||
.select_with(fruit::Entity)
|
||||
.filter(cake::Column::Id.eq(1))
|
||||
.filter(fruit::Column::Id.eq(2))
|
||||
.build(DatabaseBackend::MySql)
|
||||
.build(DbBackend::MySql)
|
||||
.to_string(),
|
||||
[
|
||||
"SELECT `cake`.`id` AS `A_id`, `cake`.`name` AS `A_name`,",
|
||||
|
@ -31,28 +31,28 @@ impl Delete {
|
||||
///
|
||||
/// Model
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// Delete::one(cake::Model {
|
||||
/// id: 1,
|
||||
/// name: "Apple Pie".to_owned(),
|
||||
/// })
|
||||
/// .build(DatabaseBackend::Postgres)
|
||||
/// .build(DbBackend::Postgres)
|
||||
/// .to_string(),
|
||||
/// r#"DELETE FROM "cake" WHERE "cake"."id" = 1"#,
|
||||
/// );
|
||||
/// ```
|
||||
/// ActiveModel
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// Delete::one(cake::ActiveModel {
|
||||
/// id: ActiveValue::set(1),
|
||||
/// name: ActiveValue::set("Apple Pie".to_owned()),
|
||||
/// })
|
||||
/// .build(DatabaseBackend::Postgres)
|
||||
/// .build(DbBackend::Postgres)
|
||||
/// .to_string(),
|
||||
/// r#"DELETE FROM "cake" WHERE "cake"."id" = 1"#,
|
||||
/// );
|
||||
@ -75,12 +75,12 @@ impl Delete {
|
||||
/// Delete many ActiveModel
|
||||
///
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::fruit, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::fruit, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// Delete::many(fruit::Entity)
|
||||
/// .filter(fruit::Column::Name.contains("Apple"))
|
||||
/// .build(DatabaseBackend::Postgres)
|
||||
/// .build(DbBackend::Postgres)
|
||||
/// .to_string(),
|
||||
/// r#"DELETE FROM "fruit" WHERE "fruit"."name" LIKE '%Apple%'"#,
|
||||
/// );
|
||||
@ -179,7 +179,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tests_cfg::{cake, fruit};
|
||||
use crate::{entity::*, query::*, DatabaseBackend};
|
||||
use crate::{entity::*, query::*, DbBackend};
|
||||
|
||||
#[test]
|
||||
fn delete_1() {
|
||||
@ -188,7 +188,7 @@ mod tests {
|
||||
id: 1,
|
||||
name: "Apple Pie".to_owned(),
|
||||
})
|
||||
.build(DatabaseBackend::Postgres)
|
||||
.build(DbBackend::Postgres)
|
||||
.to_string(),
|
||||
r#"DELETE FROM "cake" WHERE "cake"."id" = 1"#,
|
||||
);
|
||||
@ -197,7 +197,7 @@ mod tests {
|
||||
id: ActiveValue::set(1),
|
||||
name: ActiveValue::set("Apple Pie".to_owned()),
|
||||
})
|
||||
.build(DatabaseBackend::Postgres)
|
||||
.build(DbBackend::Postgres)
|
||||
.to_string(),
|
||||
r#"DELETE FROM "cake" WHERE "cake"."id" = 1"#,
|
||||
);
|
||||
@ -208,7 +208,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
Delete::many(fruit::Entity)
|
||||
.filter(fruit::Column::Name.contains("Cheese"))
|
||||
.build(DatabaseBackend::Postgres)
|
||||
.build(DbBackend::Postgres)
|
||||
.to_string(),
|
||||
r#"DELETE FROM "fruit" WHERE "fruit"."name" LIKE '%Cheese%'"#,
|
||||
);
|
||||
|
@ -23,13 +23,13 @@ pub trait QuerySelect: Sized {
|
||||
|
||||
/// Add a select column
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find()
|
||||
/// .select_only()
|
||||
/// .column(cake::Column::Name)
|
||||
/// .build(DatabaseBackend::Postgres)
|
||||
/// .build(DbBackend::Postgres)
|
||||
/// .to_string(),
|
||||
/// r#"SELECT "cake"."name" FROM "cake""#
|
||||
/// );
|
||||
@ -44,13 +44,13 @@ pub trait QuerySelect: Sized {
|
||||
|
||||
/// Add a select column with alias
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find()
|
||||
/// .select_only()
|
||||
/// .column_as(cake::Column::Id.count(), "count")
|
||||
/// .build(DatabaseBackend::Postgres)
|
||||
/// .build(DbBackend::Postgres)
|
||||
/// .to_string(),
|
||||
/// r#"SELECT COUNT("cake"."id") AS "count" FROM "cake""#
|
||||
/// );
|
||||
@ -68,14 +68,14 @@ pub trait QuerySelect: Sized {
|
||||
|
||||
/// Add a group by column
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find()
|
||||
/// .select_only()
|
||||
/// .column(cake::Column::Name)
|
||||
/// .group_by(cake::Column::Name)
|
||||
/// .build(DatabaseBackend::Postgres)
|
||||
/// .build(DbBackend::Postgres)
|
||||
/// .to_string(),
|
||||
/// r#"SELECT "cake"."name" FROM "cake" GROUP BY "cake"."name""#
|
||||
/// );
|
||||
@ -90,13 +90,13 @@ pub trait QuerySelect: Sized {
|
||||
|
||||
/// Add an AND HAVING expression
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find()
|
||||
/// .having(cake::Column::Id.eq(4))
|
||||
/// .having(cake::Column::Id.eq(5))
|
||||
/// .build(DatabaseBackend::MySql)
|
||||
/// .build(DbBackend::MySql)
|
||||
/// .to_string(),
|
||||
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` HAVING `cake`.`id` = 4 AND `cake`.`id` = 5"
|
||||
/// );
|
||||
@ -151,13 +151,13 @@ pub trait QueryOrder: Sized {
|
||||
|
||||
/// Add an order_by expression
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find()
|
||||
/// .order_by(cake::Column::Id, Order::Asc)
|
||||
/// .order_by(cake::Column::Name, Order::Desc)
|
||||
/// .build(DatabaseBackend::MySql)
|
||||
/// .build(DbBackend::MySql)
|
||||
/// .to_string(),
|
||||
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` ORDER BY `cake`.`id` ASC, `cake`.`name` DESC"
|
||||
/// );
|
||||
@ -172,12 +172,12 @@ pub trait QueryOrder: Sized {
|
||||
|
||||
/// Add an order_by expression (ascending)
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find()
|
||||
/// .order_by_asc(cake::Column::Id)
|
||||
/// .build(DatabaseBackend::MySql)
|
||||
/// .build(DbBackend::MySql)
|
||||
/// .to_string(),
|
||||
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` ORDER BY `cake`.`id` ASC"
|
||||
/// );
|
||||
@ -193,12 +193,12 @@ pub trait QueryOrder: Sized {
|
||||
|
||||
/// Add an order_by expression (descending)
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find()
|
||||
/// .order_by_desc(cake::Column::Id)
|
||||
/// .build(DatabaseBackend::MySql)
|
||||
/// .build(DbBackend::MySql)
|
||||
/// .to_string(),
|
||||
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` ORDER BY `cake`.`id` DESC"
|
||||
/// );
|
||||
@ -221,13 +221,13 @@ pub trait QueryFilter: Sized {
|
||||
|
||||
/// Add an AND WHERE expression
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find()
|
||||
/// .filter(cake::Column::Id.eq(4))
|
||||
/// .filter(cake::Column::Id.eq(5))
|
||||
/// .build(DatabaseBackend::MySql)
|
||||
/// .build(DbBackend::MySql)
|
||||
/// .to_string(),
|
||||
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`id` = 4 AND `cake`.`id` = 5"
|
||||
/// );
|
||||
@ -235,7 +235,7 @@ pub trait QueryFilter: Sized {
|
||||
///
|
||||
/// Add a condition tree.
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// cake::Entity::find()
|
||||
@ -244,7 +244,7 @@ pub trait QueryFilter: Sized {
|
||||
/// .add(cake::Column::Id.eq(4))
|
||||
/// .add(cake::Column::Id.eq(5))
|
||||
/// )
|
||||
/// .build(DatabaseBackend::MySql)
|
||||
/// .build(DbBackend::MySql)
|
||||
/// .to_string(),
|
||||
/// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`id` = 4 OR `cake`.`id` = 5"
|
||||
/// );
|
||||
|
@ -39,28 +39,28 @@ where
|
||||
///
|
||||
/// Model
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// Insert::one(cake::Model {
|
||||
/// id: 1,
|
||||
/// name: "Apple Pie".to_owned(),
|
||||
/// })
|
||||
/// .build(DatabaseBackend::Postgres)
|
||||
/// .build(DbBackend::Postgres)
|
||||
/// .to_string(),
|
||||
/// r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#,
|
||||
/// );
|
||||
/// ```
|
||||
/// ActiveModel
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// Insert::one(cake::ActiveModel {
|
||||
/// id: Unset(None),
|
||||
/// name: Set("Apple Pie".to_owned()),
|
||||
/// })
|
||||
/// .build(DatabaseBackend::Postgres)
|
||||
/// .build(DbBackend::Postgres)
|
||||
/// .to_string(),
|
||||
/// r#"INSERT INTO "cake" ("name") VALUES ('Apple Pie')"#,
|
||||
/// );
|
||||
@ -75,7 +75,7 @@ where
|
||||
/// Insert many Model or ActiveModel
|
||||
///
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// Insert::many(vec![
|
||||
@ -88,7 +88,7 @@ where
|
||||
/// name: "Orange Scone".to_owned(),
|
||||
/// }
|
||||
/// ])
|
||||
/// .build(DatabaseBackend::Postgres)
|
||||
/// .build(DbBackend::Postgres)
|
||||
/// .to_string(),
|
||||
/// r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie'), (2, 'Orange Scone')"#,
|
||||
/// );
|
||||
@ -162,7 +162,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tests_cfg::cake;
|
||||
use crate::{ActiveValue, DatabaseBackend, Insert, QueryTrait};
|
||||
use crate::{ActiveValue, DbBackend, Insert, QueryTrait};
|
||||
|
||||
#[test]
|
||||
fn insert_1() {
|
||||
@ -172,7 +172,7 @@ mod tests {
|
||||
id: ActiveValue::unset(),
|
||||
name: ActiveValue::set("Apple Pie".to_owned()),
|
||||
})
|
||||
.build(DatabaseBackend::Postgres)
|
||||
.build(DbBackend::Postgres)
|
||||
.to_string(),
|
||||
r#"INSERT INTO "cake" ("name") VALUES ('Apple Pie')"#,
|
||||
);
|
||||
@ -186,7 +186,7 @@ mod tests {
|
||||
id: ActiveValue::set(1),
|
||||
name: ActiveValue::set("Apple Pie".to_owned()),
|
||||
})
|
||||
.build(DatabaseBackend::Postgres)
|
||||
.build(DbBackend::Postgres)
|
||||
.to_string(),
|
||||
r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#,
|
||||
);
|
||||
@ -200,7 +200,7 @@ mod tests {
|
||||
id: 1,
|
||||
name: "Apple Pie".to_owned(),
|
||||
})
|
||||
.build(DatabaseBackend::Postgres)
|
||||
.build(DbBackend::Postgres)
|
||||
.to_string(),
|
||||
r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#,
|
||||
);
|
||||
@ -220,7 +220,7 @@ mod tests {
|
||||
name: "Orange Scone".to_owned(),
|
||||
}
|
||||
])
|
||||
.build(DatabaseBackend::Postgres)
|
||||
.build(DbBackend::Postgres)
|
||||
.to_string(),
|
||||
r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie'), (2, 'Orange Scone')"#,
|
||||
);
|
||||
@ -240,7 +240,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
Insert::<cake::ActiveModel>::new()
|
||||
.add_many(vec![apple, orange])
|
||||
.build(DatabaseBackend::Postgres)
|
||||
.build(DbBackend::Postgres)
|
||||
.to_string(),
|
||||
r#"INSERT INTO "cake" ("id", "name") VALUES (NULL, 'Apple'), (2, 'Orange')"#,
|
||||
);
|
||||
|
@ -62,14 +62,14 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tests_cfg::{cake, filling, fruit};
|
||||
use crate::{ColumnTrait, DatabaseBackend, EntityTrait, ModelTrait, QueryFilter, QueryTrait};
|
||||
use crate::{ColumnTrait, DbBackend, EntityTrait, ModelTrait, QueryFilter, QueryTrait};
|
||||
|
||||
#[test]
|
||||
fn join_1() {
|
||||
assert_eq!(
|
||||
cake::Entity::find()
|
||||
.left_join(fruit::Entity)
|
||||
.build(DatabaseBackend::MySql)
|
||||
.build(DbBackend::MySql)
|
||||
.to_string(),
|
||||
[
|
||||
"SELECT `cake`.`id`, `cake`.`name` FROM `cake`",
|
||||
@ -85,7 +85,7 @@ mod tests {
|
||||
cake::Entity::find()
|
||||
.inner_join(fruit::Entity)
|
||||
.filter(fruit::Column::Name.contains("cherry"))
|
||||
.build(DatabaseBackend::MySql)
|
||||
.build(DbBackend::MySql)
|
||||
.to_string(),
|
||||
[
|
||||
"SELECT `cake`.`id`, `cake`.`name` FROM `cake`",
|
||||
@ -101,7 +101,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
fruit::Entity::find()
|
||||
.reverse_join(cake::Entity)
|
||||
.build(DatabaseBackend::MySql)
|
||||
.build(DbBackend::MySql)
|
||||
.to_string(),
|
||||
[
|
||||
"SELECT `fruit`.`id`, `fruit`.`name`, `fruit`.`cake_id` FROM `fruit`",
|
||||
@ -119,7 +119,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
find_fruit
|
||||
.filter(cake::Column::Id.eq(11))
|
||||
.build(DatabaseBackend::MySql)
|
||||
.build(DbBackend::MySql)
|
||||
.to_string(),
|
||||
[
|
||||
"SELECT `fruit`.`id`, `fruit`.`name`, `fruit`.`cake_id` FROM `fruit`",
|
||||
@ -140,7 +140,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
cake_model
|
||||
.find_related(fruit::Entity)
|
||||
.build(DatabaseBackend::MySql)
|
||||
.build(DbBackend::MySql)
|
||||
.to_string(),
|
||||
[
|
||||
"SELECT `fruit`.`id`, `fruit`.`name`, `fruit`.`cake_id` FROM `fruit`",
|
||||
@ -156,7 +156,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
cake::Entity::find()
|
||||
.left_join(filling::Entity)
|
||||
.build(DatabaseBackend::MySql)
|
||||
.build(DbBackend::MySql)
|
||||
.to_string(),
|
||||
[
|
||||
"SELECT `cake`.`id`, `cake`.`name` FROM `cake`",
|
||||
@ -173,7 +173,7 @@ mod tests {
|
||||
|
||||
let find_filling: Select<filling::Entity> = cake::Entity::find_related();
|
||||
assert_eq!(
|
||||
find_filling.build(DatabaseBackend::MySql).to_string(),
|
||||
find_filling.build(DbBackend::MySql).to_string(),
|
||||
[
|
||||
"SELECT `filling`.`id`, `filling`.`name` FROM `filling`",
|
||||
"INNER JOIN `cake_filling` ON `cake_filling`.`filling_id` = `filling`.`id`",
|
||||
|
@ -102,12 +102,12 @@ impl FromQueryResult for JsonValue {
|
||||
#[cfg(feature = "mock")]
|
||||
mod tests {
|
||||
use crate::tests_cfg::cake;
|
||||
use crate::{entity::*, DatabaseBackend, MockDatabase};
|
||||
use crate::{entity::*, DbBackend, MockDatabase};
|
||||
use sea_query::Value;
|
||||
|
||||
#[async_std::test]
|
||||
async fn to_json_1() {
|
||||
let db = MockDatabase::new(DatabaseBackend::Postgres)
|
||||
let db = MockDatabase::new(DbBackend::Postgres)
|
||||
.append_query_results(vec![vec![maplit::btreemap! {
|
||||
"id" => Into::<Value>::into(128), "name" => Into::<Value>::into("apple")
|
||||
}]])
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{DatabaseBackend, Statement};
|
||||
use crate::{DbBackend, Statement};
|
||||
use sea_query::QueryStatementBuilder;
|
||||
|
||||
pub trait QueryTrait {
|
||||
@ -14,7 +14,7 @@ pub trait QueryTrait {
|
||||
fn into_query(self) -> Self::QueryStatement;
|
||||
|
||||
/// Build the query as [`Statement`]
|
||||
fn build(&self, db_backend: DatabaseBackend) -> Statement {
|
||||
fn build(&self, db_backend: DbBackend) -> Statement {
|
||||
let query_builder = db_backend.get_query_builder();
|
||||
Statement::from_string_values_tuple(
|
||||
db_backend,
|
||||
|
@ -30,14 +30,14 @@ impl Update {
|
||||
/// Update one ActiveModel
|
||||
///
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// Update::one(cake::ActiveModel {
|
||||
/// id: ActiveValue::set(1),
|
||||
/// name: ActiveValue::set("Apple Pie".to_owned()),
|
||||
/// })
|
||||
/// .build(DatabaseBackend::Postgres)
|
||||
/// .build(DbBackend::Postgres)
|
||||
/// .to_string(),
|
||||
/// r#"UPDATE "cake" SET "name" = 'Apple Pie' WHERE "cake"."id" = 1"#,
|
||||
/// );
|
||||
@ -59,13 +59,13 @@ impl Update {
|
||||
/// Update many ActiveModel
|
||||
///
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::fruit, sea_query::Expr, DatabaseBackend};
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::fruit, sea_query::Expr, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// Update::many(fruit::Entity)
|
||||
/// .col_expr(fruit::Column::Name, Expr::value("Golden Apple"))
|
||||
/// .filter(fruit::Column::Name.contains("Apple"))
|
||||
/// .build(DatabaseBackend::Postgres)
|
||||
/// .build(DbBackend::Postgres)
|
||||
/// .to_string(),
|
||||
/// r#"UPDATE "fruit" SET "name" = 'Golden Apple' WHERE "fruit"."name" LIKE '%Apple%'"#,
|
||||
/// );
|
||||
@ -184,7 +184,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tests_cfg::{cake, fruit};
|
||||
use crate::{entity::*, query::*, DatabaseBackend};
|
||||
use crate::{entity::*, query::*, DbBackend};
|
||||
use sea_query::{Expr, Value};
|
||||
|
||||
#[test]
|
||||
@ -194,7 +194,7 @@ mod tests {
|
||||
id: ActiveValue::set(1),
|
||||
name: ActiveValue::set("Apple Pie".to_owned()),
|
||||
})
|
||||
.build(DatabaseBackend::Postgres)
|
||||
.build(DbBackend::Postgres)
|
||||
.to_string(),
|
||||
r#"UPDATE "cake" SET "name" = 'Apple Pie' WHERE "cake"."id" = 1"#,
|
||||
);
|
||||
@ -208,7 +208,7 @@ mod tests {
|
||||
name: ActiveValue::set("Orange".to_owned()),
|
||||
cake_id: ActiveValue::unset(),
|
||||
})
|
||||
.build(DatabaseBackend::Postgres)
|
||||
.build(DbBackend::Postgres)
|
||||
.to_string(),
|
||||
r#"UPDATE "fruit" SET "name" = 'Orange' WHERE "fruit"."id" = 1"#,
|
||||
);
|
||||
@ -222,7 +222,7 @@ mod tests {
|
||||
name: ActiveValue::unchanged("Apple".to_owned()),
|
||||
cake_id: ActiveValue::set(Some(3)),
|
||||
})
|
||||
.build(DatabaseBackend::Postgres)
|
||||
.build(DbBackend::Postgres)
|
||||
.to_string(),
|
||||
r#"UPDATE "fruit" SET "cake_id" = 3 WHERE "fruit"."id" = 2"#,
|
||||
);
|
||||
@ -234,7 +234,7 @@ mod tests {
|
||||
Update::many(fruit::Entity)
|
||||
.col_expr(fruit::Column::CakeId, Expr::value(Value::Null))
|
||||
.filter(fruit::Column::Id.eq(2))
|
||||
.build(DatabaseBackend::Postgres)
|
||||
.build(DbBackend::Postgres)
|
||||
.to_string(),
|
||||
r#"UPDATE "fruit" SET "cake_id" = NULL WHERE "fruit"."id" = 2"#,
|
||||
);
|
||||
|
@ -1,4 +1,4 @@
|
||||
use sea_orm::{entity::*, error::*, sea_query, tests_cfg::*, DatabaseBackend, DbConn, Statement};
|
||||
use sea_orm::{entity::*, error::*, sea_query, tests_cfg::*, DbBackend, DbConn, Statement};
|
||||
|
||||
mod setup;
|
||||
|
||||
@ -28,7 +28,7 @@ async fn setup_schema(db: &DbConn) {
|
||||
.build(SqliteQueryBuilder);
|
||||
|
||||
let result = db
|
||||
.execute(Statement::from_string(DatabaseBackend::Sqlite, stmt))
|
||||
.execute(Statement::from_string(DbBackend::Sqlite, stmt))
|
||||
.await;
|
||||
println!("Create table cake: {:?}", result);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user