Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub struct ColumnName(pub Option<TableName>, pub DynIden);

### Enhancements

* Add `Expr::not_exists` https://github.com/SeaQL/sea-query/pull/983
* Add `serde` feature. Currently, enabling it allows `Value` to be serializable https://github.com/SeaQL/sea-query/pull/966
* Add `Keyword::Default` https://github.com/SeaQL/sea-query/pull/965
* Enable `clippy::nursery` https://github.com/SeaQL/sea-query/pull/938
Expand Down
26 changes: 26 additions & 0 deletions src/expr/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,32 @@ impl Expr {
Self::SubQuery(Some(SubQueryOper::Exists), Box::new(sel.into()))
}

/// Express a `NOT EXISTS` sub-query expression.
/// ```
/// use sea_query::{*, tests_cfg::*};
///
/// let query = Query::select()
/// .expr_as(Expr::not_exists(Query::select().column(Char::Id).from(Char::Table).take()), "character_exists")
/// .expr_as(Expr::not_exists(Query::select().column(Glyph::Id).from(Glyph::Table).take()), "glyph_exists")
/// .to_owned();
///
/// assert_eq!(
/// query.to_string(MysqlQueryBuilder),
/// r#"SELECT NOT EXISTS(SELECT `id` FROM `character`) AS `character_exists`, NOT EXISTS(SELECT `id` FROM `glyph`) AS `glyph_exists`"#
/// );
/// assert_eq!(
/// query.to_string(PostgresQueryBuilder),
/// r#"SELECT NOT EXISTS(SELECT "id" FROM "character") AS "character_exists", NOT EXISTS(SELECT "id" FROM "glyph") AS "glyph_exists""#
/// );
/// assert_eq!(
/// query.to_string(SqliteQueryBuilder),
/// r#"SELECT NOT EXISTS(SELECT "id" FROM "character") AS "character_exists", NOT EXISTS(SELECT "id" FROM "glyph") AS "glyph_exists""#
/// );
/// ```
pub fn not_exists(sel: SelectStatement) -> Self {
Self::exists(sel).not()
}

/// Express a `ANY` sub-query expression.
///
/// # Examples
Expand Down
Loading