New Features
- Add
Value::Enum— a typed enum value that generates a literal cast in Postgres #1051
let value = sea_query::Enum {
type_name: "FontSizeEnum".to_owned().into(),
value: "large".into(),
};
assert_eq!(
Query::insert()
.into_table(Char::Table)
.columns([Char::FontSize])
.values_panic([Expr::val(value)])
.to_string(PostgresQueryBuilder),
r#"INSERT INTO "character" ("font_size") VALUES ('large'::"FontSizeEnum")"#
);Arrays of enum values are also supported (requires postgres-array):
let value = Value::Array(
ArrayType::Enum(Box::new("FontSizeEnum".to_owned().into())),
Some(Box::new(vec![
sea_query::Enum { type_name: "FontSizeEnum".to_owned().into(), value: "large".into() }.into(),
])),
);
// Generates: INSERT INTO "character" ("font_size") VALUES ($1::"FontSizeEnum"[])- Add Postgres advisory lock functions #1062
assert_eq!(
Query::select()
.expr(PgFunc::advisory_lock(Expr::val(12345_i64)))
.to_owned()
.to_string(PostgresQueryBuilder),
r#"SELECT PG_ADVISORY_LOCK(12345)"#
);Full set of functions added: PgFunc::advisory_lock, advisory_lock_shared, try_advisory_lock, try_advisory_lock_shared, advisory_unlock, advisory_unlock_shared, advisory_unlock_all, advisory_xact_lock, advisory_xact_lock_shared, try_advisory_xact_lock, try_advisory_xact_lock_shared
- Add
SelectExprTraitfor ergonomic alias and window chaining #1040
// Attach alias directly on an expression
Query::select()
.expr(Expr::col(Char::Character).alias("C"))
.from(Char::Table);
// Chain window function inline
Query::select()
.from(Char::Table)
.expr(
Expr::col(Char::Character)
.max()
.over(WindowStatement::partition_by(Char::FontSize))
.alias("C"),
);
// Reference a named window
Query::select()
.from(Char::Table)
.expr(Expr::col(Char::Character).max().over("w"))
.window("w", WindowStatement::partition_by(Char::FontSize));Enhancements
- Allow schema-referencing foreign keys in SQLite backend — the schema qualifier is stripped since SQLite foreign key syntax does not support it #1056
- Fix null array handling:
Array::Null.is_empty()now correctly returnsfalse; null and empty are distinct states #1034 - Rename
Value::as_ref_arraytoValue::as_array; old name kept as a deprecated alias #1034 - Add
PostgresValues::as_types()— returns the correspondingpostgres::Typefor each bound value #967
House Keeping
- Simplify
FunctionCall::new(PgFunc::...)calls