cargo sea-query 1.0.0-rc.32

latest releases: 1.0.1, 1.0.0, 1.0.0-rc.34...
2 months ago

New Features

  • Support EXPLAIN statements #1044
// Postgres
assert_eq!(
    ExplainStatement::new()
        .analyze()
        .format(ExplainFormat::Json)
        .statement(
            Query::select()
                .column(Char::Character)
                .from(Char::Table)
                .to_owned(),
        )
        .to_string(PostgresQueryBuilder),
    r#"EXPLAIN (ANALYZE, FORMAT JSON) SELECT "character" FROM "character""#
);

// MySQL
assert_eq!(
    ExplainStatement::new()
        .format(ExplainFormat::Json)
        .statement(
            Query::select()
                .column(Char::Character)
                .from(Char::Table)
                .to_owned(),
        )
        .to_string(MysqlQueryBuilder),
    "EXPLAIN FORMAT = JSON SELECT `character` FROM `character`"
);

// SQLite
assert_eq!(
    ExplainStatement::new()
        .query_plan()
        .statement(
            Query::select()
                .column(Char::Character)
                .from(Char::Table)
                .to_owned(),
        )
        .to_string(SqliteQueryBuilder),
    r#"EXPLAIN QUERY PLAN SELECT "character" FROM "character""#
);
  • Support for FILTER clause on aggregate functions #1043
let query = Query::select()
    .expr_as(
        Func::count(Expr::val(1))
            .filter(
                Cond::all()
                    .add(Expr::col(Char::Character).eq("foo"))
                    .add(Expr::col(Char::SizeW).eq(1))
            ),
        Alias::new("filtered_total")
    )
    .expr_as(Func::count(Expr::val(1)), Alias::new("total"))
    .from(Char::Table)
    .to_owned();

assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT COUNT(1) FILTER (WHERE "character" = 'foo' AND "size_w" = 1) AS "filtered_total", COUNT(1) AS "total" FROM "character""#
);
  • Add ALTER TABLE DROP CONSTRAINT
let table = Table::alter()
    .table(Font::Table)
    .drop_constraint("font_name_key")
    .to_owned();

assert_eq!(
    table.to_string(MysqlQueryBuilder),
    r#"ALTER TABLE `font` DROP CONSTRAINT `font_name_key`"#
);
assert_eq!(
    table.to_string(PostgresQueryBuilder),
    r#"ALTER TABLE "font" DROP CONSTRAINT "font_name_key""#
);

House Keeping

  • Bump Rust version to 1.88
  • Bump rusqlite to 0.38.0 #1059
  • Update time to 0.3.47 #1057

Don't miss a new sea-query release

NewReleases is sending notifications on new releases.