Merge remote-tracking branch 'origin/master' into active-enum
This commit is contained in:
commit
fe64d53b45
158
.github/workflows/rust.yml
vendored
158
.github/workflows/rust.yml
vendored
@ -1,3 +1,53 @@
|
||||
# GitHub Actions with Conditional Job Running Based on Commit Message
|
||||
#
|
||||
# --------------------------------------------------------------------------------
|
||||
#
|
||||
# Following jobs will always run
|
||||
#
|
||||
# - `clippy`
|
||||
# - `test`
|
||||
# - `examples`
|
||||
#
|
||||
# Following jobs will be run when no keywords were found in commit message)
|
||||
#
|
||||
# - `compile-sqlite`
|
||||
# - `sqlite`
|
||||
# - `compile-mysql`
|
||||
# - `mysql`
|
||||
# - `mariadb`
|
||||
# - `compile-postgres`
|
||||
# - `postgres`
|
||||
#
|
||||
# Following jobs will be run if keywords `[issues]` were found in commit message
|
||||
#
|
||||
# - Jobs that will always run
|
||||
# - `issues`
|
||||
#
|
||||
# Following jobs will be run if keywords `[cli]` were found in commit message
|
||||
#
|
||||
# - Jobs that will always run
|
||||
# - `cli`
|
||||
#
|
||||
# Following jobs will be run if keywords `[sqlite]` were found in commit message
|
||||
#
|
||||
# - Jobs that will always run
|
||||
# - `compile-sqlite`
|
||||
# - `sqlite`
|
||||
#
|
||||
# Following jobs will be run if keywords `[mysql]` were found in commit message
|
||||
#
|
||||
# - Jobs that will always run
|
||||
# - `compile-mysql`
|
||||
# - `mysql`
|
||||
# - `mariadb`
|
||||
#
|
||||
# Following jobs will be run if keywords `[postgres]` were found in commit message
|
||||
#
|
||||
# - Jobs that will always run
|
||||
# - `compile-postgres`
|
||||
# - `postgres`
|
||||
|
||||
|
||||
name: tests
|
||||
|
||||
on:
|
||||
@ -12,8 +62,33 @@ env:
|
||||
|
||||
jobs:
|
||||
|
||||
clippy:
|
||||
name: Clippy
|
||||
init:
|
||||
name: Init
|
||||
runs-on: ubuntu-20.04
|
||||
outputs:
|
||||
run-sqlite: ${{ contains(steps.git-log.outputs.message, '[sqlite]') }}
|
||||
run-mysql: ${{ contains(steps.git-log.outputs.message, '[mysql]') }}
|
||||
run-postgres: ${{ contains(steps.git-log.outputs.message, '[postgres]') }}
|
||||
run-cli: ${{ contains(steps.git-log.outputs.message, '[cli]') }}
|
||||
run-issues: ${{ contains(steps.git-log.outputs.message, '[issues]') }}
|
||||
run-partial: >-
|
||||
${{
|
||||
contains(steps.git-log.outputs.message, '[sqlite]') ||
|
||||
contains(steps.git-log.outputs.message, '[mysql]') ||
|
||||
contains(steps.git-log.outputs.message, '[postgres]') ||
|
||||
contains(steps.git-log.outputs.message, '[cli]') ||
|
||||
contains(steps.git-log.outputs.message, '[issues]')
|
||||
}}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- id: git-log
|
||||
run: echo "::set-output name=message::$(git log --no-merges -1 --oneline)"
|
||||
|
||||
clippy-fmt:
|
||||
name: Clippy + Fmt
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
@ -22,9 +97,17 @@ jobs:
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
components: clippy
|
||||
components: clippy, rustfmt
|
||||
override: true
|
||||
|
||||
|
||||
# Make sure files are formatted
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: fmt
|
||||
args: >
|
||||
--all
|
||||
|
||||
# Run clippy
|
||||
- uses: actions-rs/clippy-check@v1
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
@ -32,6 +115,12 @@ jobs:
|
||||
|
||||
compile-sqlite:
|
||||
name: Compile SQLite
|
||||
needs: init
|
||||
if: >-
|
||||
${{
|
||||
needs.init.outputs.run-partial == 'false' ||
|
||||
(needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-sqlite == 'true')
|
||||
}}
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
@ -65,6 +154,12 @@ jobs:
|
||||
|
||||
compile-mysql:
|
||||
name: Compile MySQL
|
||||
needs: init
|
||||
if: >-
|
||||
${{
|
||||
needs.init.outputs.run-partial == 'false' ||
|
||||
(needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-mysql == 'true')
|
||||
}}
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
@ -98,6 +193,12 @@ jobs:
|
||||
|
||||
compile-postgres:
|
||||
name: Compile PostgreSQL
|
||||
needs: init
|
||||
if: >-
|
||||
${{
|
||||
needs.init.outputs.run-partial == 'false' ||
|
||||
(needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-postgres == 'true')
|
||||
}}
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
@ -161,6 +262,8 @@ jobs:
|
||||
|
||||
cli:
|
||||
name: CLI
|
||||
needs: init
|
||||
if: ${{ (needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-cli == 'true') }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
@ -179,6 +282,7 @@ jobs:
|
||||
command: install
|
||||
args: >
|
||||
--path sea-orm-cli
|
||||
--debug
|
||||
|
||||
examples:
|
||||
name: Examples
|
||||
@ -204,11 +308,13 @@ jobs:
|
||||
|
||||
issues:
|
||||
name: Issues
|
||||
needs: init
|
||||
if: ${{ (needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-issues == 'true') }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
path: [86]
|
||||
path: [86, 249, 262]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
@ -224,10 +330,23 @@ jobs:
|
||||
args: >
|
||||
--manifest-path issues/${{ matrix.path }}/Cargo.toml
|
||||
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
args: >
|
||||
--manifest-path issues/${{ matrix.path }}/Cargo.toml
|
||||
|
||||
sqlite:
|
||||
name: SQLite
|
||||
needs:
|
||||
- init
|
||||
- compile-sqlite
|
||||
if: >-
|
||||
${{
|
||||
needs.init.outputs.run-partial == 'false' ||
|
||||
(needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-sqlite == 'true')
|
||||
}}
|
||||
runs-on: ubuntu-20.04
|
||||
needs: compile-sqlite
|
||||
env:
|
||||
DATABASE_URL: "sqlite::memory:"
|
||||
strategy:
|
||||
@ -261,8 +380,15 @@ jobs:
|
||||
|
||||
mysql:
|
||||
name: MySQL
|
||||
needs:
|
||||
- init
|
||||
- compile-mysql
|
||||
if: >-
|
||||
${{
|
||||
needs.init.outputs.run-partial == 'false' ||
|
||||
(needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-mysql == 'true')
|
||||
}}
|
||||
runs-on: ubuntu-20.04
|
||||
needs: compile-mysql
|
||||
env:
|
||||
DATABASE_URL: "mysql://root:@localhost"
|
||||
strategy:
|
||||
@ -314,8 +440,15 @@ jobs:
|
||||
|
||||
mariadb:
|
||||
name: MariaDB
|
||||
needs:
|
||||
- init
|
||||
- compile-mysql
|
||||
if: >-
|
||||
${{
|
||||
needs.init.outputs.run-partial == 'false' ||
|
||||
(needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-mysql == 'true')
|
||||
}}
|
||||
runs-on: ubuntu-20.04
|
||||
needs: compile-mysql
|
||||
env:
|
||||
DATABASE_URL: "mysql://root:@localhost"
|
||||
strategy:
|
||||
@ -367,8 +500,15 @@ jobs:
|
||||
|
||||
postgres:
|
||||
name: Postgres
|
||||
needs:
|
||||
- init
|
||||
- compile-postgres
|
||||
if: >-
|
||||
${{
|
||||
needs.init.outputs.run-partial == 'false' ||
|
||||
(needs.init.outputs.run-partial == 'true' && needs.init.outputs.run-postgres == 'true')
|
||||
}}
|
||||
runs-on: ubuntu-20.04
|
||||
needs: compile-postgres
|
||||
env:
|
||||
DATABASE_URL: "postgres://root:root@localhost"
|
||||
strategy:
|
||||
|
19
CHANGELOG.md
19
CHANGELOG.md
@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## 0.3.1 - 2021-10-23
|
||||
|
||||
(We are changing our Changelog format from now on)
|
||||
|
||||
### Fixed Issues
|
||||
* Align case trasforms across derive macros https://github.com/SeaQL/sea-orm/issues/262
|
||||
* Added `is_null` and `is_not_null` to `ColumnTrait` https://github.com/SeaQL/sea-orm/issues/267
|
||||
|
||||
(The following is generated by GitHub)
|
||||
|
||||
### Merged PRs
|
||||
* Changed manual url parsing to use Url crate by @AngelOnFira in https://github.com/SeaQL/sea-orm/pull/253
|
||||
* Test self referencing relation by @billy1624 in https://github.com/SeaQL/sea-orm/pull/256
|
||||
* Unify case-transform using the same crate by @billy1624 in https://github.com/SeaQL/sea-orm/pull/264
|
||||
* CI cleaning by @AngelOnFira in https://github.com/SeaQL/sea-orm/pull/263
|
||||
* CI install sea-orm-cli in debug mode by @billy1624 in https://github.com/SeaQL/sea-orm/pull/265
|
||||
|
||||
**Full Changelog**: https://github.com/SeaQL/sea-orm/compare/0.3.0...0.3.1
|
||||
|
||||
## 0.3.0 - 2021-10-15
|
||||
|
||||
https://www.sea-ql.org/SeaORM/blog/2021-10-15-whats-new-in-0.3.0
|
||||
|
@ -3,9 +3,9 @@ members = [".", "sea-orm-macros", "sea-orm-codegen"]
|
||||
|
||||
[package]
|
||||
name = "sea-orm"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
authors = ["Chris Tsang <tyt2y7@gmail.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
description = "🐚 An async & dynamic ORM for Rust"
|
||||
license = "MIT OR Apache-2.0"
|
||||
documentation = "https://docs.rs/sea-orm"
|
||||
@ -29,7 +29,7 @@ futures = { version = "^0.3" }
|
||||
futures-util = { version = "^0.3" }
|
||||
log = { version = "^0.4", optional = true }
|
||||
rust_decimal = { version = "^1", optional = true }
|
||||
sea-orm-macros = { version = "^0.3.0", path = "sea-orm-macros", optional = true }
|
||||
sea-orm-macros = { version = "^0.3.1", path = "sea-orm-macros", optional = true }
|
||||
sea-query = { version = "^0.18.0", git = "https://github.com/SeaQL/sea-query.git", branch = "sea-orm/active-enum-1", features = ["thread-safe"] }
|
||||
sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] }
|
||||
serde = { version = "^1.0", features = ["derive"] }
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "sea-orm-actix-4-beta-example"
|
||||
version = "0.1.0"
|
||||
authors = ["Sam Samai <sam@studio2pi.com.au>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[workspace]
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "sea-orm-actix-example"
|
||||
version = "0.1.0"
|
||||
authors = ["Sam Samai <sam@studio2pi.com.au>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[workspace]
|
||||
|
@ -4,7 +4,7 @@
|
||||
[package]
|
||||
name = "sea-orm-example-async-std"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
@ -13,4 +13,4 @@ sea-orm = { path = "../../", features = [ "sqlx-all", "runtime-async-std-native-
|
||||
serde_json = { version = "^1" }
|
||||
futures = { version = "^0.3" }
|
||||
async-stream = { version = "^0.3" }
|
||||
futures-util = { version = "^0.3" }
|
||||
futures-util = { version = "^0.3" }
|
||||
|
@ -2,7 +2,7 @@
|
||||
name = "sea-orm-rocket-example"
|
||||
version = "0.1.0"
|
||||
authors = ["Sam Samai <sam@studio2pi.com.au>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[workspace]
|
||||
|
@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "sea-orm-issues-249-app"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
|
@ -1,11 +1,11 @@
|
||||
[package]
|
||||
name = "core"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
sea-orm = { path = "../../../", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
sea-orm = { path = "../../../", features = ["mock"] }
|
||||
sea-orm = { path = "../../../", features = ["mock"] }
|
||||
|
12
issues/262/Cargo.toml
Normal file
12
issues/262/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[workspace]
|
||||
# A separate workspace
|
||||
|
||||
[package]
|
||||
name = "sea-orm-issues-262"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
sea-orm = { path = "../../", features = [ "sqlx-all", "runtime-async-std-native-tls", "debug-print" ] }
|
||||
async-std = { version = "^1", features = ["attributes"] }
|
26
issues/262/src/cake.rs
Normal file
26
issues/262/src/cake.rs
Normal file
@ -0,0 +1,26 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||
#[sea_orm(table_name = "cake")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub md5hash: String,
|
||||
pub md5_hash: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_case_transform_1() {
|
||||
assert_eq!(Column::Md5hash.to_string().as_str(), "md5hash");
|
||||
assert_eq!(Column::Md5Hash.to_string().as_str(), "md5_hash");
|
||||
}
|
||||
}
|
14
issues/262/src/main.rs
Normal file
14
issues/262/src/main.rs
Normal file
@ -0,0 +1,14 @@
|
||||
mod cake;
|
||||
use sea_orm::*;
|
||||
|
||||
#[async_std::main]
|
||||
pub async fn main() {
|
||||
let db = Database::connect("mysql://sea:sea@localhost/bakery")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
async_std::task::spawn(async move {
|
||||
cake::Entity::find().one(&db).await.unwrap();
|
||||
})
|
||||
.await;
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
[package]
|
||||
name = "sea-orm-issues-86"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
|
@ -3,9 +3,9 @@
|
||||
|
||||
[package]
|
||||
name = "sea-orm-cli"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
authors = [ "Billy Chan <ccw.billy.123@gmail.com>" ]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
description = "Command line utility for SeaORM"
|
||||
license = "MIT OR Apache-2.0"
|
||||
documentation = "https://docs.rs/sea-orm"
|
||||
@ -21,7 +21,7 @@ path = "src/main.rs"
|
||||
clap = { version = "^2.33.3" }
|
||||
dotenv = { version = "^0.15" }
|
||||
async-std = { version = "^1.9", features = [ "attributes" ] }
|
||||
sea-orm-codegen = { version = "^0.3.0", path = "../sea-orm-codegen" }
|
||||
sea-orm-codegen = { version = "^0.3.1", path = "../sea-orm-codegen" }
|
||||
sea-schema = { version = "^0.2.9", default-features = false, features = [
|
||||
"debug-print",
|
||||
"sqlx-mysql",
|
||||
|
@ -50,7 +50,6 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Er
|
||||
//
|
||||
// Missing scheme will have been caught by the Url::parse() call
|
||||
// above
|
||||
|
||||
let url_username = url.username();
|
||||
let url_password = url.password();
|
||||
let url_host = url.host_str();
|
||||
|
@ -1,8 +1,8 @@
|
||||
[package]
|
||||
name = "sea-orm-codegen"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
authors = ["Billy Chan <ccw.billy.123@gmail.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
description = "Code Generator for SeaORM"
|
||||
license = "MIT OR Apache-2.0"
|
||||
documentation = "https://docs.rs/sea-orm"
|
||||
|
@ -934,7 +934,7 @@ mod tests {
|
||||
}
|
||||
let content = lines.join("");
|
||||
let expected: TokenStream = content.parse().unwrap();
|
||||
let generated = generator(&cake_entity, &entity_serde_variant.1)
|
||||
let generated = generator(cake_entity, &entity_serde_variant.1)
|
||||
.into_iter()
|
||||
.fold(TokenStream::new(), |mut acc, tok| {
|
||||
acc.extend(tok);
|
||||
|
@ -1,8 +1,8 @@
|
||||
[package]
|
||||
name = "sea-orm-macros"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
authors = [ "Billy Chan <ccw.billy.123@gmail.com>" ]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
description = "Derive macros for SeaORM"
|
||||
license = "MIT OR Apache-2.0"
|
||||
documentation = "https://docs.rs/sea-orm"
|
||||
@ -21,4 +21,3 @@ syn = { version = "^1", default-features = false, features = [ "full", "derive",
|
||||
quote = "^1"
|
||||
heck = "^0.3"
|
||||
proc-macro2 = "^1"
|
||||
convert_case = "0.4"
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::util::{escape_rust_keyword, trim_starting_raw_identifier};
|
||||
use convert_case::{Case, Casing};
|
||||
use heck::CamelCase;
|
||||
use proc_macro2::{Ident, Span, TokenStream};
|
||||
use quote::{format_ident, quote, quote_spanned};
|
||||
use syn::{
|
||||
@ -62,7 +62,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
|
||||
for field in fields.named {
|
||||
if let Some(ident) = &field.ident {
|
||||
let mut field_name = Ident::new(
|
||||
&trim_starting_raw_identifier(&ident).to_case(Case::Pascal),
|
||||
&trim_starting_raw_identifier(&ident).to_camel_case(),
|
||||
Span::call_site(),
|
||||
);
|
||||
|
||||
|
@ -7,7 +7,7 @@ repository = "https://github.com/SergioBenitez/Rocket/contrib/db_pools"
|
||||
readme = "../README.md"
|
||||
keywords = ["rocket", "framework", "database", "pools"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
@ -7,7 +7,7 @@ repository = "https://github.com/SeaQL/sea-orm"
|
||||
readme = "../README.md"
|
||||
keywords = ["rocket", "framework", "database", "pools"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
|
@ -48,8 +48,9 @@ macro_rules! bind_oper {
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! bind_agg_func {
|
||||
macro_rules! bind_func_no_params {
|
||||
( $func: ident ) => {
|
||||
/// See also SeaQuery's method with same name.
|
||||
fn $func(&self) -> SimpleExpr {
|
||||
Expr::tbl(self.entity_name(), *self).$func()
|
||||
}
|
||||
@ -214,10 +215,12 @@ pub trait ColumnTrait: IdenStatic + Iterable + FromStr {
|
||||
Expr::tbl(self.entity_name(), *self).like(&pattern)
|
||||
}
|
||||
|
||||
bind_agg_func!(max);
|
||||
bind_agg_func!(min);
|
||||
bind_agg_func!(sum);
|
||||
bind_agg_func!(count);
|
||||
bind_func_no_params!(max);
|
||||
bind_func_no_params!(min);
|
||||
bind_func_no_params!(sum);
|
||||
bind_func_no_params!(count);
|
||||
bind_func_no_params!(is_null);
|
||||
bind_func_no_params!(is_not_null);
|
||||
|
||||
fn if_null<V>(&self, v: V) -> SimpleExpr
|
||||
where
|
||||
@ -681,6 +684,7 @@ mod tests {
|
||||
fn column_name_enum_name_1() {
|
||||
use sea_query::Iden;
|
||||
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
mod hello {
|
||||
use crate as sea_orm;
|
||||
use crate::entity::prelude::*;
|
||||
|
@ -340,6 +340,18 @@ pub trait QueryFilter: Sized {
|
||||
/// r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE (NOT (1 = 1 AND 2 = 2)) AND (3 = 3 OR 4 = 4)"#
|
||||
/// );
|
||||
/// ```
|
||||
/// Use a sea_query expression
|
||||
/// ```
|
||||
/// use sea_orm::{entity::*, query::*, sea_query::Expr, tests_cfg::fruit, DbBackend};
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// fruit::Entity::find()
|
||||
/// .filter(Expr::col(fruit::Column::CakeId).is_null())
|
||||
/// .build(DbBackend::MySql)
|
||||
/// .to_string(),
|
||||
/// "SELECT `fruit`.`id`, `fruit`.`name`, `fruit`.`cake_id` FROM `fruit` WHERE `cake_id` IS NULL"
|
||||
/// );
|
||||
/// ```
|
||||
fn filter<F>(mut self, filter: F) -> Self
|
||||
where
|
||||
F: IntoCondition,
|
||||
|
@ -43,26 +43,36 @@ debug_query_build!(&DatabaseConnection, |x: &DebugQuery<
|
||||
/// # let conn = MockDatabase::new(DbBackend::Postgres)
|
||||
/// # .into_connection();
|
||||
/// #
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, debug_query_stmt};
|
||||
/// use sea_orm::{debug_query_stmt, entity::*, query::*, tests_cfg::cake};
|
||||
///
|
||||
/// let c = cake::Entity::insert(
|
||||
/// cake::ActiveModel {
|
||||
/// id: ActiveValue::set(1),
|
||||
/// name: ActiveValue::set("Apple Pie".to_owned()),
|
||||
/// let c = cake::Entity::insert(cake::ActiveModel {
|
||||
/// id: ActiveValue::set(1),
|
||||
/// name: ActiveValue::set("Apple Pie".to_owned()),
|
||||
/// });
|
||||
///
|
||||
/// let raw_sql = debug_query_stmt!(&c, &conn).to_string();
|
||||
/// assert_eq!(raw_sql, r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#);
|
||||
/// assert_eq!(
|
||||
/// raw_sql,
|
||||
/// r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#
|
||||
/// );
|
||||
///
|
||||
/// let raw_sql = debug_query_stmt!(&c, conn).to_string();
|
||||
/// assert_eq!(raw_sql, r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#);
|
||||
/// assert_eq!(
|
||||
/// raw_sql,
|
||||
/// r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#
|
||||
/// );
|
||||
///
|
||||
/// let raw_sql = debug_query_stmt!(&c, DbBackend::MySql).to_string();
|
||||
/// assert_eq!(raw_sql, r#"INSERT INTO `cake` (`id`, `name`) VALUES (1, 'Apple Pie')"#);
|
||||
/// assert_eq!(
|
||||
/// raw_sql,
|
||||
/// r#"INSERT INTO `cake` (`id`, `name`) VALUES (1, 'Apple Pie')"#
|
||||
/// );
|
||||
///
|
||||
/// let raw_sql = debug_query_stmt!(&c, &DbBackend::MySql).to_string();
|
||||
/// assert_eq!(raw_sql, r#"INSERT INTO `cake` (`id`, `name`) VALUES (1, 'Apple Pie')"#);
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// raw_sql,
|
||||
/// r#"INSERT INTO `cake` (`id`, `name`) VALUES (1, 'Apple Pie')"#
|
||||
/// );
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! debug_query_stmt {
|
||||
@ -86,23 +96,30 @@ macro_rules! debug_query_stmt {
|
||||
/// # let conn = MockDatabase::new(DbBackend::Postgres)
|
||||
/// # .into_connection();
|
||||
/// #
|
||||
/// use sea_orm::{entity::*, query::*, tests_cfg::cake,debug_query};
|
||||
/// use sea_orm::{debug_query, entity::*, query::*, tests_cfg::cake};
|
||||
///
|
||||
/// let c = cake::Entity::insert(
|
||||
/// cake::ActiveModel {
|
||||
/// id: ActiveValue::set(1),
|
||||
/// name: ActiveValue::set("Apple Pie".to_owned()),
|
||||
/// let c = cake::Entity::insert(cake::ActiveModel {
|
||||
/// id: ActiveValue::set(1),
|
||||
/// name: ActiveValue::set("Apple Pie".to_owned()),
|
||||
/// });
|
||||
///
|
||||
/// let raw_sql = debug_query!(&c, &conn);
|
||||
/// assert_eq!(raw_sql, r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#);
|
||||
/// assert_eq!(
|
||||
/// raw_sql,
|
||||
/// r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#
|
||||
/// );
|
||||
///
|
||||
/// let raw_sql = debug_query!(&c, conn);
|
||||
/// assert_eq!(raw_sql, r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#);
|
||||
/// assert_eq!(
|
||||
/// raw_sql,
|
||||
/// r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#
|
||||
/// );
|
||||
///
|
||||
/// let raw_sql = debug_query!(&c, DbBackend::Sqlite);
|
||||
/// assert_eq!(raw_sql, r#"INSERT INTO `cake` (`id`, `name`) VALUES (1, 'Apple Pie')"#);
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// raw_sql,
|
||||
/// r#"INSERT INTO `cake` (`id`, `name`) VALUES (1, 'Apple Pie')"#
|
||||
/// );
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! debug_query {
|
||||
|
@ -67,9 +67,7 @@ pub enum Relation {}
|
||||
|
||||
impl RelationTrait for Relation {
|
||||
fn def(&self) -> RelationDef {
|
||||
match self {
|
||||
_ => panic!("No RelationDef"),
|
||||
}
|
||||
panic!("No RelationDef")
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user